[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/jquery_ui/jquery.ui.old/ui/ -> ui.core.js (source)

   1  /*

   2   * jQuery UI 1.6

   3   *

   4   * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about)

   5   * Dual licensed under the MIT (MIT-LICENSE.txt)

   6   * and GPL (GPL-LICENSE.txt) licenses.

   7   *

   8   * http://docs.jquery.com/UI

   9   */
  10  ;(function($) {
  11  
  12  var _remove = $.fn.remove,
  13      isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);
  14  
  15  //Helper functions and ui object

  16  $.ui = {
  17  
  18      version: "1.6",
  19  
  20      // $.ui.plugin is deprecated.  Use the proxy pattern instead.

  21      plugin: {
  22          add: function(module, option, set) {
  23              var proto = $.ui[module].prototype;
  24              for(var i in set) {
  25                  proto.plugins[i] = proto.plugins[i] || [];
  26                  proto.plugins[i].push([option, set[i]]);
  27              }
  28          },
  29          call: function(instance, name, args) {
  30              var set = instance.plugins[name];
  31              if(!set) { return; }
  32  
  33              for (var i = 0; i < set.length; i++) {
  34                  if (instance.options[set[i][0]]) {
  35                      set[i][1].apply(instance.element, args);
  36                  }
  37              }
  38          }
  39      },
  40  
  41      contains: function(a, b) {
  42          var safari2 = $.browser.safari && $.browser.version < 522;
  43          if (a.contains && !safari2) {
  44              return a.contains(b);
  45          }
  46          if (a.compareDocumentPosition)
  47              return !!(a.compareDocumentPosition(b) & 16);
  48          while (b = b.parentNode)
  49                if (b == a) return true;
  50          return false;
  51      },
  52  
  53      cssCache: {},
  54      css: function(name) {
  55          if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
  56          var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
  57  
  58          //if (!$.browser.safari)

  59              //tmp.appendTo('body');

  60  
  61          //Opera and Safari set width and height to 0px instead of auto

  62          //Safari returns rgba(0,0,0,0) when bgcolor is not set

  63          $.ui.cssCache[name] = !!(
  64              (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
  65              !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
  66          );
  67          try { $('body').get(0).removeChild(tmp.get(0));    } catch(e){}
  68          return $.ui.cssCache[name];
  69      },
  70  
  71      hasScroll: function(el, a) {
  72  
  73          //If overflow is hidden, the element might have extra content, but the user wants to hide it

  74          if ($(el).css('overflow') == 'hidden') { return false; }
  75  
  76          var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
  77              has = false;
  78  
  79          if (el[scroll] > 0) { return true; }
  80  
  81          // TODO: determine which cases actually cause this to happen

  82          // if the element doesn't have the scroll set, see if it's possible to

  83          // set the scroll

  84          el[scroll] = 1;
  85          has = (el[scroll] > 0);
  86          el[scroll] = 0;
  87          return has;
  88      },
  89  
  90      isOverAxis: function(x, reference, size) {
  91          //Determines when x coordinate is over "b" element axis

  92          return (x > reference) && (x < (reference + size));
  93      },
  94  
  95      isOver: function(y, x, top, left, height, width) {
  96          //Determines when x, y coordinates is over "b" element

  97          return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
  98      },
  99  
 100      keyCode: {
 101          BACKSPACE: 8,
 102          CAPS_LOCK: 20,
 103          COMMA: 188,
 104          CONTROL: 17,
 105          DELETE: 46,
 106          DOWN: 40,
 107          END: 35,
 108          ENTER: 13,
 109          ESCAPE: 27,
 110          HOME: 36,
 111          INSERT: 45,
 112          LEFT: 37,
 113          NUMPAD_ADD: 107,
 114          NUMPAD_DECIMAL: 110,
 115          NUMPAD_DIVIDE: 111,
 116          NUMPAD_ENTER: 108,
 117          NUMPAD_MULTIPLY: 106,
 118          NUMPAD_SUBTRACT: 109,
 119          PAGE_DOWN: 34,
 120          PAGE_UP: 33,
 121          PERIOD: 190,
 122          RIGHT: 39,
 123          SHIFT: 16,
 124          SPACE: 32,
 125          TAB: 9,
 126          UP: 38
 127      }
 128  
 129  };
 130  
 131  // WAI-ARIA normalization

 132  if (isFF2) {
 133      var attr = $.attr,
 134          removeAttr = $.fn.removeAttr,
 135          ariaNS = "http://www.w3.org/2005/07/aaa",
 136          ariaState = /^aria-/,
 137          ariaRole = /^wairole:/;
 138  
 139      $.attr = function(elem, name, value) {
 140          var set = value !== undefined;
 141  
 142          return (name == 'role'
 143              ? (set
 144                  ? attr.call(this, elem, name, "wairole:" + value)
 145                  : (attr.apply(this, arguments) || "").replace(ariaRole, ""))
 146              : (ariaState.test(name)
 147                  ? (set
 148                      ? elem.setAttributeNS(ariaNS,
 149                          name.replace(ariaState, "aaa:"), value)
 150                      : attr.call(this, elem, name.replace(ariaState, "aaa:")))
 151                  : attr.apply(this, arguments)));
 152      };
 153  
 154      $.fn.removeAttr = function(name) {
 155          return (ariaState.test(name)
 156              ? this.each(function() {
 157                  this.removeAttributeNS(ariaNS, name.replace(ariaState, ""));
 158              }) : removeAttr.call(this, name));
 159      };
 160  }
 161  
 162  //jQuery plugins

 163  $.fn.extend({
 164  
 165      remove: function() {
 166          // Safari has a native remove event which actually removes DOM elements,

 167          // so we have to use triggerHandler instead of trigger (#3037).

 168          $("*", this).add(this).each(function() {
 169              $(this).triggerHandler("remove");
 170          });
 171          return _remove.apply(this, arguments );
 172      },
 173  
 174      enableSelection: function() {
 175          return this
 176              .attr('unselectable', 'off')
 177              .css('MozUserSelect', '')
 178              .unbind('selectstart.ui');
 179      },
 180  
 181      disableSelection: function() {
 182          return this
 183              .attr('unselectable', 'on')
 184              .css('MozUserSelect', 'none')
 185              .bind('selectstart.ui', function() { return false; });
 186      },
 187  
 188      scrollParent: function() {
 189  
 190          var scrollParent;
 191          if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
 192              scrollParent = this.parents().filter(function() {
 193                  return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
 194              }).eq(0);
 195          } else {
 196              scrollParent = this.parents().filter(function() {
 197                  return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
 198              }).eq(0);
 199          }
 200  
 201          return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
 202  
 203  
 204      }
 205  
 206  });
 207  
 208  
 209  //Additional selectors

 210  $.extend($.expr[':'], {
 211  
 212      data: function(a, i, m) {
 213          return $.data(a, m[3]);
 214      },
 215  
 216      // TODO: add support for object, area

 217      tabbable: function(a, i, m) {
 218  
 219          var nodeName = a.nodeName.toLowerCase();
 220  		function isVisible(element) {
 221              return !($(element).is(':hidden') || $(element).parents(':hidden').length);
 222          }
 223  
 224          return (
 225              // in tab order

 226              a.tabIndex >= 0 &&
 227  
 228              ( // filter node types that participate in the tab order
 229  
 230                  // anchor tag

 231                  ('a' == nodeName && a.href) ||
 232  
 233                  // enabled form element

 234                  (/input|select|textarea|button/.test(nodeName) &&
 235                      'hidden' != a.type && !a.disabled)
 236              ) &&
 237  
 238              // visible on page

 239              isVisible(a)
 240          );
 241  
 242      }
 243  
 244  });
 245  
 246  
 247  // $.widget is a factory to create jQuery plugins

 248  // taking some boilerplate code out of the plugin code

 249  function getter(namespace, plugin, method, args) {
 250  	function getMethods(type) {
 251          var methods = $[namespace][plugin][type] || [];
 252          return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
 253      }
 254  
 255      var methods = getMethods('getter');
 256      if (args.length == 1 && typeof args[0] == 'string') {
 257          methods = methods.concat(getMethods('getterSetter'));
 258      }
 259      return ($.inArray(method, methods) != -1);
 260  }
 261  
 262  $.widget = function(name, prototype) {
 263      var namespace = name.split(".")[0];
 264      name = name.split(".")[1];
 265  
 266      // create plugin method

 267      $.fn[name] = function(options) {
 268          var isMethodCall = (typeof options == 'string'),
 269              args = Array.prototype.slice.call(arguments, 1);
 270  
 271          // prevent calls to internal methods

 272          if (isMethodCall && options.substring(0, 1) == '_') {
 273              return this;
 274          }
 275  
 276          // handle getter methods

 277          if (isMethodCall && getter(namespace, name, options, args)) {
 278              var instance = $.data(this[0], name);
 279              return (instance ? instance[options].apply(instance, args)
 280                  : undefined);
 281          }
 282  
 283          // handle initialization and non-getter methods

 284          return this.each(function() {
 285              var instance = $.data(this, name);
 286  
 287              // constructor

 288              (!instance && !isMethodCall &&
 289                  $.data(this, name, new $[namespace][name](this, options)));
 290  
 291              // method call

 292              (instance && isMethodCall && $.isFunction(instance[options]) &&
 293                  instance[options].apply(instance, args));
 294          });
 295      };
 296  
 297      // create widget constructor

 298      $[namespace] = $[namespace] || {};
 299      $[namespace][name] = function(element, options) {
 300          var self = this;
 301  
 302          this.widgetName = name;
 303          this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
 304          this.widgetBaseClass = namespace + '-' + name;
 305  
 306          this.options = $.extend({},
 307              $.widget.defaults,
 308              $[namespace][name].defaults,
 309              $.metadata && $.metadata.get(element)[name],
 310              options);
 311  
 312          this.element = $(element)
 313              .bind('setData.' + name, function(event, key, value) {
 314                  return self._setData(key, value);
 315              })
 316              .bind('getData.' + name, function(event, key) {
 317                  return self._getData(key);
 318              })
 319              .bind('remove', function() {
 320                  return self.destroy();
 321              });
 322  
 323          this._init();
 324      };
 325  
 326      // add widget prototype

 327      $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
 328  
 329      // TODO: merge getter and getterSetter properties from widget prototype

 330      // and plugin prototype

 331      $[namespace][name].getterSetter = 'option';
 332  };
 333  
 334  $.widget.prototype = {
 335      _init: function() {},
 336      destroy: function() {
 337          this.element.removeData(this.widgetName);
 338      },
 339  
 340      option: function(key, value) {
 341          var options = key,
 342              self = this;
 343  
 344          if (typeof key == "string") {
 345              if (value === undefined) {
 346                  return this._getData(key);
 347              }
 348              options = {};
 349              options[key] = value;
 350          }
 351  
 352          $.each(options, function(key, value) {
 353              self._setData(key, value);
 354          });
 355      },
 356      _getData: function(key) {
 357          return this.options[key];
 358      },
 359      _setData: function(key, value) {
 360          this.options[key] = value;
 361  
 362          if (key == 'disabled') {
 363              this.element[value ? 'addClass' : 'removeClass'](
 364                  this.widgetBaseClass + '-disabled');
 365          }
 366      },
 367  
 368      enable: function() {
 369          this._setData('disabled', false);
 370      },
 371      disable: function() {
 372          this._setData('disabled', true);
 373      },
 374  
 375      _trigger: function(type, event, data) {
 376          var eventName = (type == this.widgetEventPrefix
 377              ? type : this.widgetEventPrefix + type);
 378          event = event || $.event.fix({ type: eventName, target: this.element[0] });
 379          return this.element.triggerHandler(eventName, [event, data], this.options[type]);
 380      }
 381  };
 382  
 383  $.widget.defaults = {
 384      disabled: false
 385  };
 386  
 387  
 388  /** Mouse Interaction Plugin **/

 389  
 390  $.ui.mouse = {
 391      _mouseInit: function() {
 392          var self = this;
 393  
 394          this.element
 395              .bind('mousedown.'+this.widgetName, function(event) {
 396                  return self._mouseDown(event);
 397              })
 398              .bind('click.'+this.widgetName, function(event) {
 399                  if(self._preventClickEvent) {
 400                      self._preventClickEvent = false;
 401                      return false;
 402                  }
 403              });
 404  
 405          // Prevent text selection in IE

 406          if ($.browser.msie) {
 407              this._mouseUnselectable = this.element.attr('unselectable');
 408              this.element.attr('unselectable', 'on');
 409          }
 410  
 411          this.started = false;
 412      },
 413  
 414      // TODO: make sure destroying one instance of mouse doesn't mess with

 415      // other instances of mouse

 416      _mouseDestroy: function() {
 417          this.element.unbind('.'+this.widgetName);
 418  
 419          // Restore text selection in IE

 420          ($.browser.msie
 421              && this.element.attr('unselectable', this._mouseUnselectable));
 422      },
 423  
 424      _mouseDown: function(event) {
 425          // we may have missed mouseup (out of window)

 426          (this._mouseStarted && this._mouseUp(event));
 427  
 428          this._mouseDownEvent = event;
 429  
 430          var self = this,
 431              btnIsLeft = (event.which == 1),
 432              elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
 433          if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
 434              return true;
 435          }
 436  
 437          this.mouseDelayMet = !this.options.delay;
 438          if (!this.mouseDelayMet) {
 439              this._mouseDelayTimer = setTimeout(function() {
 440                  self.mouseDelayMet = true;
 441              }, this.options.delay);
 442          }
 443  
 444          if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
 445              this._mouseStarted = (this._mouseStart(event) !== false);
 446              if (!this._mouseStarted) {
 447                  event.preventDefault();
 448                  return true;
 449              }
 450          }
 451  
 452          // these delegates are required to keep context

 453          this._mouseMoveDelegate = function(event) {
 454              return self._mouseMove(event);
 455          };
 456          this._mouseUpDelegate = function(event) {
 457              return self._mouseUp(event);
 458          };
 459          $(document)
 460              .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
 461              .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
 462  
 463          // preventDefault() is used to prevent the selection of text here -

 464          // however, in Safari, this causes select boxes not to be selectable

 465          // anymore, so this fix is needed

 466          if(!$.browser.safari) event.preventDefault();
 467          return true;
 468      },
 469  
 470      _mouseMove: function(event) {
 471          // IE mouseup check - mouseup happened when mouse was out of window

 472          if ($.browser.msie && !event.button) {
 473              return this._mouseUp(event);
 474          }
 475  
 476          if (this._mouseStarted) {
 477              this._mouseDrag(event);
 478              return event.preventDefault();
 479          }
 480  
 481          if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
 482              this._mouseStarted =
 483                  (this._mouseStart(this._mouseDownEvent, event) !== false);
 484              (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
 485          }
 486  
 487          return !this._mouseStarted;
 488      },
 489  
 490      _mouseUp: function(event) {
 491          $(document)
 492              .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
 493              .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
 494  
 495          if (this._mouseStarted) {
 496              this._mouseStarted = false;
 497              this._preventClickEvent = true;
 498              this._mouseStop(event);
 499          }
 500  
 501          return false;
 502      },
 503  
 504      _mouseDistanceMet: function(event) {
 505          return (Math.max(
 506                  Math.abs(this._mouseDownEvent.pageX - event.pageX),
 507                  Math.abs(this._mouseDownEvent.pageY - event.pageY)
 508              ) >= this.options.distance
 509          );
 510      },
 511  
 512      _mouseDelayMet: function(event) {
 513          return this.mouseDelayMet;
 514      },
 515  
 516      // These are placeholder methods, to be overriden by extending plugin

 517      _mouseStart: function(event) {},
 518      _mouseDrag: function(event) {},
 519      _mouseStop: function(event) {},
 520      _mouseCapture: function(event) { return true; }
 521  };
 522  
 523  $.ui.mouse.defaults = {
 524      cancel: null,
 525      distance: 1,
 526      delay: 0
 527  };
 528  
 529  })(jQuery);


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7