jquery.newsticker.js

2009 blev det här scriptet till.

/*
	Made By Peter Lindblom 2009
	http://www.plweb.se
	ver 1.000
*/

(function ($) {
	
	$.fn.startNewsTicker = function (settings) {

		var config = {
			startPosition: -20, 
			stopPosition: 100,
			pausPosition: 50,
			units: "px",
			waitToStartForMS:0,
			waitOnPausPositionForMS:1000,
			animationDelayMS:25
		};
		
		return this.each(function () {
			
			this.newsTicker = function (currentHtmlObj) {
				var childElements = [],
				currentElement = 0,
				lastChildElement = 0,
				startTimer = null,
				timer = null, 
				localConfig = $.extend({}, config, settings),
				delay = localConfig.animationDelayMS,
				
				startNewsTicker = function () {
					childElements = $(currentHtmlObj).children();
					lastChildElement = (childElements.length -1);
					
					$.each($(currentHtmlObj).children(), function () {
						$(this).css("top",localConfig.startPosition + localConfig.units);
						$(this).css("position","absolute");
						$(this).hide();
					});
					
					startTimer = setTimeout(tick, localConfig.waitToStartForMS);
				},
				
				tick = function () {
											
					if( (currentElement <= lastChildElement) && ( parseInt(currentJQueryObj(currentElement).css("top"),10) !== localConfig.stopPosition ) ){
						delay = localConfig.animationDelayMS;
						currentJQueryObj(currentElement).show();
						if (localConfig.startPosition < localConfig.stopPosition) {
							currentJQueryObj(currentElement).css("top", ( parseInt(currentJQueryObj(currentElement).css("top"), 10) + 1 ) + localConfig.units  );
						}else if (localConfig.startPosition > localConfig.stopPosition) {
							currentJQueryObj(currentElement).css("top", ( parseInt(currentJQueryObj(currentElement).css("top"), 10) - 1 ) + localConfig.units  );
						}
						
						if( parseInt(currentJQueryObj(currentElement).css("top"), 10) === localConfig.stopPosition ){
							currentJQueryObj(currentElement).hide();
							currentJQueryObj(currentElement).css("top",localConfig.startPosition + localConfig.units);
							currentElement = currentElement + 1; 
							if (currentElement > lastChildElement ){
								currentElement = 0;
							}
						}
					}
					
					if( (currentElement <= lastChildElement) && ( parseInt(currentJQueryObj(currentElement).css("top"), 10) === localConfig.pausPosition ) ){						
						delay = localConfig.waitOnPausPositionForMS;						
					}
					
					timer = setTimeout(tick, delay);
					
				},
				currentJQueryObj = function (pos) {
					return $(childElements[currentElement]);
				};
				
				startNewsTicker();
			};
			
			this.newsTicker(this);
			
		});
	};
	
		
	
}(jQuery));


localStorage test

Idag testade jag localStorage på en av mina sajter och jag måste säga att det är väldigt coolt 🙂

Jag valde att spara alla inmatning i localStorage tills man valt skicka väg formuläret. namnet på formulär fältet används som nyckel i localStorage men det det bör inte vara något större problem att kombinera formulärets id eller action attribut.

ls = {
	set : function(name, value){
		if(window.localStorage){
			localStorage.removeItem(name);			
			localStorage.setItem(name, value);			
		}
	},
	get : function(name){
		if(window.localStorage){
			return localStorage.getItem(name);
		}
	},
	clear : function() {
		if(window.localStorage){
			return localStorage.clear();
		}
	}
}; 

$(document).ready(function(){
	
	$(":input").each(function(){
		if($(this).val() == "" && ls.get($(this).attr("name")) != ""){
			$(this).val(ls.get($(this).attr("name")));
		}									
	});
	
	$(":input").change(function(){
		if($(this).val() != ""){
			ls.set($(this).attr("name"), $(this).val());
		}									
	});

	$("form").submit(function(){
		form = this; 
		$(form).find(":input").each(function(){	
			ls.set($(this).attr("name"), "");
		});				
	});	
});

Jag gillar jquery


<a id="mail"></a>

(function($) {
    $.fn.extend({
        mailLink: function(options) {
        
    		var defaults = {
                userName: "nobody",
                domainName: "localhost",
                topLevelDomain: ""    		                
            };

            var options = $.extend(defaults, options);
					    		
    		return this.each(function() {
    	    	var obj = $(this);
    	    	var emailAdress = options.userName + "@" + options.domainName + ( (options.topLevelDomain == "") ? "" : "." ) + options.topLevelDomain;  
    	    	obj.attr("href","mailto:" +emailAdress).text(emailAdress);
    		});
        }
    });
})(jQuery);

$(document).ready(function(){
$("#mail").mailLink({userName:'info', domainName:'reurl', topLevelDomain:'se'});
});