[8961] | 1 | /* file: ui.inputPosition.js - v1.0.0 | minified on 2011/01/27 with http://jscompress.com/ */ |
---|
| 2 | (function($) |
---|
| 3 | {var publicMethods={init:function(opt) |
---|
| 4 | {return this.each(function() |
---|
| 5 | {var $this=$(this),data=$this.data('options'),objects=$this.data('objects'),properties=$this.data('properties'),options={disabled:false,width:0,height:0,values:['center','corners','sides'],change:null};$this.data('options',options);if(!properties) |
---|
| 6 | {$this.data('properties',{initialized:false,value:'',isValid:true,radioH:0,radioW:0});properties=$this.data('properties');} |
---|
| 7 | if(!objects) |
---|
| 8 | {objects={container:$('<div/>',{'class':'ui-inputPosition',css:{width:'100%'}}),radios:{corners:[],sides:[],center:[]}};var name=$this.get(0).id,values=['TL','TR','BR','BL'];for(var i=0;i<values.length;i++) |
---|
| 9 | {objects.radios.corners.push($('<input>',{type:'radio',id:name+values[i],name:'ip_'+name,value:values[i],group:'corners'}).appendTo(objects.container));} |
---|
| 10 | values=['T','L','B','R'];for(var i=0;i<values.length;i++) |
---|
| 11 | {objects.radios.sides.push($('<input>',{type:'radio',id:name+values[i],name:'ip_'+name,value:values[i],group:'sides'}).appendTo(objects.container))} |
---|
| 12 | values=['C'];for(var i=0;i<values.length;i++) |
---|
| 13 | {objects.radios.center.push($('<input>',{type:'radio',id:name+values[i],name:'ip_'+name,value:values[i],group:'center'}).appendTo(objects.container))} |
---|
| 14 | objects.container.find('input').bind('click',function(event) |
---|
| 15 | {privateMethods.setValue($this,$(this).attr('value'),false);});$this.html('').append(objects.container);properties.radioW=objects.container.find('input').first().outerWidth()/2;properties.radioH=objects.container.find('input').first().outerHeight()/2;$this.css('padding',properties.radioH+'px '+properties.radioW+'px');$this.data('objects',objects);} |
---|
| 16 | privateMethods.setOptions($this,opt);});},destroy:function() |
---|
| 17 | {return this.each(function() |
---|
| 18 | {var $this=$(this),objects=$this.data('objects');objects.input.unbind().remove();objects.container.unbind().remove();$this.unbind('.inputPosition').css({width:'',height:''});});},options:function(value) |
---|
| 19 | {return this.each(function() |
---|
| 20 | {privateMethods.setOptions($(this),value);});},disabled:function(value) |
---|
| 21 | {if(value!=null) |
---|
| 22 | {return this.each(function() |
---|
| 23 | {privateMethods.setDisabled($(this),value);});} |
---|
| 24 | else |
---|
| 25 | {var options=this.data('options');if(options) |
---|
| 26 | {return(options.disabled);} |
---|
| 27 | else |
---|
| 28 | {return('');}}},width:function(value) |
---|
| 29 | {if(value!=null) |
---|
| 30 | {return this.each(function() |
---|
| 31 | {privateMethods.setWidth($(this),value);});} |
---|
| 32 | else |
---|
| 33 | {var options=this.data('options');if(options) |
---|
| 34 | {return(options.width);} |
---|
| 35 | else |
---|
| 36 | {return('');}}},height:function(value) |
---|
| 37 | {if(value!=null) |
---|
| 38 | {return this.each(function() |
---|
| 39 | {privateMethods.setHeight($(this),value);});} |
---|
| 40 | else |
---|
| 41 | {var options=this.data('options');if(options) |
---|
| 42 | {return(options.height);} |
---|
| 43 | else |
---|
| 44 | {return('');}}},values:function(value) |
---|
| 45 | {if(value!=null) |
---|
| 46 | {return this.each(function() |
---|
| 47 | {privateMethods.setValues($(this),value);});} |
---|
| 48 | else |
---|
| 49 | {var options=this.data('options');if(options) |
---|
| 50 | {return(options.values);} |
---|
| 51 | else |
---|
| 52 | {return('');}}},value:function(value) |
---|
| 53 | {if(value!=null) |
---|
| 54 | {return this.each(function() |
---|
| 55 | {privateMethods.setValue($(this),value,true);});} |
---|
| 56 | else |
---|
| 57 | {var properties=this.data('properties');return(properties.value);}},isValid:function(value) |
---|
| 58 | {if(value!=null) |
---|
| 59 | {return this.each(function() |
---|
| 60 | {privateMethods.setIsValid($(this),value);});} |
---|
| 61 | else |
---|
| 62 | {var properties=this.data('properties');return(properties.isValid);}},change:function(value) |
---|
| 63 | {if(value!=null&&$.isFunction(value)) |
---|
| 64 | {return this.each(function() |
---|
| 65 | {privateMethods.setEventChange($(this),value);});} |
---|
| 66 | else |
---|
| 67 | {var options=this.data('options');if(options) |
---|
| 68 | {return(options.change);} |
---|
| 69 | else |
---|
| 70 | {return(null);}}}};var privateMethods={setOptions:function(object,value) |
---|
| 71 | {var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setValues(object,(value.values!=null)?value.values:options.values);privateMethods.setHeight(object,(value.height!=null)?value.height:options.height,true);privateMethods.setWidth(object,(value.width!=null)?value.width:options.width,true);privateMethods.setValue(object,(value.value!=null)?value.value:options.value,true);privateMethods.setDisabled(object,(value.disabled!=null)?value.disabled:options.disabled);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);properties.initialized=true;},setIsValid:function(object,value) |
---|
| 72 | {var objects=object.data('objects'),properties=object.data('properties');if(properties.isValid!=value) |
---|
| 73 | {properties.isValid=value;if(properties.isValid) |
---|
| 74 | {objects.container.removeClass('ui-error');objects.input.removeClass('ui-error');} |
---|
| 75 | else |
---|
| 76 | {objects.container.addClass('ui-error');objects.input.addClass('ui-error');}} |
---|
| 77 | return(properties.isValid);},setDisabled:function(object,value) |
---|
| 78 | {var options=object.data('options'),properties=object.data('properties');if((!properties.initialized||options.disabled!=value)&&(value==true||value==false)) |
---|
| 79 | {options.disabled=value;} |
---|
| 80 | return(options.disabled);},setHeight:function(object,value) |
---|
| 81 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.height!=value)&&value>=0) |
---|
| 82 | {if(value==0) |
---|
| 83 | {options.height=value;objects.container.css('height','100%');} |
---|
| 84 | else |
---|
| 85 | {options.height=value;objects.container.css('height',options.height+'px');}} |
---|
| 86 | privateMethods.setRadioPosition(object);return(options.height);},setWidth:function(object,value) |
---|
| 87 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.width!=value)&&value>=0) |
---|
| 88 | {if(value==0) |
---|
| 89 | {options.width=value;objects.container.css('width','100%');} |
---|
| 90 | else |
---|
| 91 | {options.width=value;objects.container.css('width',options.width+'px');} |
---|
| 92 | privateMethods.setRadioPosition(object);} |
---|
| 93 | return(options.width);},setValues:function(object,value) |
---|
| 94 | {var options=object.data('options'),objects=object.data('objects');if(!$.isArray(value))value=[value];options.values=[];object.find('input').hide();for(var i=0;i<value.length;i++) |
---|
| 95 | {if(value[i]=='center'||value[i]=='corners'||value[i]=='sides') |
---|
| 96 | {options.values.push(value[i]);object.find('input[group='+value[i]+']').show();}} |
---|
| 97 | return(true);},setValue:function(object,value,apply) |
---|
| 98 | {var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(!(($.inArray('center',options.values)>-1&&value=='C')||($.inArray('corners',options.values)>-1&&(value=='TL'||value=='TR'||value=='BR'||value=='BL'))||($.inArray('sides',options.values)>-1&&(value=='L'||value=='R'||value=='B'||value=='T'))))return(false);properties.value=value;if(apply) |
---|
| 99 | {switch(properties.value) |
---|
| 100 | {case'TL':objects.radios.corners[0].attr('checked',true);break;case'TR':objects.radios.corners[1].attr('checked',true);break;case'BR':objects.radios.corners[2].attr('checked',true);break;case'BL':objects.radios.corners[3].attr('checked',true);break;case'T':objects.radios.sides[0].attr('checked',true);break;case'L':objects.radios.sides[1].attr('checked',true);break;case'B':objects.radios.sides[2].attr('checked',true);break;case'R':objects.radios.sides[3].attr('checked',true);break;case'C':objects.radios.center[0].attr('checked',true);break;}} |
---|
| 101 | if(options.change)object.trigger('inputPositionChange',properties.value);return(true);},setEventChange:function(object,value) |
---|
| 102 | {var options=object.data('options');options.change=value;object.unbind('inputPositionChange');if(value)object.bind('inputPositionChange',options.change);return(options.change);},setRadioPosition:function(object) |
---|
| 103 | {var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if($.inArray('center',options.values)>-1) |
---|
| 104 | {objects.radios.center[0].css({'margin-left':(options.width/2-properties.radioW)+'px','margin-top':(options.height/2-properties.radioH)+'px'});} |
---|
| 105 | if($.inArray('corners',options.values)>-1) |
---|
| 106 | {for(var i=0;i<objects.radios.corners.length;i++) |
---|
| 107 | {switch(objects.radios.corners[i].attr('value')) |
---|
| 108 | {case'TL':objects.radios.corners[i].css({'margin-left':'-'+properties.radioW+'px','margin-top':'-'+properties.radioH+'px'});break;case'TR':objects.radios.corners[i].css({'margin-left':(options.width-properties.radioW)+'px','margin-top':'-'+properties.radioH+'px'});break;case'BR':objects.radios.corners[i].css({'margin-left':(options.width-properties.radioW)+'px','margin-top':(options.height-properties.radioH)+'px'});break;case'BL':objects.radios.corners[i].css({'margin-left':'-'+properties.radioW+'px','margin-top':(options.height-properties.radioH)+'px'});break;}}} |
---|
| 109 | if($.inArray('sides',options.values)>-1) |
---|
| 110 | {w=objects.radios.sides[0].width();h=objects.radios.sides[0].height();for(var i=0;i<objects.radios.sides.length;i++) |
---|
| 111 | {switch(objects.radios.sides[i].attr('value')) |
---|
| 112 | {case'L':objects.radios.sides[i].css({'margin-left':'-'+properties.radioW+'px','margin-top':(options.height/2-properties.radioH)+'px'});break;case'T':objects.radios.sides[i].css({'margin-left':(options.width/2-properties.radioW)+'px','margin-top':'-'+properties.radioH+'px'});break;case'R':objects.radios.sides[i].css({'margin-left':(options.width-properties.radioW)+'px','margin-top':(options.height/2-properties.radioH)+'px'});break;case'B':objects.radios.sides[i].css({'margin-left':(options.width/2-properties.radioW)+'px','margin-top':(options.height-properties.radioH)+'px'});break;}}}}};$.fn.inputPosition=function(method) |
---|
| 113 | {if(publicMethods[method]) |
---|
| 114 | {return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));} |
---|
| 115 | else if(typeof method==='object'||!method) |
---|
| 116 | {return publicMethods.init.apply(this,arguments);} |
---|
| 117 | else |
---|
| 118 | {$.error('Method '+method+' does not exist on jQuery.inputPosition');}}})(jQuery); |
---|