www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

jquery.ui.core.js (5469B)


      1 /*!
      2  * jQuery UI 1.8
      3  *
      4  * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.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 ;jQuery.ui || (function($) {
     11 
     12 //Helper functions and ui object
     13 $.ui = {
     14 	version: "1.8",
     15 
     16 	// $.ui.plugin is deprecated.  Use the proxy pattern instead.
     17 	plugin: {
     18 		add: function(module, option, set) {
     19 			var proto = $.ui[module].prototype;
     20 			for(var i in set) {
     21 				proto.plugins[i] = proto.plugins[i] || [];
     22 				proto.plugins[i].push([option, set[i]]);
     23 			}
     24 		},
     25 		call: function(instance, name, args) {
     26 			var set = instance.plugins[name];
     27 			if(!set || !instance.element[0].parentNode) { return; }
     28 
     29 			for (var i = 0; i < set.length; i++) {
     30 				if (instance.options[set[i][0]]) {
     31 					set[i][1].apply(instance.element, args);
     32 				}
     33 			}
     34 		}
     35 	},
     36 
     37 	contains: function(a, b) {
     38 		return document.compareDocumentPosition
     39 			? a.compareDocumentPosition(b) & 16
     40 			: a !== b && a.contains(b);
     41 	},
     42 
     43 	hasScroll: function(el, a) {
     44 
     45 		//If overflow is hidden, the element might have extra content, but the user wants to hide it
     46 		if ($(el).css('overflow') == 'hidden') { return false; }
     47 
     48 		var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
     49 			has = false;
     50 
     51 		if (el[scroll] > 0) { return true; }
     52 
     53 		// TODO: determine which cases actually cause this to happen
     54 		// if the element doesn't have the scroll set, see if it's possible to
     55 		// set the scroll
     56 		el[scroll] = 1;
     57 		has = (el[scroll] > 0);
     58 		el[scroll] = 0;
     59 		return has;
     60 	},
     61 
     62 	isOverAxis: function(x, reference, size) {
     63 		//Determines when x coordinate is over "b" element axis
     64 		return (x > reference) && (x < (reference + size));
     65 	},
     66 
     67 	isOver: function(y, x, top, left, height, width) {
     68 		//Determines when x, y coordinates is over "b" element
     69 		return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
     70 	},
     71 
     72 	keyCode: {
     73 		BACKSPACE: 8,
     74 		CAPS_LOCK: 20,
     75 		COMMA: 188,
     76 		CONTROL: 17,
     77 		DELETE: 46,
     78 		DOWN: 40,
     79 		END: 35,
     80 		ENTER: 13,
     81 		ESCAPE: 27,
     82 		HOME: 36,
     83 		INSERT: 45,
     84 		LEFT: 37,
     85 		NUMPAD_ADD: 107,
     86 		NUMPAD_DECIMAL: 110,
     87 		NUMPAD_DIVIDE: 111,
     88 		NUMPAD_ENTER: 108,
     89 		NUMPAD_MULTIPLY: 106,
     90 		NUMPAD_SUBTRACT: 109,
     91 		PAGE_DOWN: 34,
     92 		PAGE_UP: 33,
     93 		PERIOD: 190,
     94 		RIGHT: 39,
     95 		SHIFT: 16,
     96 		SPACE: 32,
     97 		TAB: 9,
     98 		UP: 38
     99 	}
    100 };
    101 
    102 //jQuery plugins
    103 $.fn.extend({
    104 	_focus: $.fn.focus,
    105 	focus: function(delay, fn) {
    106 		return typeof delay === 'number'
    107 			? this.each(function() {
    108 				var elem = this;
    109 				setTimeout(function() {
    110 					$(elem).focus();
    111 					(fn && fn.call(elem));
    112 				}, delay);
    113 			})
    114 			: this._focus.apply(this, arguments);
    115 	},
    116 	
    117 	enableSelection: function() {
    118 		return this
    119 			.attr('unselectable', 'off')
    120 			.css('MozUserSelect', '')
    121 			.unbind('selectstart.ui');
    122 	},
    123 
    124 	disableSelection: function() {
    125 		return this
    126 			.attr('unselectable', 'on')
    127 			.css('MozUserSelect', 'none')
    128 			.bind('selectstart.ui', function() { return false; });
    129 	},
    130 
    131 	scrollParent: function() {
    132 		var scrollParent;
    133 		if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
    134 			scrollParent = this.parents().filter(function() {
    135 				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));
    136 			}).eq(0);
    137 		} else {
    138 			scrollParent = this.parents().filter(function() {
    139 				return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
    140 			}).eq(0);
    141 		}
    142 
    143 		return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
    144 	},
    145 
    146 	zIndex: function(zIndex) {
    147 		if (zIndex !== undefined) {
    148 			return this.css('zIndex', zIndex);
    149 		}
    150 		
    151 		if (this.length) {
    152 			var elem = $(this[0]), position, value;
    153 			while (elem.length && elem[0] !== document) {
    154 				// Ignore z-index if position is set to a value where z-index is ignored by the browser
    155 				// This makes behavior of this function consistent across browsers
    156 				// WebKit always returns auto if the element is positioned
    157 				position = elem.css('position');
    158 				if (position == 'absolute' || position == 'relative' || position == 'fixed')
    159 				{
    160 					// IE returns 0 when zIndex is not specified
    161 					// other browsers return a string
    162 					// we ignore the case of nested elements with an explicit value of 0
    163 					// <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
    164 					value = parseInt(elem.css('zIndex'));
    165 					if (!isNaN(value) && value != 0) {
    166 						return value;
    167 					}
    168 				}
    169 				elem = elem.parent();
    170 			}
    171 		}
    172 
    173 		return 0;
    174 	}
    175 });
    176 
    177 
    178 //Additional selectors
    179 $.extend($.expr[':'], {
    180 	data: function(elem, i, match) {
    181 		return !!$.data(elem, match[3]);
    182 	},
    183 
    184 	focusable: function(element) {
    185 		var nodeName = element.nodeName.toLowerCase(),
    186 			tabIndex = $.attr(element, 'tabindex');
    187 		return (/input|select|textarea|button|object/.test(nodeName)
    188 			? !element.disabled
    189 			: 'a' == nodeName || 'area' == nodeName
    190 				? element.href || !isNaN(tabIndex)
    191 				: !isNaN(tabIndex))
    192 			// the element and all of its ancestors must be visible
    193 			// the browser may report that the area is hidden
    194 			&& !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
    195 	},
    196 
    197 	tabbable: function(element) {
    198 		var tabIndex = $.attr(element, 'tabindex');
    199 		return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
    200 	}
    201 });
    202 
    203 })(jQuery);