summaryrefslogtreecommitdiffstats
path: root/wp-includes/js/jquery
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/js/jquery')
-rw-r--r--wp-includes/js/jquery/jquery.color.js128
-rw-r--r--wp-includes/js/jquery/jquery.dimensions.min.js12
-rw-r--r--wp-includes/js/jquery/jquery.schedule.js36
-rw-r--r--wp-includes/js/jquery/suggest.js310
-rw-r--r--wp-includes/js/jquery/ui.tabs.js529
5 files changed, 1015 insertions, 0 deletions
diff --git a/wp-includes/js/jquery/jquery.color.js b/wp-includes/js/jquery/jquery.color.js
new file mode 100644
index 0000000..1dffbd5
--- /dev/null
+++ b/wp-includes/js/jquery/jquery.color.js
@@ -0,0 +1,128 @@
+/*
+ * jQuery Color Animations
+ * Copyright 2007 John Resig
+ * Released under the MIT and GPL licenses.
+ */
+
+(function(jQuery){
+
+ // We override the animation for all of these color styles
+ jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
+ jQuery.fx.step[attr] = function(fx){
+ if ( fx.state == 0 ) {
+ fx.start = getColor( fx.elem, attr );
+ fx.end = getRGB( fx.end );
+ }
+
+ fx.elem.style[attr] = "rgb(" + [
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
+ ].join(",") + ")";
+ }
+ });
+
+ // Color Conversion functions from highlightFade
+ // By Blair Mitchelmore
+ // http://jquery.offput.ca/highlightFade/
+
+ // Parse strings looking for color tuples [255,255,255]
+ function getRGB(color) {
+ var result;
+
+ // Check if we're already dealing with an array of colors
+ if ( color && color.constructor == Array && color.length == 3 )
+ return color;
+
+ // Look for rgb(num,num,num)
+ if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
+ return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
+
+ // Look for rgb(num%,num%,num%)
+ if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
+ return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
+
+ // Look for #a0b1c2
+ if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
+ return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
+
+ // Look for #fff
+ if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
+ return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
+
+ // Look for rgba(0, 0, 0, 0) == transparent in Safari 3
+ if (result = /rgba\(0, 0, 0, 0\)/.exec(color))
+ return colors['transparent']
+
+ // Otherwise, we're most likely dealing with a named color
+ return colors[jQuery.trim(color).toLowerCase()];
+ }
+
+ function getColor(elem, attr) {
+ var color;
+
+ do {
+ color = jQuery.curCSS(elem, attr);
+
+ // Keep going until we find an element that has color, or we hit the body
+ if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
+ break;
+
+ attr = "backgroundColor";
+ } while ( elem = elem.parentNode );
+
+ return getRGB(color);
+ };
+
+ // Some named colors to work with
+ // From Interface by Stefan Petre
+ // http://interface.eyecon.ro/
+
+ var colors = {
+ aqua:[0,255,255],
+ azure:[240,255,255],
+ beige:[245,245,220],
+ black:[0,0,0],
+ blue:[0,0,255],
+ brown:[165,42,42],
+ cyan:[0,255,255],
+ darkblue:[0,0,139],
+ darkcyan:[0,139,139],
+ darkgrey:[169,169,169],
+ darkgreen:[0,100,0],
+ darkkhaki:[189,183,107],
+ darkmagenta:[139,0,139],
+ darkolivegreen:[85,107,47],
+ darkorange:[255,140,0],
+ darkorchid:[153,50,204],
+ darkred:[139,0,0],
+ darksalmon:[233,150,122],
+ darkviolet:[148,0,211],
+ fuchsia:[255,0,255],
+ gold:[255,215,0],
+ green:[0,128,0],
+ indigo:[75,0,130],
+ khaki:[240,230,140],
+ lightblue:[173,216,230],
+ lightcyan:[224,255,255],
+ lightgreen:[144,238,144],
+ lightgrey:[211,211,211],
+ lightpink:[255,182,193],
+ lightyellow:[255,255,224],
+ lime:[0,255,0],
+ magenta:[255,0,255],
+ maroon:[128,0,0],
+ navy:[0,0,128],
+ olive:[128,128,0],
+ orange:[255,165,0],
+ pink:[255,192,203],
+ purple:[128,0,128],
+ violet:[128,0,128],
+ red:[255,0,0],
+ silver:[192,192,192],
+ white:[255,255,255],
+ yellow:[255,255,0],
+ transparent: [255,255,255]
+ };
+
+})(jQuery);
diff --git a/wp-includes/js/jquery/jquery.dimensions.min.js b/wp-includes/js/jquery/jquery.dimensions.min.js
new file mode 100644
index 0000000..34c06de
--- /dev/null
+++ b/wp-includes/js/jquery/jquery.dimensions.min.js
@@ -0,0 +1,12 @@
+/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
+ *
+ * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $
+ * $Rev: 4257 $
+ *
+ * Version: 1.2
+ *
+ * Requires: jQuery 1.2+
+ */
+(function($){$.dimensions={version:'1.2'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return this.is(':visible')?this[0]['client'+name]:num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});var val=this.is(':visible')?this[0]['offset'+name]:num(this,name.toLowerCase())+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')+num(this,'padding'+torl)+num(this,'padding'+borr);return val+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;};})(jQuery); \ No newline at end of file
diff --git a/wp-includes/js/jquery/jquery.schedule.js b/wp-includes/js/jquery/jquery.schedule.js
new file mode 100644
index 0000000..f00e7b3
--- /dev/null
+++ b/wp-includes/js/jquery/jquery.schedule.js
@@ -0,0 +1,36 @@
+
+(function($){$.scheduler=function(){this.bucket={};return;};$.scheduler.prototype={schedule:function(){var ctx={"id":null,"time":1000,"repeat":false,"protect":false,"obj":null,"func":function(){},"args":[]};function _isfn(fn){return(!!fn&&typeof fn!="string"&&typeof fn[0]=="undefined"&&RegExp("function","i").test(fn+""));};var i=0;var override=false;if(typeof arguments[i]=="object"&&arguments.length>1){override=true;i++;}
+if(typeof arguments[i]=="object"){for(var option in arguments[i])
+if(typeof ctx[option]!="undefined")
+ctx[option]=arguments[i][option];i++;}
+if(typeof arguments[i]=="number"||(typeof arguments[i]=="string"&&arguments[i].match(RegExp("^[0-9]+[smhdw]$"))))
+ctx["time"]=arguments[i++];if(typeof arguments[i]=="boolean")
+ctx["repeat"]=arguments[i++];if(typeof arguments[i]=="boolean")
+ctx["protect"]=arguments[i++];if(typeof arguments[i]=="object"&&typeof arguments[i+1]=="string"&&_isfn(arguments[i][arguments[i+1]])){ctx["obj"]=arguments[i++];ctx["func"]=arguments[i++];}
+else if(typeof arguments[i]!="undefined"&&(_isfn(arguments[i])||typeof arguments[i]=="string"))
+ctx["func"]=arguments[i++];while(typeof arguments[i]!="undefined")
+ctx["args"].push(arguments[i++]);if(override){if(typeof arguments[1]=="object"){for(var option in arguments[0])
+if(typeof ctx[option]!="undefined"&&typeof arguments[1][option]=="undefined")
+ctx[option]=arguments[0][option];}
+else{for(var option in arguments[0])
+if(typeof ctx[option]!="undefined")
+ctx[option]=arguments[0][option];}
+i++;}
+ctx["_scheduler"]=this;ctx["_handle"]=null;var match=String(ctx["time"]).match(RegExp("^([0-9]+)([smhdw])$"));if(match&&match[0]!="undefined"&&match[1]!="undefined")
+ctx["time"]=String(parseInt(match[1])*{s:1000,m:1000*60,h:1000*60*60,d:1000*60*60*24,w:1000*60*60*24*7}[match[2]]);if(ctx["id"]==null)
+ctx["id"]=(String(ctx["repeat"])+":"
++String(ctx["protect"])+":"
++String(ctx["time"])+":"
++String(ctx["obj"])+":"
++String(ctx["func"])+":"
++String(ctx["args"]));if(ctx["protect"])
+if(typeof this.bucket[ctx["id"]]!="undefined")
+return this.bucket[ctx["id"]];if(!_isfn(ctx["func"])){if(ctx["obj"]!=null&&typeof ctx["obj"]=="object"&&typeof ctx["func"]=="string"&&_isfn(ctx["obj"][ctx["func"]]))
+ctx["func"]=ctx["obj"][ctx["func"]];else
+ctx["func"]=eval("function () { "+ctx["func"]+" }");}
+ctx["_handle"]=this._schedule(ctx);this.bucket[ctx["id"]]=ctx;return ctx;},reschedule:function(ctx){if(typeof ctx=="string")
+ctx=this.bucket[ctx];ctx["_handle"]=this._schedule(ctx);return ctx;},_schedule:function(ctx){var trampoline=function(){var obj=(ctx["obj"]!=null?ctx["obj"]:ctx);(ctx["func"]).apply(obj,ctx["args"]);if(typeof(ctx["_scheduler"]).bucket[ctx["id"]]!="undefined"&&ctx["repeat"])
+(ctx["_scheduler"])._schedule(ctx);else
+delete(ctx["_scheduler"]).bucket[ctx["id"]];};return setTimeout(trampoline,ctx["time"]);},cancel:function(ctx){if(typeof ctx=="string")
+ctx=this.bucket[ctx];if(typeof ctx=="object"){clearTimeout(ctx["_handle"]);delete this.bucket[ctx["id"]];}}};$.extend({scheduler$:new $.scheduler(),schedule:function(){return $.scheduler$.schedule.apply($.scheduler$,arguments)},reschedule:function(){return $.scheduler$.reschedule.apply($.scheduler$,arguments)},cancel:function(){return $.scheduler$.cancel.apply($.scheduler$,arguments)}});$.fn.extend({schedule:function(){var a=[{}];for(var i=0;i<arguments.length;i++)
+a.push(arguments[i]);return this.each(function(){a[0]={"id":this,"obj":this};return $.schedule.apply($,a);});}});})(jQuery); \ No newline at end of file
diff --git a/wp-includes/js/jquery/suggest.js b/wp-includes/js/jquery/suggest.js
new file mode 100644
index 0000000..656e58b
--- /dev/null
+++ b/wp-includes/js/jquery/suggest.js
@@ -0,0 +1,310 @@
+/*
+ * jquery.suggest 1.1 - 2007-08-06
+ *
+ * Uses code and techniques from following libraries:
+ * 1. http://www.dyve.net/jquery/?autocomplete
+ * 2. http://dev.jquery.com/browser/trunk/plugins/interface/iautocompleter.js
+ *
+ * All the new stuff written by Peter Vulgaris (www.vulgarisoip.com)
+ * Feel free to do whatever you want with this file
+ *
+ */
+
+(function($) {
+
+ $.suggest = function(input, options) {
+
+ var $input = $(input).attr("autocomplete", "off");
+ var $results = $(document.createElement("ul"));
+
+ var timeout = false; // hold timeout ID for suggestion results to appear
+ var prevLength = 0; // last recorded length of $input.val()
+ var cache = []; // cache MRU list
+ var cacheSize = 0; // size of cache in chars (bytes?)
+
+ $results.addClass(options.resultsClass).appendTo('body');
+
+
+ resetPosition();
+ $(window)
+ .load(resetPosition) // just in case user is changing size of page while loading
+ .resize(resetPosition);
+
+ $input.blur(function() {
+ setTimeout(function() { $results.hide() }, 200);
+ });
+
+
+ // help IE users if possible
+ try {
+ $results.bgiframe();
+ } catch(e) { }
+
+
+ // I really hate browser detection, but I don't see any other way
+ if ($.browser.mozilla)
+ $input.keypress(processKey); // onkeypress repeats arrow keys in Mozilla/Opera
+ else
+ $input.keydown(processKey); // onkeydown repeats arrow keys in IE/Safari
+
+
+
+
+ function resetPosition() {
+ // requires jquery.dimension plugin
+ var offset = $input.offset();
+ $results.css({
+ top: (offset.top + input.offsetHeight) + 'px',
+ left: offset.left + 'px'
+ });
+ }
+
+
+ function processKey(e) {
+
+ // handling up/down/escape requires results to be visible
+ // handling enter/tab requires that AND a result to be selected
+ if ((/27$|38$|40$/.test(e.keyCode) && $results.is(':visible')) ||
+ (/^13$|^9$/.test(e.keyCode) && getCurrentResult())) {
+
+ if (e.preventDefault)
+ e.preventDefault();
+ if (e.stopPropagation)
+ e.stopPropagation();
+
+ e.cancelBubble = true;
+ e.returnValue = false;
+
+ switch(e.keyCode) {
+
+ case 38: // up
+ prevResult();
+ break;
+
+ case 40: // down
+ nextResult();
+ break;
+
+ case 9: // tab
+ case 13: // return
+ selectCurrentResult();
+ break;
+
+ case 27: // escape
+ $results.hide();
+ break;
+
+ }
+
+ } else if ($input.val().length != prevLength) {
+
+ if (timeout)
+ clearTimeout(timeout);
+ timeout = setTimeout(suggest, options.delay);
+ prevLength = $input.val().length;
+
+ }
+
+
+ }
+
+
+ function suggest() {
+
+ var q = $.trim($input.val());
+
+ if (q.length >= options.minchars) {
+
+ cached = checkCache(q);
+
+ if (cached) {
+
+ displayItems(cached['items']);
+
+ } else {
+
+ $.get(options.source, {q: q}, function(txt) {
+
+ $results.hide();
+
+ var items = parseTxt(txt, q);
+
+ displayItems(items);
+ addToCache(q, items, txt.length);
+
+ });
+
+ }
+
+ } else {
+
+ $results.hide();
+
+ }
+
+ }
+
+
+ function checkCache(q) {
+
+ for (var i = 0; i < cache.length; i++)
+ if (cache[i]['q'] == q) {
+ cache.unshift(cache.splice(i, 1)[0]);
+ return cache[0];
+ }
+
+ return false;
+
+ }
+
+ function addToCache(q, items, size) {
+
+ while (cache.length && (cacheSize + size > options.maxCacheSize)) {
+ var cached = cache.pop();
+ cacheSize -= cached['size'];
+ }
+
+ cache.push({
+ q: q,
+ size: size,
+ items: items
+ });
+
+ cacheSize += size;
+
+ }
+
+ function displayItems(items) {
+
+ if (!items)
+ return;
+
+ if (!items.length) {
+ $results.hide();
+ return;
+ }
+
+ var html = '';
+ for (var i = 0; i < items.length; i++)
+ html += '<li>' + items[i] + '</li>';
+
+ $results.html(html).show();
+
+ $results
+ .children('li')
+ .mouseover(function() {
+ $results.children('li').removeClass(options.selectClass);
+ $(this).addClass(options.selectClass);
+ })
+ .click(function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ selectCurrentResult();
+ });
+
+ }
+
+ function parseTxt(txt, q) {
+
+ var items = [];
+ var tokens = txt.split(options.delimiter);
+
+ // parse returned data for non-empty items
+ for (var i = 0; i < tokens.length; i++) {
+ var token = $.trim(tokens[i]);
+ if (token) {
+ token = token.replace(
+ new RegExp(q, 'ig'),
+ function(q) { return '<span class="' + options.matchClass + '">' + q + '</span>' }
+ );
+ items[items.length] = token;
+ }
+ }
+
+ return items;
+ }
+
+ function getCurrentResult() {
+
+ if (!$results.is(':visible'))
+ return false;
+
+ var $currentResult = $results.children('li.' + options.selectClass);
+
+ if (!$currentResult.length)
+ $currentResult = false;
+
+ return $currentResult;
+
+ }
+
+ function selectCurrentResult() {
+
+ $currentResult = getCurrentResult();
+
+ if ($currentResult) {
+ $input.val($currentResult.text());
+ $results.hide();
+
+ if (options.onSelect)
+ options.onSelect.apply($input[0]);
+
+ }
+
+ }
+
+ function nextResult() {
+
+ $currentResult = getCurrentResult();
+
+ if ($currentResult)
+ $currentResult
+ .removeClass(options.selectClass)
+ .next()
+ .addClass(options.selectClass);
+ else
+ $results.children('li:first-child').addClass(options.selectClass);
+
+ }
+
+ function prevResult() {
+
+ $currentResult = getCurrentResult();
+
+ if ($currentResult)
+ $currentResult
+ .removeClass(options.selectClass)
+ .prev()
+ .addClass(options.selectClass);
+ else
+ $results.children('li:last-child').addClass(options.selectClass);
+
+ }
+
+ }
+
+ $.fn.suggest = function(source, options) {
+
+ if (!source)
+ return;
+
+ options = options || {};
+ options.source = source;
+ options.delay = options.delay || 100;
+ options.resultsClass = options.resultsClass || 'ac_results';
+ options.selectClass = options.selectClass || 'ac_over';
+ options.matchClass = options.matchClass || 'ac_match';
+ options.minchars = options.minchars || 2;
+ options.delimiter = options.delimiter || '\n';
+ options.onSelect = options.onSelect || false;
+ options.maxCacheSize = options.maxCacheSize || 65536;
+
+ this.each(function() {
+ new $.suggest(this, options);
+ });
+
+ return this;
+
+ };
+
+})(jQuery); \ No newline at end of file
diff --git a/wp-includes/js/jquery/ui.tabs.js b/wp-includes/js/jquery/ui.tabs.js
new file mode 100644
index 0000000..8634b41
--- /dev/null
+++ b/wp-includes/js/jquery/ui.tabs.js
@@ -0,0 +1,529 @@
+/*
+ * Tabs 3 - New Wave Tabs
+ *
+ * Copyright (c) 2007 Klaus Hartl (stilbuero.de)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ */
+
+(function($) {
+
+ // if the UI scope is not availalable, add it
+ $.ui = $.ui || {};
+
+ // tabs initialization
+ $.fn.tabs = function(initial, options) {
+ if (initial && initial.constructor == Object) { // shift arguments
+ options = initial;
+ initial = null;
+ }
+ options = options || {};
+
+ initial = initial && initial.constructor == Number && --initial || 0;
+
+ return this.each(function() {
+ new $.ui.tabs(this, $.extend(options, { initial: initial }));
+ });
+ };
+
+ // other chainable tabs methods
+ $.each(['Add', 'Remove', 'Enable', 'Disable', 'Click', 'Load', 'Href'], function(i, method) {
+ $.fn['tabs' + method] = function() {
+ var args = arguments;
+ return this.each(function() {
+ var instance = $.ui.tabs.getInstance(this);
+ instance[method.toLowerCase()].apply(instance, args);
+ });
+ };
+ });
+ $.fn.tabsSelected = function() {
+ var selected = -1;
+ if (this[0]) {
+ var instance = $.ui.tabs.getInstance(this[0]),
+ $lis = $('li', this);
+ selected = $lis.index( $lis.filter('.' + instance.options.selectedClass)[0] );
+ }
+ return selected >= 0 ? ++selected : -1;
+ };
+
+ // tabs class
+ $.ui.tabs = function(el, options) {
+
+ this.source = el;
+
+ this.options = $.extend({
+
+ // basic setup
+ initial: 0,
+ event: 'click',
+ disabled: [],
+ cookie: null, // pass options object as expected by cookie plugin: { expires: 7, path: '/', domain: 'jquery.com', secure: true }
+ // TODO bookmarkable: $.ajaxHistory ? true : false,
+ unselected: false,
+ unselect: options.unselected ? true : false,
+
+ // Ajax
+ spinner: 'Loading&#8230;',
+ cache: false,
+ idPrefix: 'ui-tabs-',
+ ajaxOptions: {},
+
+ // animations
+ /*fxFade: null,
+ fxSlide: null,
+ fxShow: null,
+ fxHide: null,*/
+ fxSpeed: 'normal',
+ /*fxShowSpeed: null,
+ fxHideSpeed: null,*/
+
+ // callbacks
+ add: function() {},
+ remove: function() {},
+ enable: function() {},
+ disable: function() {},
+ click: function() {},
+ hide: function() {},
+ show: function() {},
+ load: function() {},
+
+ // templates
+ tabTemplate: '<li><a href="#{href}"><span>#{text}</span></a></li>',
+ panelTemplate: '<div></div>',
+
+ // CSS classes
+ navClass: 'ui-tabs-nav',
+ selectedClass: 'ui-tabs-selected',
+ unselectClass: 'ui-tabs-unselect',
+ disabledClass: 'ui-tabs-disabled',
+ panelClass: 'ui-tabs-panel',
+ hideClass: 'ui-tabs-hide',
+ loadingClass: 'ui-tabs-loading'
+
+ }, options);
+
+ this.options.event += '.ui-tabs'; // namespace event
+ this.options.cookie = $.cookie && $.cookie.constructor == Function && this.options.cookie;
+
+ // save instance for later
+ $.data(el, $.ui.tabs.INSTANCE_KEY, this);
+
+ // create tabs
+ this.tabify(true);
+ };
+
+ // static
+ $.ui.tabs.INSTANCE_KEY = 'ui_tabs_instance';
+ $.ui.tabs.getInstance = function(el) {
+ return $.data(el, $.ui.tabs.INSTANCE_KEY);
+ };
+
+ // instance methods
+ $.extend($.ui.tabs.prototype, {
+ tabId: function(a) {
+ return a.title ? a.title.replace(/\s/g, '_')
+ : this.options.idPrefix + $.data(a);
+ },
+ tabify: function(init) {
+
+ this.$lis = $('li:has(a[href])', this.source);
+ this.$tabs = this.$lis.map(function() { return $('a', this)[0] });
+ this.$panels = $([]);
+
+ var self = this, o = this.options;
+
+ this.$tabs.each(function(i, a) {
+ // inline tab
+ if (a.hash && a.hash.replace('#', '')) { // Safari 2 reports '#' for an empty hash
+ self.$panels = self.$panels.add(a.hash);
+ }
+ // remote tab
+ else if ($(a).attr('href') != '#') { // prevent loading the page itself if href is just "#"
+ $.data(a, 'href', a.href);
+ var id = self.tabId(a);
+ a.href = '#' + id;
+ self.$panels = self.$panels.add(
+ $('#' + id)[0] || $(o.panelTemplate).attr('id', id).addClass(o.panelClass)
+ .insertAfter( self.$panels[i - 1] || self.source )
+ );
+ }
+ // invalid tab href
+ else {
+ o.disabled.push(i + 1);
+ }
+ });
+
+ if (init) {
+
+ // attach necessary classes for styling if not present
+ $(this.source).hasClass(o.navClass) || $(this.source).addClass(o.navClass);
+ this.$panels.each(function() {
+ var $this = $(this);
+ $this.hasClass(o.panelClass) || $this.addClass(o.panelClass);
+ });
+
+ // disabled tabs
+ for (var i = 0, position; position = o.disabled[i]; i++) {
+ this.disable(position);
+ }
+
+ // Try to retrieve initial tab:
+ // 1. from fragment identifier in url if present
+ // 2. from cookie
+ // 3. from selected class attribute on <li>
+ // 4. otherwise use given initial argument
+ // 5. check if tab is disabled
+ this.$tabs.each(function(i, a) {
+ if (location.hash) {
+ if (a.hash == location.hash) {
+ o.initial = i;
+ // prevent page scroll to fragment
+ //if (($.browser.msie || $.browser.opera) && !o.remote) {
+ if ($.browser.msie || $.browser.opera) {
+ var $toShow = $(location.hash), toShowId = $toShow.attr('id');
+ $toShow.attr('id', '');
+ setTimeout(function() {
+ $toShow.attr('id', toShowId); // restore id
+ }, 500);
+ }
+ scrollTo(0, 0);
+ return false; // break
+ }
+ } else if (o.cookie) {
+ o.initial = parseInt($.cookie( $.ui.tabs.INSTANCE_KEY + $.data(self.source) )) || 0;
+ return false; // break
+ } else if ( self.$lis.eq(i).hasClass(o.selectedClass) ) {
+ o.initial = i;
+ return false; // break
+ }
+ });
+ var n = this.$lis.length;
+ while (this.$lis.eq(o.initial).hasClass(o.disabledClass) && n) {
+ o.initial = ++o.initial < this.$lis.length ? o.initial : 0;
+ n--;
+ }
+ if (!n) { // all tabs disabled, set option unselected to true
+ o.unselected = o.unselect = true;
+ }
+
+ // highlight selected tab
+ this.$panels.addClass(o.hideClass);
+ this.$lis.removeClass(o.selectedClass);
+ if (!o.unselected) {
+ this.$panels.eq(o.initial).show().removeClass(o.hideClass); // use show and remove class to show in any case no matter how it has been hidden before
+ this.$lis.eq(o.initial).addClass(o.selectedClass);
+ }
+
+ // load if remote tab
+ var href = !o.unselected && $.data(this.$tabs[o.initial], 'href');
+ if (href) {
+ this.load(o.initial + 1, href);
+ }
+
+ // disable click if event is configured to something else
+ if (!/^click/.test(o.event)) {
+ this.$tabs.bind('click', function(e) { e.preventDefault(); });
+ }
+
+ }
+
+ // setup animations
+ var showAnim = {}, showSpeed = o.fxShowSpeed || o.fxSpeed,
+ hideAnim = {}, hideSpeed = o.fxHideSpeed || o.fxSpeed;
+ if (o.fxSlide || o.fxFade) {
+ if (o.fxSlide) {
+ showAnim['height'] = 'show';
+ hideAnim['height'] = 'hide';
+ }
+ if (o.fxFade) {
+ showAnim['opacity'] = 'show';
+ hideAnim['opacity'] = 'hide';
+ }
+ } else {
+ if (o.fxShow) {
+ showAnim = o.fxShow;
+ } else { // use some kind of animation to prevent browser scrolling to the tab
+ showAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox
+ showSpeed = 1; // as little as 1 is sufficient
+ }
+ if (o.fxHide) {
+ hideAnim = o.fxHide;
+ } else { // use some kind of animation to prevent browser scrolling to the tab
+ hideAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox
+ hideSpeed = 1; // as little as 1 is sufficient
+ }
+ }
+
+ // reset some styles to maintain print style sheets etc.
+ var resetCSS = { display: '', overflow: '', height: '' };
+ if (!$.browser.msie) { // not in IE to prevent ClearType font issue
+ resetCSS['opacity'] = '';
+ }
+
+ // Hide a tab, animation prevents browser scrolling to fragment,
+ // $show is optional.
+ function hideTab(clicked, $hide, $show) {
+ $hide.animate(hideAnim, hideSpeed, function() { //
+ $hide.addClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc.
+ if ($.browser.msie && hideAnim['opacity']) {
+ $hide[0].style.filter = '';
+ }
+ o.hide(clicked, $hide[0], $show && $show[0] || null);
+ if ($show) {
+ showTab(clicked, $show, $hide);
+ }
+ });
+ }
+
+ // Show a tab, animation prevents browser scrolling to fragment,
+ // $hide is optional
+ function showTab(clicked, $show, $hide) {
+ if (!(o.fxSlide || o.fxFade || o.fxShow)) {
+ $show.css('display', 'block'); // prevent occasionally occuring flicker in Firefox cause by gap between showing and hiding the tab panels
+ }
+ $show.animate(showAnim, showSpeed, function() {
+ $show.removeClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc.
+ if ($.browser.msie && showAnim['opacity']) {
+ $show[0].style.filter = '';
+ }
+ o.show(clicked, $show[0], $hide && $hide[0] || null);
+ });
+ }
+
+ // switch a tab
+ function switchTab(clicked, $li, $hide, $show) {
+ /*if (o.bookmarkable && trueClick) { // add to history only if true click occured, not a triggered click
+ $.ajaxHistory.update(clicked.hash);
+ }*/
+ $li.addClass(o.selectedClass)
+ .siblings().removeClass(o.selectedClass);
+ hideTab(clicked, $hide, $show);
+ }
+
+ // attach tab event handler, unbind to avoid duplicates from former tabifying...
+ this.$tabs.unbind(o.event).bind(o.event, function() {
+
+ //var trueClick = e.clientX; // add to history only if true click occured, not a triggered click
+ var $li = $(this).parents('li:eq(0)'),
+ $hide = self.$panels.filter(':visible'),
+ $show = $(this.hash);
+
+ // If tab is already selected and not unselectable or tab disabled or click callback returns false stop here.
+ // Check if click handler returns false last so that it is not executed for a disabled tab!
+ if (($li.hasClass(o.selectedClass) && !o.unselect) || $li.hasClass(o.disabledClass)
+ || o.click(this, $show[0], $hide[0]) === false) {
+ this.blur();
+ return false;
+ }
+
+ if (o.cookie) {
+ $.cookie($.ui.tabs.INSTANCE_KEY + $.data(self.source), self.$tabs.index(this), o.cookie);
+ }
+
+ // if tab may be closed
+ if (o.unselect) {
+ if ($li.hasClass(o.selectedClass)) {
+ $li.removeClass(o.selectedClass);
+ self.$panels.stop();
+ hideTab(this, $hide);
+ this.blur();
+ return false;
+ } else if (!$hide.length) {
+ self.$panels.stop();
+ if ($.data(this, 'href')) { // remote tab
+ var a = this;
+ self.load(self.$tabs.index(this) + 1, $.data(this, 'href'), function() {
+ $li.addClass(o.selectedClass).addClass(o.unselectClass);
+ showTab(a, $show);
+ });
+ } else {
+ $li.addClass(o.selectedClass).addClass(o.unselectClass);
+ showTab(this, $show);
+ }
+ this.blur();
+ return false;
+ }
+ }
+
+ // stop possibly running animations
+ self.$panels.stop();
+
+ // show new tab
+ if ($show.length) {
+
+ // prevent scrollbar scrolling to 0 and than back in IE7, happens only if bookmarking/history is enabled
+ /*if ($.browser.msie && o.bookmarkable) {
+ var showId = this.hash.replace('#', '');
+ $show.attr('id', '');
+ setTimeout(function() {
+ $show.attr('id', showId); // restore id
+ }, 0);
+ }*/
+
+ if ($.data(this, 'href')) { // remote tab
+ var a = this;
+ self.load(self.$tabs.index(this) + 1, $.data(this, 'href'), function() {
+ switchTab(a, $li, $hide, $show);
+ });
+ } else {
+ switchTab(this, $li, $hide, $show);
+ }
+
+ // Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash
+ /*var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0;
+ var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0;
+ setTimeout(function() {
+ scrollTo(scrollX, scrollY);
+ }, 0);*/
+
+ } else {
+ throw 'jQuery UI Tabs: Mismatching fragment identifier.';
+ }
+
+ // Prevent IE from keeping other link focussed when using the back button
+ // and remove dotted border from clicked link. This is controlled in modern
+ // browsers via CSS, also blur removes focus from address bar in Firefox
+ // which can become a usability and annoying problem with tabsRotate.
+ if ($.browser.msie) {
+ this.blur();
+ }
+
+ //return o.bookmarkable && !!trueClick; // convert trueClick == undefined to Boolean required in IE
+ return false;
+
+ });
+
+ },
+ add: function(url, text, position) {
+ if (url && text) {
+ position = position || this.$tabs.length; // append by default
+
+ var o = this.options,
+ $li = $(o.tabTemplate.replace(/#\{href\}/, url).replace(/#\{text\}/, text));
+
+ var id = url.indexOf('#') == 0 ? url.replace('#', '') : this.tabId( $('a:first-child', $li)[0] );
+
+ // try to find an existing element before creating a new one
+ var $panel = $('#' + id);
+ $panel = $panel.length && $panel
+ || $(o.panelTemplate).attr('id', id).addClass(o.panelClass).addClass(o.hideClass);
+ if (position >= this.$lis.length) {
+ $li.appendTo(this.source);
+ $panel.appendTo(this.source.parentNode);
+ } else {
+ $li.insertBefore(this.$lis[position - 1]);
+ $panel.insertBefore(this.$panels[position - 1]);
+ }
+
+ this.tabify();
+
+ if (this.$tabs.length == 1) {
+ $li.addClass(o.selectedClass);
+ $panel.removeClass(o.hideClass);
+ var href = $.data(this.$tabs[0], 'href');
+ if (href) {
+ this.load(position + 1, href);
+ }
+ }
+ o.add(this.$tabs[position], this.$panels[position]); // callback
+ } else {
+ throw 'jQuery UI Tabs: Not enough arguments to add tab.';
+ }
+ },
+ remove: function(position) {
+ if (position && position.constructor == Number) {
+ var o = this.options, $li = this.$lis.eq(position - 1).remove(),
+ $panel = this.$panels.eq(position - 1).remove();
+
+ // If selected tab was removed focus tab to the right or
+ // tab to the left if last tab was removed.
+ if ($li.hasClass(o.selectedClass) && this.$tabs.length > 1) {
+ this.click(position + (position < this.$tabs.length ? 1 : -1));
+ }
+ this.tabify();
+ o.remove($li.end()[0], $panel[0]); // callback
+ }
+ },
+ enable: function(position) {
+ var o = this.options, $li = this.$lis.eq(position - 1);
+ $li.removeClass(o.disabledClass);
+ if ($.browser.safari) { // fix disappearing tab (that used opacity indicating disabling) after enabling in Safari 2...
+ $li.css('display', 'inline-block');
+ setTimeout(function() {
+ $li.css('display', 'block')
+ }, 0)
+ }
+ o.enable(this.$tabs[position - 1], this.$panels[position - 1]); // callback
+ },
+ disable: function(position) {
+ var o = this.options;
+ this.$lis.eq(position - 1).addClass(o.disabledClass);
+ o.disable(this.$tabs[position - 1], this.$panels[position - 1]); // callback
+ },
+ click: function(position) {
+ this.$tabs.eq(position - 1).trigger(this.options.event);
+ },
+ load: function(position, url, callback) {
+ var self = this, o = this.options,
+ $a = this.$tabs.eq(position - 1), a = $a[0], $span = $('span', a);
+
+ // shift arguments
+ if (url && url.constructor == Function) {
+ callback = url;
+ url = null;
+ }
+
+ // set new URL or get existing
+ if (url) {
+ $.data(a, 'href', url);
+ } else {
+ url = $.data(a, 'href');
+ }
+
+ // load
+ if (o.spinner) {
+ $.data(a, 'title', $span.html());
+ $span.html('<em>' + o.spinner + '</em>');
+ }
+ var finish = function() {
+ self.$tabs.filter('.' + o.loadingClass).each(function() {
+ $(this).removeClass(o.loadingClass);
+ if (o.spinner) {
+ $('span', this).html( $.data(this, 'title') );
+ }
+ });
+ self.xhr = null;
+ };
+ var ajaxOptions = $.extend(o.ajaxOptions, {
+ url: url,
+ success: function(r) {
+ $(a.hash).html(r);
+ finish();
+ // This callback is required because the switch has to take
+ // place after loading has completed.
+ if (callback && callback.constructor == Function) {
+ callback();
+ }
+ if (o.cache) {
+ $.removeData(a, 'href'); // if loaded once do not load them again
+ }
+ o.load(self.$tabs[position - 1], self.$panels[position - 1]); // callback
+ }
+ });
+ if (this.xhr) {
+ // terminate pending requests from other tabs and restore title
+ this.xhr.abort();
+ finish();
+ }
+ $a.addClass(o.loadingClass);
+ setTimeout(function() { // timeout is again required in IE, "wait" for id being restored
+ self.xhr = $.ajax(ajaxOptions);
+ }, 0);
+
+ },
+ href: function(position, href) {
+ $.data(this.$tabs.eq(position - 1)[0], 'href', href);
+ }
+ });
+
+})(jQuery);