you are in: codestackercodes [RSS] → tag: prototype [RSS]

explode function like php Delicious Email

show/hide lines
   1  String.prototype.explode = function(separator:String) {
   2  	var string = this;
   3  	var list = new Array();
   4  
   5  	if (separator == null) return false;
   6  	if (string == null) return false;
   7  
   8  	var currentStringPosition = 0;
   9  	while (currentStringPosition<string.length) {
  10  		var nextIndex = string.indexOf(separator, currentStringPosition);
  11  		if (nextIndex == -1) break;
  12  		var word = string.slice(currentStringPosition, nextIndex);
  13  		list.push(word);
  14  		currentStringPosition = nextIndex+1;
  15  	}
  16  	if (list.length<1) {
  17  		list.push(string);
  18  	} else {
  19  		list.push(string.slice(currentStringPosition, string.length));
  20  	}
  21  	return list;
  22  }
  23  
  24  var mystring = "test1 - test2";
  25  exploded = mystring.explode(" - ");
  26  trace (exploded[0]); // returns 'test1'
created by leozera — 09 December 2008 — get a short url — tags: actionscript flash prototype embed

realtime email validation Delicious Email

requires prototype and script.aculo.us
demo: http://ajaxorized.com/examples/scriptaculous/email.html

show/hide lines
   1  var isValid = false;
   2  
   3  validateEmail = function(e) {
   4  	if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
   5  		if(!isValid) {
   6  			$(e).morph('border-color:#00FF00', {duration:.3});
   7  			isValid = true;
   8  		}
   9  	} else {
  10  		if(isValid) {
  11  			$(e).morph('border-color:#FF0000', {duration:.3});						
  12  			isValid = false;					
  13  		}
  14  	}	
  15  }
  16  
  17  // <input type = "email" id = "myinput" onKeyUp = "validateEmail(this)" />
created by leozera — 22 November 2008 — get a short url — tags: javascript prototype scriptaculous validation embed

[prototype] adding input:focus functionality to ie Delicious Email

show/hide lines
   1  Event.observe(window, 'load', function() { 
   2  var fields = $$("input"); 
   3  for (var i = 0; i fields[i].onfocus = function() {this.className += ' focused';} 
   4  fields[i].onblur = function() {this.className = this.className.replace('focused', '');} 
   5  } 
   6  }); 
   7  
   8  // in css, paste
   9  // input:focus, /* works in FF without javascript */ 
  10  // input.focused /* used by js */ 
  11  // { background-color: #f7cd72; } 
created by leozera — 18 November 2008 — get a short url — tags: hack ie6 javascript prototype embed

passing extra parameters to prototype observer handlers Delicious Email

a simple listener: $(‘myForm’).observe(‘submit’, validateMyForm) dont support extra params in the function (in the case, validateMyForm. the solution:

show/hide lines
   1  $('myForm').observe('submit', function(event) {  
   2      validateMyForm(event, param1, param2);  
   3  }); 
created by leozera — 05 August 2008 — get a short url — tags: javascript prototype embed