Changeset 3069
- Timestamp:
- 09/02/07 21:01:16 (1 year ago)
- Location:
- trunk/plugins/ui
- Files:
-
- 2 modified
-
tests/tabs.html (modified) (2 diffs)
-
ui.tabs.js (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/ui/tests/tabs.html
r3056 r3069 26 26 fxFade: true, 27 27 fxSpeed: 'fast', 28 onClick: function() {29 alert(' onClick');28 click: function() { 29 alert('click callback'); 30 30 }, 31 onHide: function() {32 alert(' onHide');31 hide: function() { 32 alert('hide callback'); 33 33 }, 34 onShow: function() {35 alert(' onShow');34 show: function() { 35 alert('show callback'); 36 36 } 37 37 }); 38 38 //$('#container-7 ul').tabs({ fxAutoHeight: true }); 39 39 $('#container-7 ul').tabs({ fxShow: { height: 'show', opacity: 'show' }, fxSpeed: 'normal' }); 40 $('#container 8 ul').tabs();40 $('#container-8 ul').tabs(); 41 41 $('#container-9 ul').tabs({ disabled: [3] }); 42 42 … … 317 317 <div id="container-8"> 318 318 <ul> 319 <li><a href="ahah_1.html" ><span>One</span></a></li>320 <li><a href="ahah_2.html" ><span>Two</span></a></li>321 <li><a href="ahah_3.html" ><span>Three</span></a></li>319 <li><a href="ahah_1.html" title="Tab one"><span>One</span></a></li> 320 <li><a href="ahah_2.html" title="Tab two"><span>Two</span></a></li> 321 <li><a href="ahah_3.html" title="Tab three"><span>Three</span></a></li> 322 322 </ul> 323 323 </div> -
trunk/plugins/ui/ui.tabs.js
r3056 r3069 8 8 9 9 $.fn.tabs = function(initial, options) { 10 if (initial && initial.constructor == Object) { 10 if (initial && initial.constructor == Object) { // shift arguments 11 11 options = initial; 12 12 initial = null; … … 23 23 24 24 // create chainable tabs methods 25 $.each(['add', 'remove' ], function(i, method) {25 $.each(['add', 'remove', 'enable', 'disable', 'show', 'load'], function(i, method) { 26 26 $.fn[method + 'Tab'] = function() { 27 27 var args = arguments; … … 44 44 this.jQueryTabs.remove.apply(this.jQueryTabs, args); 45 45 }); 46 }; 47 48 $.fn.enableTab = function(position) { 49 return this.each(function() { 50 51 }); 52 }; 53 54 $.fn.disableTab = function(position) { 55 return this.each(function() { 56 57 }); 58 }; 59 60 $.fn.showTab = function(position) { 61 return this.each(function() { 62 63 }); 64 }; 65 66 $.fn.loadTab = function(position, url, callback) { 67 // frequently requested: if url is passed reload tab with that url 68 return this.each(function() { 69 70 }); 46 71 };*/ 47 48 $.fn.enableTab = function(position) {49 return this.each(function() {50 51 });52 };53 54 $.fn.disableTab = function(position) {55 return this.each(function() {56 57 });58 };59 60 $.fn.showTab = function(position) {61 return this.each(function() {62 63 });64 };65 66 $.fn.reloadTab = function(position, url) {67 // frequently requested: if url is passed reload tab with that url68 return this.each(function() {69 70 });71 };72 72 73 73 $.fn.activeTab = function() { … … 81 81 this.options = $.extend({ 82 82 initial: 0, 83 /*disabled: null,*/83 disabled: [], 84 84 // TODO bookmarkable: $.ajaxHistory ? true : false, 85 85 spinner: 'Loading…', … … 89 89 fxShow: null, 90 90 fxHide: null,*/ 91 closable: false, // TODO 92 closed: false, // TODO selected? 91 93 fxSpeed: 'normal', 92 94 /*fxShowSpeed: null, 93 95 fxHideSpeed: null,*/ 94 click: null, 95 show: null, 96 click: function() {}, 97 hide: function() {}, 98 show: function() {}, 96 99 navClass: 'tabs-nav', 97 100 selectedClass: 'tabs-selected', … … 118 121 instance.$containers = instance.$containers.add(a.hash); // jQuery's add() does not work somehow 119 122 } else { // remote tab 120 // TODO create and add container 123 // TODO create unique ids 124 var id = a.title && a.title.replace(/\s/g, '_') || options.hashPrefix + (i + 1), url = a.href; 125 a.href = '#' + id; 126 a.url = url; 127 instance.$containers = instance.$containers.add( 128 $('<div id="' + id + '" class="' + options.containerClass + '"></div>') 129 .insertAfter( instance.$containers[i - 1] || $source ) 130 ); 121 131 } 122 132 }); … … 162 172 //tabs.eq(options.initial).trigger('loadRemoteTab').end(); 163 173 174 // disabled tabs 175 for (var i = 0, k = options.disabled.length; i < k; i++) { 176 this.disable(--options.disabled[i]); 177 } 178 164 179 // setup animations 165 180 var showAnim = {}, hideAnim = {}, showSpeed = options.fxShowSpeed || options.fxSpeed, hideSpeed = options.fxHideSpeed || options.fxSpeed; … … 188 203 } 189 204 205 // callbacks 206 var click = options.click, hide = options.hide, show = options.show; 207 190 208 var $containers = this.$containers; 191 209 … … 196 214 //var trueClick = e.clientX; // add to history only if true click occured, not a triggered click 197 215 var clicked = this, $li = $(this).parents('li:eq(0)'), $show = $(this.hash), $hide = $containers.filter(':visible'); 198 216 199 217 // if animation is still running, tab is selected or disabled or onClick callback returns false stop here 200 218 // check if onClick returns false last so that it is not executed for a disabled tab 201 if ($source['locked'] || $li.is('.' + options.selectedClass , '.' + options.disabledClass)202 || typeof onClick == 'function' && onClick(this, $show[0], $hide[0]) === false) {219 if ($source['locked'] || $li.is('.' + options.selectedClass + ', .' + options.disabledClass) 220 || click(this, $show[0], $hide[0]) === false) { 203 221 this.blur(); 204 222 return false; … … 208 226 209 227 // show new tab 210 if ($show. size()) {228 if ($show.length) { 211 229 212 230 // prevent scrollbar scrolling to 0 and than back in IE7, happens only if bookmarking/history is enabled … … 232 250 $(clicked).parents('li:eq(0)').addClass(options.selectedClass).siblings().removeClass(options.selectedClass); 233 251 $hide.addClass(options.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc. 234 if (typeof onHide == 'function') { 235 onHide(clicked, $show[0], $hide[0]); 236 } 252 hide(clicked, $show[0], $hide[0]); 237 253 if (!(options.fxSlide || options.fxFade || options.fxShow)) { 238 254 $show.css('display', 'block'); // prevent occasionally occuring flicker in Firefox cause by gap between showing and hiding the tab containers … … 244 260 $show[0].style.filter = ''; 245 261 } 246 if (typeof onShow == 'function') { 247 onShow(clicked, $show[0], $hide[0]); 248 } 262 show(clicked, $show[0], $hide[0]); 249 263 $source['locked'] = null; 250 264 }); 251 265 }); 252 266 } 253 switchTab(); 254 255 /*if (!options.remote) { 267 268 if (this.url) { // remote tab 269 instance.load(instance.$tabs.index(this) + 1, this.url, switchTab) 270 } else { 256 271 switchTab(); 257 } else { 258 $(clicked).trigger('loadRemoteTab', [switchTab]); 259 }*/ 272 } 273 274 // Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash 275 var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0; 276 var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0; 277 setTimeout(function() { 278 scrollTo(scrollX, scrollY); 279 }, 0); 260 280 261 281 } else { 262 282 alert('There is no such container.'); 263 283 } 264 265 // Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash266 var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0;267 var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0;268 setTimeout(function() {269 scrollTo(scrollX, scrollY);270 }, 0);271 284 272 285 this.blur(); // prevent IE from keeping other link focussed when using the back button … … 298 311 } 299 312 }, 300 remove: function(position ) { // TODO callback313 remove: function(position, callback) { 301 314 if (position && position.constructor == Number) { 302 315 --position; … … 306 319 this.tabify(); 307 320 } 308 }, 309 enable: function(position) { // TODO callback 310 311 }, 312 disable: function(position) { // TODO callback 313 314 }, 315 show: function(position) { // TODO callback 316 317 }, 318 reload: function(position, url) { // TODO callback 319 321 if (callback && callback.constructor == Function) { 322 callback(); 323 } 324 }, 325 enable: function(position, callback) { 326 var $li = this.$tabs.slice(position - 1, position).parents('li:eq(0)'); 327 $li.removeClass(this.options.disabledClass); 328 if ($.browser.safari) { /* fix disappearing tab after enabling in Safari... TODO check Safari 3 */ 329 $li.animate({ opacity: 1 }, 1, function() { 330 $li.css({ opacity: '' }); 331 }); 332 } 333 if (callback && callback.constructor == Function) { 334 callback(); 335 } 336 }, 337 disable: function(position, callback) { 338 var $li = this.$tabs.slice(position - 1, position).parents('li:eq(0)'); 339 if ($.browser.safari) { /* fix opacity of tab after disabling in Safari... TODO check Safari 3 */ 340 $li.animate({ opacity: 0 }, 1, function() { 341 $li.css({ opacity: '' }); 342 }); 343 } 344 $li.addClass(this.options.disabledClass); 345 if (callback && callback.constructor == Function) { 346 callback(); 347 } 348 }, 349 show: function(position, callback) { // TODO callback 350 351 }, 352 load: function(position, url, callback) { // TODO callback 353 var options = this.options; 354 if (url && url.constructor == Function) { // shift arguments 355 callback = url; 356 } 357 var $a = this.$tabs.slice(position - 1, position).addClass(options.loadingClass), 358 $span = $('span', $a), text = $span.html(); 359 if (options.spinner) { 360 // TODO if spinner is image 361 $span.html('<em>' + options.spinner + '</em>'); 362 } 363 setTimeout(function() { // Timeout is again required in IE, "wait" for id being restored 364 $($a[0].hash).load(url, function() { 365 if (options.spinner) { 366 $span.html(text); 367 } 368 $a.removeClass(options.loadingClass); 369 if (callback && callback.constructor == Function) { 370 callback(); 371 } 372 }); 373 }, 0); 320 374 } 321 375 }); 322 376 323 324 377 })(jQuery); 325 378
