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

Diff of /contributions/modules/ui/javascript/ui.resizable.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 10  Line 10 
10                  });                  });
11          }          }
12    
13          //Macros for external methods          //Macros for external methods that support chaining
14          var methods = "destroy,enable,disable".split(",");          var methods = "destroy,enable,disable".split(",");
15          for(var i=0;i<methods.length;i++) {          for(var i=0;i<methods.length;i++) {
16                  var cur = methods[i], f;                  var cur = methods[i], f;
17                  eval('f = function() { return this.each(function() { if($(this).is(".ui-resizable")) this.uiResizable["'+cur+'"](); }); }');                  eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-resizable")) jQuery.data(this, "ui-resizable")["'+cur+'"](a); if(jQuery(this.parentNode).is(".ui-resizable")) jQuery.data(this, "ui-resizable")["'+cur+'"](a); }); }');
18                  $.fn["resizable"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f;                  $.fn["resizable"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f;
19          };          };
20    
21            //get instance method
22            $.fn.resizableInstance = function() {
23                    if($(this[0]).is(".ui-resizable") || $(this[0].parentNode).is(".ui-resizable")) return $.data(this[0], "ui-resizable");
24                    return false;
25            };
26    
27    
28          $.ui.resizable = function(el,o) {          $.ui.resizable = function(el,o) {
29    
30                  var options = {}; o = o || {}; $.extend(options, o); //Extend and copy options                  var options = {}; o = o || {}; $.extend(options, o); //Extend and copy options
31                  this.element = el; var self = this; //Do bindings                  this.element = el; var self = this; //Do bindings
32                  this.element.uiResizable = this; //TODO: Real expando (this one causes memory leaks)                  $.data(this.element, "ui-resizable", this);
33    
34                  if(options.proxy) {                  if(options.proxy) {
35                          var helper = function(e,that) {                          var helper = function(e,that) {
# Line 40  Line 47 
47                  }                  }
48    
49                  //Destructive mode wraps the original element                  //Destructive mode wraps the original element
50                  if(el.nodeName.match(/textarea|input|select|button/i)) options.destructive = true;                  if(el.nodeName.match(/textarea|input|select|button|img/i)) options.destructive = true;
51                  if(options.destructive) {                  if(options.destructive) {
52    
53                          $(el).wrap('<div class="ui-wrapper"  style="position: relative; width: '+$(el).outerWidth()+'px; height: '+$(el).outerHeight()+';"></div>');                          $(el).wrap('<div class="ui-wrapper"  style="position: relative; width: '+$(el).outerWidth()+'px; height: '+$(el).outerHeight()+';"></div>');
# Line 50  Line 57 
57                          //Move margins to the wrapper                          //Move margins to the wrapper
58                          $(el).css({ marginLeft: $(oel).css("marginLeft"), marginTop: $(oel).css("marginTop"), marginRight: $(oel).css("marginRight"), marginBottom: $(oel).css("marginBottom")});                          $(el).css({ marginLeft: $(oel).css("marginLeft"), marginTop: $(oel).css("marginTop"), marginRight: $(oel).css("marginRight"), marginBottom: $(oel).css("marginBottom")});
59                          $(oel).css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});                          $(oel).css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
   
                         var t = function(a,b) { $(el).append("<div class='ui-resizable-"+a+" ui-resizable-handle' style='position: absolute; "+b+"'></div>"); };  
                         var b = [parseInt($(oel).css('borderTopWidth')),parseInt($(oel).css('borderRightWidth')),parseInt($(oel).css('borderBottomWidth')),parseInt($(oel).css('borderLeftWidth'))];  
                         t('n','top: '+b[0]+'px;');  
                         t('e','right: '+b[1]+'px;');  
                         t('s','bottom: '+b[1]+'px;');  
                         t('w','left: '+b[3]+'px;');  
                         t('se','bottom: '+b[2]+'px; right: '+b[1]+'px;');  
                         t('sw','bottom: '+b[2]+'px; left: '+b[3]+'px;');  
                         t('ne','top: '+b[0]+'px; right: '+b[1]+'px;');  
                         t('nw','top: '+b[0]+'px; left: '+b[3]+'px;');  
60    
61                          o.proportionallyResize = o.proportionallyResize || [];                          o.proportionallyResize = o.proportionallyResize || [];
62                          o.proportionallyResize.push(oel);                          o.proportionallyResize.push(oel);
63    
64                            var b = [parseInt($(oel).css('borderTopWidth')),parseInt($(oel).css('borderRightWidth')),parseInt($(oel).css('borderBottomWidth')),parseInt($(oel).css('borderLeftWidth'))];
65                    } else {
66                            var b = [0,0,0,0];
67                  }                  }
68    
69                    if(options.destructive || !$(".ui-resizable-handle",el).length) {
70                            //Adding handles (disabled not so common ones)
71                            var t = function(a,b) { $(el).append("<div class='ui-resizable-"+a+" ui-resizable-handle' style='"+b+"'></div>"); };
72                            //t('n','top: '+b[0]+'px;');
73                            t('e','right: '+b[1]+'px;'+(options.zIndex ? 'z-index: '+options.zIndex+';' : ''));
74                            t('s','bottom: '+b[1]+'px;'+(options.zIndex ? 'z-index: '+options.zIndex+';' : ''));
75                            //t('w','left: '+b[3]+'px;');
76                            t('se','bottom: '+b[2]+'px; right: '+b[1]+'px;'+(options.zIndex ? 'z-index: '+options.zIndex+';' : ''));
77                            //t('sw','bottom: '+b[2]+'px; left: '+b[3]+'px;');
78                            //t('ne','top: '+b[0]+'px; right: '+b[1]+'px;');
79                            //t('nw','top: '+b[0]+'px; left: '+b[3]+'px;');
80                    }
81    
82    
83    
84                  //If other elements should be modified, we have to copy that array                  //If other elements should be modified, we have to copy that array
85                  options.modifyThese = [];                  options.modifyThese = [];
86                  if(o.proportionallyResize) {                  if(o.proportionallyResize) {
# Line 102  Line 117 
117                          $(options.handles[i]).bind('mousedown', function(e) {                          $(options.handles[i]).bind('mousedown', function(e) {
118                                  self.interaction.options.axis = this.resizeAxis;                                  self.interaction.options.axis = this.resizeAxis;
119                          })[0].resizeAxis = i;                          })[0].resizeAxis = i;
120    
121                  }                  }
122    
123                    //If we want to auto hide the elements
124                    if(o.autohide)
125                            $(this.element).addClass("ui-resizable-autohide").hover(function() { $(this).removeClass("ui-resizable-autohide"); }, function() { if(self.interaction.options.autohide && !self.interaction.init) $(this).addClass("ui-resizable-autohide"); });
126    
127    
128                  $.extend(options, {                  $.extend(options, {
129                          helper: helper,                          helper: helper,
130                          nonDestructive: true,                          nonDestructive: true,
131                          dragPrevention: 'input,button,select',                          dragPrevention: 'input,button,select',
132                            minHeight: options.minHeight || 50,
133                            minWidth: options.minWidth || 100,
134                          startCondition: function(e) {                          startCondition: function(e) {
135                                  if(self.disabled) return false;                                  if(self.disabled) return false;
136                                  for(var i in options.handles) {                                  for(var i in options.handles) {
# Line 159  Line 182 
182                  start: function(that, e) {                  start: function(that, e) {
183                          this.options.originalSize = [$(this.element).width(),$(this.element).height()];                          this.options.originalSize = [$(this.element).width(),$(this.element).height()];
184                          this.options.originalPosition = $(this.element).css("position");                          this.options.originalPosition = $(this.element).css("position");
185                            this.options.originalPositionValues = $(this.element).position();
186    
187                          this.options.modifyThese.push([$(this.helper),0,0]);                          this.options.modifyThese.push([$(this.helper),0,0]);
188    
                         $.ui.plugin.call('start', that, this);  
189                          $(that.element).triggerHandler("resizestart", [e, that.prepareCallbackObj(this)], this.options.start);                          $(that.element).triggerHandler("resizestart", [e, that.prepareCallbackObj(this)], this.options.start);
190                          return false;                          return false;
191                  },                  },
# Line 170  Line 193 
193    
194                          var o = this.options;                          var o = this.options;
195    
                         $.ui.plugin.call('stop', that, this);  
196                          $(that.element).triggerHandler("resizestop", [e, that.prepareCallbackObj(this)], this.options.stop);                          $(that.element).triggerHandler("resizestop", [e, that.prepareCallbackObj(this)], this.options.stop);
197    
198                          if(o.proxy) {                          if(o.proxy) {
# Line 192  Line 214 
214                  drag: function(that, e) {                  drag: function(that, e) {
215    
216                          var o = this.options;                          var o = this.options;
217                          var co = o.co;                          var rel = (o.originalPosition != "absolute" && o.originalPosition != "fixed");
218                            var co = rel ? o.co : this.options.originalPositionValues;
219                          var p = o.originalSize;                          var p = o.originalSize;
220    
221                          this.pos = [this.rpos[0]-o.cursorAt.left, this.rpos[1]-o.cursorAt.top];                          this.pos = rel ? [this.rpos[0]-o.cursorAt.left, this.rpos[1]-o.cursorAt.top] : [this.pos[0]-o.cursorAt.left, this.pos[1]-o.cursorAt.top];
222    
223                          var nw = p[0] + (this.pos[0] - co.left);                          var nw = p[0] + (this.pos[0] - co.left);
224                          var nh = p[1] + (this.pos[1] - co.top);                          var nh = p[1] + (this.pos[1] - co.top);
225    
226                          if(o.axis) {                          if(o.axis) {
227                                  switch(o.axis) {                                  switch(o.axis) {
228                                          case 'e':                                          case 'e':
# Line 211  Line 234 
234                                          case 'n':                                          case 'n':
235                                          case 'ne':                                          case 'ne':
236    
237    
238                                                  if(!o.proxy && (o.originalPosition != "absolute" && o.originalPosition != "fixed"))                                                  if(!o.proxy && (o.originalPosition != "absolute" && o.originalPosition != "fixed"))
239                                                          return false;                                                          return false;
240    
# Line 251  Line 275 
275                                                  break;                                                  break;
276                                  }                                  }
277                          }                          }
278    
279                            if(e.shiftKey) nh = nw * (p[1]/p[0]);
280    
281                          if(o.minWidth) nw = nw <= o.minWidth ? o.minWidth : nw;                          if(o.minWidth) nw = nw <= o.minWidth ? o.minWidth : nw;
282                          if(o.minHeight) nh = nh <= o.minHeight ? o.minHeight : nh;                          if(o.minHeight) nh = nh <= o.minHeight ? o.minHeight : nh;
283    
284                          if(o.maxWidth) nw = nw >= o.maxWidth ? o.maxWidth : nw;                          if(o.maxWidth) nw = nw >= o.maxWidth ? o.maxWidth : nw;
285                          if(o.maxHeight) nh = nh >= o.maxHeight ? o.maxHeight : nh;                          if(o.maxHeight) nh = nh >= o.maxHeight ? o.maxHeight : nh;
286    
287                            if(e.shiftKey) nh = nw * (p[1]/p[0]);
288    
                         $.ui.plugin.call('resize', that, this);  
289                          var modifier = $(that.element).triggerHandler("resize", [e, that.prepareCallbackObj(this)], o.resize);                          var modifier = $(that.element).triggerHandler("resize", [e, that.prepareCallbackObj(this)], o.resize);
290                          if(!modifier) modifier = {};                          if(!modifier) modifier = {};
291    

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

  ViewVC Help
Powered by ViewVC 1.1.2