2009-11-21 03:22:52 +01:00
|
|
|
(function($){
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine('ss', function($){
|
2009-11-21 03:33:06 +01:00
|
|
|
/**
|
2012-11-30 01:42:43 +01:00
|
|
|
* Lightweight wrapper around jQuery UI tabs for generic tab set-up
|
2009-11-21 03:33:06 +01:00
|
|
|
*/
|
2010-04-13 07:45:29 +02:00
|
|
|
$('.ss-tabset').entwine({
|
2012-12-10 23:30:06 +01:00
|
|
|
IgnoreTabState: false,
|
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2015-06-26 02:45:02 +02:00
|
|
|
var hash = window.location.hash;
|
|
|
|
|
2011-07-21 18:39:26 +02:00
|
|
|
// Can't name redraw() as it clashes with other CMS entwine classes
|
|
|
|
this.redrawTabs();
|
2015-06-26 02:45:02 +02:00
|
|
|
|
|
|
|
if (hash !== '') {
|
|
|
|
this.openTabFromURL(hash);
|
|
|
|
}
|
|
|
|
|
2011-07-15 10:37:46 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2015-06-26 02:45:02 +02:00
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
2014-07-14 01:15:38 +02:00
|
|
|
if(this.data('tabs')) this.tabs('destroy');
|
2012-05-11 07:36:18 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2015-06-26 02:45:02 +02:00
|
|
|
|
2011-07-21 18:39:26 +02:00
|
|
|
redrawTabs: function() {
|
2009-11-21 03:32:38 +01:00
|
|
|
this.rewriteHashlinks();
|
2012-04-17 17:40:37 +02:00
|
|
|
this.tabs();
|
2009-11-21 03:32:38 +01:00
|
|
|
},
|
2015-06-26 02:45:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @func openTabFromURL
|
|
|
|
* @param {string} hash
|
|
|
|
* @desc Allows linking to a specific tab.
|
|
|
|
*/
|
|
|
|
openTabFromURL: function (hash) {
|
|
|
|
var $trigger;
|
|
|
|
|
|
|
|
// Make sure the hash relates to a valid tab.
|
|
|
|
$.each(this.find('.cms-panel-link'), function () {
|
|
|
|
// The hash in in the button's href and there is exactly one tab with that id.
|
|
|
|
if (this.href.indexOf(hash) !== -1 && $(hash).length === 1) {
|
|
|
|
$trigger = $(this);
|
|
|
|
return false; // break the loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// If there's no tab, it means the hash is invalid, so do nothing.
|
|
|
|
if ($trigger === void 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Switch to the correct tab when AJAX loading completes.
|
|
|
|
$(window).one('ajaxComplete', function () {
|
|
|
|
$trigger.click();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-11-21 03:32:38 +01:00
|
|
|
/**
|
2015-06-26 02:45:02 +02:00
|
|
|
* @func rewriteHashlinks
|
|
|
|
* @desc Ensure hash links are prefixed with the current page URL, otherwise jQuery interprets them as being external.
|
2009-11-21 03:32:38 +01:00
|
|
|
*/
|
|
|
|
rewriteHashlinks: function() {
|
|
|
|
$(this).find('ul a').each(function() {
|
2012-12-04 05:59:33 +01:00
|
|
|
if (!$(this).attr('href')) return;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-11-06 15:28:09 +01:00
|
|
|
var matches = $(this).attr('href').match(/#.*/);
|
|
|
|
if(!matches) return;
|
|
|
|
$(this).attr('href', document.location.href.replace(/#.*/, '') + matches[0]);
|
2009-11-21 03:32:38 +01:00
|
|
|
});
|
2014-07-14 01:15:38 +02:00
|
|
|
}
|
2009-11-21 03:33:06 +01:00
|
|
|
});
|
2009-11-21 03:22:52 +01:00
|
|
|
});
|
2012-05-11 07:36:18 +02:00
|
|
|
})(jQuery);
|