source: extensions/GrumPluginClasses/js/ui.inputDotArea.min.js @ 8961

Last change on this file since 8961 was 8961, checked in by grum, 13 years ago

release 3.4.0
fix bug:1984, bug:2109
js file are minified, remove packed files

  • Property svn:executable set to *
File size: 7.0 KB
Line 
1/* file: ui.inputDotArea.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={range:{x:[0,100],y:[0,100]},width:0,height:0,disabled:false,change:null};$this.data('options',options);if(!properties)
6{$this.data('properties',{initialized:false,values:{x:50,y:50},isValid:true,mouseIsDown:false});properties=$this.data('properties');}
7if(!objects)
8{objects={container:$('<div/>',{'class':'ui-inputDotArea',css:{width:'100%',height:'100%'}}).bind('mousedown.inputDotArea',function(event)
9{privateMethods.mouseDown($this,event);}).bind('mouseup.inputDotArea',function(event)
10{privateMethods.mouseUp($this,event);}).bind('mousemove.inputDotArea',function(event)
11{privateMethods.mouseMove($this,event);}),dot:$('<div/>',{'class':'ui-inputDotArea-dot'})};$this.html('').append(objects.container.append(objects.dot));$this.data('objects',objects);}
12privateMethods.setOptions($this,opt);});},destroy:function()
13{return this.each(function()
14{var $this=$(this),objects=$this.data('objects');objects.dot.remove();objects.container.unbind().remove();$this.unbind('.inputDotArea').css({width:'',height:''});});},options:function(value)
15{return(this.each(function()
16{privateMethods.setOptions($(this),value);}));},disabled:function(value)
17{if(value!=null)
18{return(this.each(function()
19{privateMethods.setDisabled($(this),value);}));}
20else
21{var options=this.data('options');if(options)
22{return(options.disabled);}
23else
24{return('');}}},width:function(value)
25{if(value!=null)
26{return(this.each(function()
27{privateMethods.setWidth($(this),value,true);}));}
28else
29{var options=this.data('options');return(options.width);}},height:function(value)
30{if(value!=null)
31{return(this.each(function()
32{privateMethods.setHeight($(this),value,true);}));}
33else
34{var options=this.data('options');return(options.height);}},range:function(value)
35{if(value!=null)
36{return(this.each(function()
37{privateMethods.setRange($(this),value,true);}));}
38else
39{var options=this.data('options');return(options.range);}},values:function(value)
40{if(value!=null)
41{return(this.each(function()
42{privateMethods.setValues($(this),value,true);}));}
43else
44{var properties=this.data('properties');return(properties.values);}},isValid:function(value)
45{if(value!=null)
46{return(this.each(function()
47{privateMethods.setIsValid($(this),value);}));}
48else
49{var properties=this.data('properties');return(properties.isValid);}},change:function(value)
50{if(value!=null&&$.isFunction(value))
51{return(this.each(function()
52{privateMethods.setEventChange($(this),value);}));}
53else
54{var options=this.data('options');if(options)
55{return(options.change);}
56else
57{return(null);}}}};var privateMethods={setOptions:function(object,value)
58{var properties=object.data('properties'),options=object.data('options');if(!$.isPlainObject(value))return(false);properties.initialized=false;privateMethods.setWidth(object,(value.width!=null)?value.width:options.width);privateMethods.setHeight(object,(value.height!=null)?value.height:options.height);privateMethods.setRange(object,(value.range!=null)?value.range:options.range);privateMethods.setValues(object,(value.values!=null)?value.values:properties.values,true);privateMethods.setEventChange(object,(value.change!=null)?value.change:options.change);properties.initialized=true;},setIsValid:function(object,value)
59{var objects=object.data('objects'),properties=object.data('properties');return(properties.isValid);},setWidth:function(object,value)
60{var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.width!=value)&&value>0)
61{options.width=value;objects.container.css('width',options.width+'px');}
62return(options.width);},setHeight:function(object,value)
63{var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.height!=value)&&value>0)
64{options.height=value;objects.container.css('height',options.height+'px');}
65return(options.height);},setDisabled:function(object,value)
66{var options=object.data('options'),objects=object.data('objects'),properties=object.data('properties');if((!properties.initialized||options.disabled!=value)&&(value==true||value==false))
67{options.disabled=value;objects.input.attr('disabled',options.disabled);}
68return(options.disabled);},setRange:function(object,value)
69{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects');if(value.x==false||($.isArray(value.x)&&value.x[0]<=value.x[1]))
70{options.range.x=value.x;}
71if(value.y==false||($.isArray(value.y)&&value.y[0]<=value.y[1]))
72{options.range.y=value.y;}
73return(options.range);},setValues:function(object,value,apply)
74{var options=object.data('options'),properties=object.data('properties'),objects=object.data('objects'),tmp={x:'',y:''};if(!((value.x==null||(value.x!=null&&options.range.x[0]<=value.x&&value.x<=options.range.x[1]))&&(value.y==null||(value.y!=null&&options.range.y[0]<=value.y&&value.y<=options.range.y[1]))&&!(value.x==null&&value.y==null)))
75{return(false);}
76if(value.x!=null)properties.values.x=value.x;if(value.y!=null)properties.values.y=value.y;if(apply)
77{if(options.range.x==false)
78{tmp.x=options.width/2;}
79else
80{tmp.x=properties.values.x*options.width/(options.range.x[1]-options.range.x[0])+options.range.x[0];}
81tmp.x-=6;if(options.range.y==false)
82{tmp.y=options.height/2;}
83else
84{tmp.y=properties.values.y*options.height/(options.range.y[1]-options.range.y[0])+options.range.y[0];}
85tmp.y-=6;objects.dot.css({top:tmp.y+'px',left:tmp.x+'px'});}
86if(options.change)object.trigger('inputDotAreaChange',properties.values);return(true);},setEventChange:function(object,value)
87{var options=object.data('options');options.change=value;object.unbind('inputDotAreaChange');if(value)object.bind('inputDotAreaChange',options.change);return(options.change);},mouseDown:function(object,event)
88{var properties=object.data('properties');properties.mouseIsDown=true;privateMethods.mouseMove(object,event);},mouseUp:function(object,event)
89{var properties=object.data('properties');properties.mouseIsDown=false;},mouseMove:function(object,event)
90{var properties=object.data('properties'),objects=object.data('objects'),options=object.data('options'),values={};if(properties.mouseIsDown)
91{event.layerX=event.pageX-objects.container.offset().left;event.layerY=event.pageY-objects.container.offset().top;if(options.range.x!=false)
92{values.x=options.range.x[0]+event.layerX*(options.range.x[1]-options.range.x[0])/options.width;}
93if(options.range.y!=false)
94{values.y=options.range.y[0]+event.layerY*(options.range.y[1]-options.range.y[0])/options.height;}
95privateMethods.setValues(object,values,true);}}};$.fn.inputDotArea=function(method)
96{if(publicMethods[method])
97{return publicMethods[method].apply(this,Array.prototype.slice.call(arguments,1));}
98else if(typeof method==='object'||!method)
99{return publicMethods.init.apply(this,arguments);}
100else
101{$.error('Method '+method+' does not exist on jQuery.inputDotArea');}}})(jQuery);
Note: See TracBrowser for help on using the repository browser.