/* * jQuery Field Plug-in * * Copyright (c) 2007 Dan G. Switzer, II * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: 14 * Version: 0.9.2 */ (function($){var defaults={delimiter:",",checkboxRangeKeyBinding:"shiftKey",useArray:false};$.Field={version:"0.9.2",setDefaults:function(options){$.extend(defaults,options)},setProperty:function(prop,value){defaults[prop]=value},getProperty:function(prop){return defaults[prop]}};$.fn.fieldArray=function(v){var t=$type(v);if(t=="undefined")return getValue(this);if(t=="string"||t=="number"){v=v.toString().split(defaults.delimiter);t="array"}if(t=="array")return setValue(this,v);return this};$.fn.getValue=function(){return getValue(this).join(defaults.delimiter)};var getValue=function(jq){var v=[];jq.each(function(lc){var t=getType(this);switch(t){case"checkbox":case"radio":if(this.checked)v.push(this.value);break;case"select":if(this.type=="select-one"){v.push((this.selectedIndex==-1)?"":getOptionVal(this[this.selectedIndex]))}else{for(var i=0;i-1))return true;if($field.getValue().length>=$field.attr("maxlength")){var $next=$field.moveNext().select();if($.isFunction(callback))callback.apply($field,[$next])}})};$.fn.moveNext=function(){return this.moveIndex("next")};$.fn.movePrev=function(){return this.moveIndex("prev")};$.fn.moveIndex=function(i){var aPos=getFieldPosition(this);if(i=="next")i=aPos[0]+1;else if(i=="prev")i=aPos[0]-1;if(i<0)i=aPos[1].length-1;else if(i>=aPos[1].length)i=0;return $(aPos[1][i]).trigger("focus")};$.fn.getTabIndex=function(){return getFieldPosition(this)[0]};var getFieldPosition=function(jq){var $field=jq.filter("input, select, textarea").get(0),aTabIndex=[],aPosIndex=[];if(!$field)return[-1,[]];$.each($field.form.elements,function(i,o){if(o.tagName!="FIELDSET"&&!o.disabled){if(o.tabIndex>0){aTabIndex.push(o)}else{aPosIndex.push(o)}}});aTabIndex.sort(function(a,b){return a.tabIndex-b.tabIndex});aTabIndex=$.merge(aTabIndex,aPosIndex);for(var i=0;iopt.limit){return(this.type=="select-multiple")?undoSelect():opt.onfailure.apply(self,[opt.limit])}opt.onsuccess.apply(self,[opt.limit]);return true})};$.fn.createCheckboxRange=function(callback){var opt=jQuery.extend((callback&&callback.constructor==Object?callback:{bind:defaults.checkboxRangeKeyBinding,onclick:callback}),callback);var iLastSelection=0,self=this,bCallback=$.isFunction(opt.onclick);if(bCallback)this.each(function(){opt.onclick.apply(this,[$(this).is(":checked")])});return this.each(function(){if(this.type!="checkbox")return false;var el=this;var updateLastCheckbox=function(e){iLastSelection=self.index(e.target)};var checkboxClicked=function(e){var bSetChecked=this.checked,current=self.index(e.target),low=Math.min(iLastSelection,current),high=Math.max(iLastSelection+1,current);if(bCallback)$(this).each(function(){opt.onclick.apply(this,[bSetChecked])});if(!e[opt.bind])return;for(var i=low;i-1)};var $type=function(o){var t=(typeof o).toLowerCase();if(t=="object"){if(o instanceof Array)t="array";else if(o instanceof Date)t="date"}return t};var $isType=function(o,v){return($type(o)==String(v).toLowerCase())}})(jQuery);