/[drupal]/contributions/modules/ui/javascript/ui.slider.js
ViewVC logotype

Diff of /contributions/modules/ui/javascript/ui.slider.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sun Sep 2 20:21:42 2007 UTC revision 1.2, Mon Sep 17 03:42:34 2007 UTC
# Line 2  Line 2 
2    
3    
4          //Web Forms 2.0          //Web Forms 2.0
5            window.webforms = 1;
6          if(window['webforms']) {          if(window['webforms']) {
7                  $(document).ready(function() {                  $(document).ready(function() {
8    
# Line 22  Line 23 
23                                          });                                          });
24                                          cur.css({ position: "absolute", opacity: 0, top: "-1000px", left: "-1000px" });                                          cur.css({ position: "absolute", opacity: 0, top: "-1000px", left: "-1000px" });
25    
                                         var name = (new Date()).getTime()+Math.random();  
26                                          slider.slider({                                          slider.slider({
27                                                  maxValue: cur.attr("max"),                                                  maxValue: cur.attr("max"),
28                                                  minValue: cur.attr("min"),                                                  minValue: cur.attr("min"),
29                                                  startValue: this.getAttribute("value"),                                                  startValue: this.getAttribute("value"),
30                                                  stepping: cur.attr("step"),                                                  stepping: cur.attr("step"),
31                                                  change: function(e, ui) { cur[0].value = ui.value; cur[0].setAttribute("value", ui.value); },                                                  change: function(e, ui) { cur[0].value = ui.value; cur[0].setAttribute("value", ui.value); },
                                                 name: name  
32                                          });                                          });
33                                          slider = $.ui.get(name, "slider")[0];  
34                                            slider = slider.sliderInstance();
35    
36                                          cur.bind("keydown", function(e) {                                          cur.bind("keydown", function(e) {
37                                                  var o = slider.interaction.options;                                                  var o = slider.interaction.options;
38                                                  switch(e.keyCode) {                                                  switch(e.keyCode) {
39                                                          case 37:                                                          case 37:
40                                                                  slider.goto(o.curValue+o.minValue-(o.stepping || 1));                                                                  slider.moveTo(slider.interaction.curValue+o.minValue-(o.stepping || 1));
41                                                                  break;                                                                  break;
42                                                          case 39:                                                          case 39:
43                                                                  slider.goto(o.curValue+o.minValue+(o.stepping || 1));                                                                  slider.moveTo(slider.interaction.curValue+o.minValue+(o.stepping || 1));
44                                                                  break;                                                                  break;
45                                                  }                                                  }
46                                                  if(e.keyCode != 9) return false;                                                  if(e.keyCode != 9) return false;
# Line 51  Line 51 
51    
52                  });                  });
53          }          }
54    
55            //Make nodes selectable by expression
56            $.extend($.expr[':'], { slider: "(' '+a.className+' ').indexOf(' ui-slider ')" });
57    
58          $.fn.slider = function(o) {          $.fn.slider = function(o) {
59                  return this.each(function() {                  return this.each(function() {
# Line 58  Line 61 
61                  });                  });
62          }          }
63    
64            //Macros for external methods that support chaining
65            var methods = "destroy,enable,disable,moveTo".split(",");
66            for(var i=0;i<methods.length;i++) {
67                    var cur = methods[i], f;
68                    eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-slider")) jQuery.data(this, "ui-slider")["'+cur+'"](a); }); }');
69                    $.fn["slider"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f;
70            };
71    
72            //get instance method
73            $.fn.sliderInstance = function() {
74                    if($(this[0]).is(".ui-slider")) return $.data(this[0], "ui-slider");
75                    return false;
76            };
77    
78          $.ui.slider = function(el, o) {          $.ui.slider = function(el, o) {
79    
80                  var options = {};                  var options = {};
# Line 76  Line 93 
93                          },                          },
94                          _drag: function(h, p, c, t, e) {                          _drag: function(h, p, c, t, e) {
95                                  self.drag.apply(t, [self, e]); // Trigger the start callback                                  self.drag.apply(t, [self, e]); // Trigger the start callback
96                            },
97                            startCondition: function() {
98                                    return !self.disabled;
99                          }                          }
100                  });                  });
101    
102                  var self = this;                  var self = this;
103                  var o = options;                  var o = options;
104                    $.data(el, "ui-slider", this);
105                  o.stepping = parseInt(o.stepping) || (o.steps ? o.maxValue/o.steps : 0);                  o.stepping = parseInt(o.stepping) || (o.steps ? o.maxValue/o.steps : 0);
106                  o.realValue = (o.maxValue - o.minValue);                  o.realValue = (o.maxValue - o.minValue);
107    
# Line 98  Line 119 
119                  }                  }
120    
121                  this.element = el;                  this.element = el;
122                    $(this.element).addClass("ui-slider");
123    
124    
125                  if(o.axis == 'horizontal') {                  if(o.axis == 'horizontal') {
# Line 112  Line 134 
134    
135                  if(!this.multipleHandles) {                  if(!this.multipleHandles) {
136                          $(el).bind('click', function(e) { self.click.apply(self, [e]); });                          $(el).bind('click', function(e) { self.click.apply(self, [e]); });
137                          if(!isNaN(o.startValue)) this.goto(o.startValue,options.realValue, null, false);                          if(!isNaN(o.startValue)) this.moveTo(o.startValue,options.realValue, null, false);
138                  }                  }
139    
140          }          }
# Line 120  Line 142 
142          $.extend($.ui.slider.prototype, {          $.extend($.ui.slider.prototype, {
143                  currentTarget: null,                  currentTarget: null,
144                  lastTarget: null,                  lastTarget: null,
145                    destroy: function() {
146                            $(this.element).removeClass("ui-slider").removeClass("ui-slider-disabled");
147                            this.interaction.destroy();
148                    },
149                    enable: function() {
150                            $(this.element).removeClass("ui-slider-disabled");
151                            this.disabled = false;
152                    },
153                    disable: function() {
154                            $(this.element).addClass("ui-slider-disabled");
155                            this.disabled = true;
156                    },
157                  nonvalidRange: function(self) {                  nonvalidRange: function(self) {
158    
159                          for(var i=0;i<this.interactions.length;i++) {                          for(var i=0;i<this.interactions.length;i++) {
# Line 160  Line 194 
194                          var o = this.interaction.options;                          var o = this.interaction.options;
195                          var pointer = [e.pageX,e.pageY];                          var pointer = [e.pageX,e.pageY];
196                          var offset = $(this.interaction.element).offsetParent().offset({ border: false });                          var offset = $(this.interaction.element).offsetParent().offset({ border: false });
197                          if(this.interaction.element == e.target) return;                          if(this.interaction.element == e.target || this.disabled) return;
198    
199                          this.interaction.pickValue = this.interaction.curValue;                          this.interaction.pickValue = this.interaction.curValue;
200                          this.drag.apply(this.interaction, [this, e, [pointer[0]-offset.left-this.handle[0].offsetWidth/2,pointer[1]-offset.top-this.handle[0].offsetHeight/2]]);                          this.drag.apply(this.interaction, [this, e, [pointer[0]-offset.left-this.handle[0].offsetWidth/2,pointer[1]-offset.top-this.handle[0].offsetHeight/2]]);
# Line 182  Line 216 
216    
217                          var o = this.options;                          var o = this.options;
218                          $(that.element).triggerHandler("slidestop", [e, that.prepareCallbackObj(this)], o.stop);                          $(that.element).triggerHandler("slidestop", [e, that.prepareCallbackObj(this)], o.stop);
219                          if(this.pickValue != this.curValue) $.ui.trigger('change', this, e, that.prepareCallbackObj(this));                          if(this.pickValue != this.curValue) $(that.element).triggerHandler("slidechange", [e, that.prepareCallbackObj(this)], o.change);
220    
221                          return false;                          return false;
222    
# Line 221  Line 255 
255                          return false;                          return false;
256    
257                  },                  },
258                  goto: function(value,scale,changeslide,p) {                  moveTo: function(value,scale,changeslide,p) {   // renamed from goto to moveTo as goto is reserved javascript word
259    
260                          if(this.multipleHandles) return false; //TODO: Multiple handle goto function                          if(this.multipleHandles) return false; //TODO: Multiple handle moveTo function
261    
262                          var o = this.interaction.options;                          var o = this.interaction.options;
263                          var offset = $(this.interaction.element).offsetParent().offset({ border: false });                          var offset = $(this.interaction.element).offsetParent().offset({ border: false });

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2