2012-02-16 12:27:47 +01:00
|
|
|
jQuery.noConflict();
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* File: LeftAndMain.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
2011-12-17 04:06:56 +01:00
|
|
|
// setup jquery.entwine
|
|
|
|
$.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE;
|
|
|
|
$.entwine('ss', function($) {
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Position the loading spinner animation below the ss logo
|
|
|
|
*/
|
|
|
|
var positionLoadingSpinner = function() {
|
|
|
|
var offset = 120; // offset from the ss logo
|
|
|
|
var spinner = $('.ss-loading-screen .loading-animation');
|
|
|
|
var top = ($(window).height() - spinner.height()) / 2;
|
|
|
|
spinner.css('top', top + offset);
|
|
|
|
spinner.show();
|
2012-02-21 17:46:58 +01:00
|
|
|
};
|
2011-12-17 00:51:32 +01:00
|
|
|
|
2012-03-27 17:06:58 +02:00
|
|
|
// apply an select element only when it is ready, ie. when it is rendered into a template
|
|
|
|
// with css applied and got a width value.
|
|
|
|
var applyChosen = function(el){
|
|
|
|
if(el.outerWidth()){
|
2012-06-15 04:32:21 +02:00
|
|
|
el.chosen({
|
|
|
|
'allow_single_deselect': true
|
|
|
|
}).addClass("has-chzn");
|
2012-03-27 15:31:04 +02:00
|
|
|
// Copy over title attribute if required
|
|
|
|
if(el.attr('title')) el.siblings('.chzn-container').attr('title', el.attr('title'));
|
2012-03-27 17:06:58 +02:00
|
|
|
} else {
|
|
|
|
setTimeout(function() {applyChosen(el);},500);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
$(window).bind('resize', positionLoadingSpinner).trigger('resize');
|
2011-12-13 11:35:00 +01:00
|
|
|
|
2012-03-30 18:30:01 +02:00
|
|
|
// global ajax handlers
|
2012-03-24 03:19:02 +01:00
|
|
|
$(document).ajaxComplete(function(e, xhr, settings) {
|
|
|
|
// Simulates a redirect on an ajax response.
|
|
|
|
if(window.History.enabled) {
|
2012-05-29 11:34:47 +02:00
|
|
|
var url = xhr.getResponseHeader('X-ControllerURL'), opts, requestHeaders = settings.headers;
|
2012-03-24 03:19:02 +01:00
|
|
|
// Normalize trailing slashes in URL to work around routing weirdnesses in SS_HTTPRequest.
|
|
|
|
var isSame = (url && History.getPageUrl().replace(/\/+$/, '') == url.replace(/\/+$/, ''));
|
|
|
|
if(url && !isSame) {
|
2012-04-18 22:11:40 +02:00
|
|
|
opts = {pjax: xhr.getResponseHeader('X-Pjax') ? xhr.getResponseHeader('X-Pjax') : settings.headers['X-Pjax']};
|
2012-03-24 03:19:02 +01:00
|
|
|
window.History.pushState(opts, '', url);
|
2012-03-24 04:35:18 +01:00
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
2012-04-17 17:12:15 +02:00
|
|
|
|
2012-05-10 10:44:21 +02:00
|
|
|
// Handle custom status message headers
|
|
|
|
var msg = (xhr.getResponseHeader('X-Status')) ? xhr.getResponseHeader('X-Status') : xhr.statusText,
|
|
|
|
msgType = (xhr.status < 200 || xhr.status > 399) ? 'bad' : 'good',
|
|
|
|
ignoredMessages = ['OK'];
|
|
|
|
|
|
|
|
// Show message (but ignore aborted requests)
|
|
|
|
if(xhr.status !== 0 && msg && $.inArray(msg, ignoredMessages)) {
|
2012-05-14 15:13:49 +02:00
|
|
|
// Decode into UTF-8, HTTP headers don't allow multibyte
|
|
|
|
statusMessage(decodeURIComponent(msg), msgType);
|
2012-03-24 03:19:02 +01:00
|
|
|
}
|
|
|
|
});
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-05-10 10:44:21 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Main LeftAndMain interface with some control panel and an edit form.
|
|
|
|
*
|
|
|
|
* Events:
|
|
|
|
* ajaxsubmit - ...
|
|
|
|
* validate - ...
|
2012-06-12 17:13:36 +02:00
|
|
|
* aftersubmitform - ...
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-container').entwine({
|
2011-06-09 03:49:52 +02:00
|
|
|
|
|
|
|
CurrentXHR: null,
|
2012-06-14 18:23:54 +02:00
|
|
|
|
|
|
|
StateChangeCount: 0,
|
2011-06-09 03:49:52 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Constructor: onmatch
|
|
|
|
*/
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2011-03-23 10:51:00 +01:00
|
|
|
var self = this;
|
2011-06-09 03:49:52 +02:00
|
|
|
|
2011-04-24 02:31:11 +02:00
|
|
|
// Browser detection
|
|
|
|
if($.browser.msie && parseInt($.browser.version, 10) < 7) {
|
|
|
|
$('.ss-loading-screen').append(
|
2011-12-15 16:54:33 +01:00
|
|
|
'<p class="ss-loading-incompat-warning"><span class="notice">' +
|
|
|
|
'Your browser is not compatible with the CMS interface. Please use Internet Explorer 7+, Google Chrome 10+ or Mozilla Firefox 3.5+.' +
|
2011-04-24 02:31:11 +02:00
|
|
|
'</span></p>'
|
2011-12-15 16:54:33 +01:00
|
|
|
).css('z-index', $('.ss-loading-screen').css('z-index')+1);
|
|
|
|
$('.loading-animation').remove();
|
2012-05-11 06:07:07 +02:00
|
|
|
|
|
|
|
this._super();
|
2011-04-24 02:31:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-21 18:39:26 +02:00
|
|
|
// Initialize layouts
|
2011-05-15 05:43:21 +02:00
|
|
|
this.redraw();
|
2011-07-21 20:14:33 +02:00
|
|
|
|
2011-04-15 00:35:09 +02:00
|
|
|
// Remove loading screen
|
|
|
|
$('.ss-loading-screen').hide();
|
|
|
|
$('body').removeClass('loading');
|
|
|
|
$(window).unbind('resize', positionLoadingSpinner);
|
2011-06-09 03:49:52 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
|
|
|
fromWindow: {
|
|
|
|
onstatechange: function(){ this.handleStateChange(); },
|
|
|
|
onresize: function(){ this.redraw(); }
|
2012-05-14 01:43:36 +02:00
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
|
|
|
'from .cms-panel': {
|
|
|
|
ontoggle: function(){ this.redraw(); }
|
2012-06-12 17:13:36 +02:00
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
|
|
|
'from .cms-container': {
|
|
|
|
onaftersubmitform: function(){ this.redraw(); }
|
|
|
|
},
|
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
redraw: function() {
|
2012-05-30 20:57:18 +02:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
2011-07-21 18:39:26 +02:00
|
|
|
// Move from inner to outer layouts. Some of the elements might not exist.
|
2011-12-15 22:04:03 +01:00
|
|
|
// Not all edit forms are layouted, so qualify by their data value.
|
2012-06-06 21:02:13 +02:00
|
|
|
|
|
|
|
this.layout({resize: false});
|
|
|
|
this.find('.cms-panel-layout').redraw();
|
2012-03-07 16:20:28 +01:00
|
|
|
this.find('.cms-content-fields[data-layout-type]').redraw();
|
2012-02-16 17:37:46 +01:00
|
|
|
this.find('.cms-edit-form[data-layout-type]').redraw();
|
2012-02-17 15:58:15 +01:00
|
|
|
this.find('.cms-preview').redraw();
|
2012-06-06 21:02:13 +02:00
|
|
|
this.find('.cms-content').redraw();
|
2011-07-21 18:39:26 +02:00
|
|
|
this.layout({resize: false});
|
2011-06-09 03:49:52 +02:00
|
|
|
},
|
2011-12-15 12:16:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy around History.pushState() which handles non-HTML5 fallbacks,
|
|
|
|
* as well as global change tracking. Change tracking needs to be synchronous rather than event/callback
|
|
|
|
* based because the user needs to be able to abort the action completely.
|
|
|
|
*
|
|
|
|
* See handleStateChange() for more details.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - {String} url
|
|
|
|
* - {String} title New window title
|
|
|
|
* - {Object} data Any additional data passed through to History.pushState()
|
|
|
|
*/
|
|
|
|
loadPanel: function(url, title, data) {
|
2012-02-21 17:46:58 +01:00
|
|
|
if(!data) data = {};
|
2012-03-24 02:20:33 +01:00
|
|
|
if(!title) title = "";
|
2012-05-30 15:01:40 +02:00
|
|
|
|
2011-12-15 12:23:32 +01:00
|
|
|
// Check change tracking (can't use events as we need a way to cancel the current state change)
|
2012-05-30 15:01:40 +02:00
|
|
|
var contentEls = this._findFragments(data.pjax ? data.pjax.split(',') : ['Content']);
|
|
|
|
var trackedEls = contentEls.find(':data(changetracker)').add(contentEls.filter(':data(changetracker)'));
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-12-15 12:23:32 +01:00
|
|
|
if(trackedEls.length) {
|
|
|
|
var abort = false;
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-12-15 12:23:32 +01:00
|
|
|
trackedEls.each(function() {
|
|
|
|
if(!$(this).confirmUnsavedChanges()) abort = true;
|
|
|
|
});
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-12-15 12:23:32 +01:00
|
|
|
if(abort) return;
|
|
|
|
}
|
2012-03-24 02:20:33 +01:00
|
|
|
|
2011-12-15 12:16:54 +01:00
|
|
|
if(window.History.enabled) {
|
|
|
|
// Active menu item is set based on X-Controller ajax header,
|
|
|
|
// which matches one class on the menu
|
|
|
|
window.History.pushState(data, title, url);
|
|
|
|
} else {
|
2011-12-14 15:37:42 +01:00
|
|
|
window.location = $.path.makeUrlAbsolute(url, $('base').attr('href'));
|
2011-12-15 12:16:54 +01:00
|
|
|
}
|
|
|
|
},
|
2012-05-30 11:57:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: submitForm
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* {DOMElement} form - The form to be submitted. Needs to be passed
|
|
|
|
* in to avoid entwine methods/context being removed through replacing the node itself.
|
|
|
|
* {DOMElement} button - The pressed button (optional)
|
|
|
|
* {Function} callback - Called in complete() handler of jQuery.ajax()
|
|
|
|
* {Object} ajaxOptions - Object literal to merge into $.ajax() call
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* (boolean)
|
|
|
|
*/
|
|
|
|
submitForm: function(form, button, callback, ajaxOptions) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// look for save button
|
|
|
|
if(!button) button = this.find('.Actions :submit[name=action_save]');
|
|
|
|
// default to first button if none given - simulates browser behaviour
|
|
|
|
if(!button) button = this.find('.Actions :submit:first');
|
|
|
|
|
2012-06-12 17:13:36 +02:00
|
|
|
form.trigger('beforesubmitform');
|
2012-05-30 11:57:49 +02:00
|
|
|
this.trigger('submitform', {form: form, button: button});
|
|
|
|
|
|
|
|
// set button to "submitting" state
|
|
|
|
$(button).addClass('loading');
|
|
|
|
|
|
|
|
// validate if required
|
|
|
|
if(!form.validate()) {
|
|
|
|
// TODO Automatically switch to the tab/position of the first error
|
|
|
|
statusMessage("Validation failed.", "bad");
|
|
|
|
|
|
|
|
$(button).removeClass('loading');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// save tab selections in order to reconstruct them later
|
|
|
|
var selectedTabs = [];
|
|
|
|
form.find('.cms-tabset').each(function(i, el) {
|
|
|
|
if($(el).attr('id')) selectedTabs.push({id:$(el).attr('id'), selected:$(el).tabs('option', 'selected')});
|
|
|
|
});
|
|
|
|
|
|
|
|
// get all data from the form
|
|
|
|
var formData = form.serializeArray();
|
|
|
|
// add button action
|
|
|
|
formData.push({name: $(button).attr('name'), value:'1'});
|
|
|
|
// Artificial HTTP referer, IE doesn't submit them via ajax.
|
|
|
|
// Also rewrites anchors to their page counterparts, which is important
|
|
|
|
// as automatic browser ajax response redirects seem to discard the hash/fragment.
|
|
|
|
formData.push({name: 'BackURL', value:History.getPageUrl()});
|
|
|
|
|
|
|
|
// Standard Pjax behaviour is to replace the submitted form with new content.
|
|
|
|
// The returned view isn't always decided upon when the request
|
|
|
|
// is fired, so the server might decide to change it based on its own logic,
|
|
|
|
// sending back different `X-Pjax` headers and content
|
|
|
|
jQuery.ajax(jQuery.extend({
|
|
|
|
headers: {"X-Pjax" : "CurrentForm,Breadcrumbs"},
|
|
|
|
url: form.attr('action'),
|
|
|
|
data: formData,
|
|
|
|
type: 'POST',
|
|
|
|
complete: function() {
|
|
|
|
$(button).removeClass('loading');
|
|
|
|
},
|
|
|
|
success: function(data, status, xhr) {
|
|
|
|
form.removeClass('changed'); // TODO This should be using the plugin API
|
2012-06-11 13:33:41 +02:00
|
|
|
if(callback) callback(data, status, xhr);
|
2012-05-30 11:57:49 +02:00
|
|
|
|
|
|
|
var newContentEls = self.handleAjaxResponse(data, status, xhr);
|
|
|
|
if(!newContentEls) return;
|
|
|
|
|
|
|
|
var newForm = newContentEls.filter('form');
|
|
|
|
|
|
|
|
// Re-init tabs (in case the form tag itself is a tabset)
|
|
|
|
if(newForm.hasClass('cms-tabset')) newForm.removeClass('cms-tabset').addClass('cms-tabset');
|
|
|
|
|
|
|
|
// re-select previously saved tabs
|
|
|
|
$.each(selectedTabs, function(i, selectedTab) {
|
|
|
|
newForm.find('#' + selectedTab.id).tabs('select', selectedTab.selected);
|
|
|
|
});
|
|
|
|
|
2012-06-12 17:13:36 +02:00
|
|
|
newForm.trigger('aftersubmitform', {status: status, xhr: xhr, formData: formData});
|
2012-05-30 11:57:49 +02:00
|
|
|
},
|
|
|
|
dataType: 'json'
|
|
|
|
}, ajaxOptions));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2011-06-09 03:49:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles ajax loading of new panels through the window.History object.
|
|
|
|
* To trigger loading, pass a new URL to window.History.pushState().
|
2011-12-15 12:16:54 +01:00
|
|
|
* Use loadPanel() as a pushState() wrapper as it provides some additional functionality
|
|
|
|
* like global changetracking and user aborts.
|
2011-06-09 03:49:52 +02:00
|
|
|
*
|
|
|
|
* Due to the nature of history management, no callbacks are allowed.
|
|
|
|
* Use the 'beforestatechange' and 'afterstatechange' events instead,
|
|
|
|
* or overwrite the beforeLoad() and afterLoad() methods on the
|
|
|
|
* DOM element you're loading the new content into.
|
|
|
|
* Although you can pass data into pushState(), it shouldn't contain
|
|
|
|
* DOM elements or callback closures.
|
|
|
|
*
|
|
|
|
* The passed URL should allow reconstructing important interface state
|
|
|
|
* without additional parameters, in the following use cases:
|
|
|
|
* - Explicit loading through History.pushState()
|
|
|
|
* - Implicit loading through browser navigation event triggered by the user (forward or back)
|
|
|
|
* - Full window refresh without ajax
|
|
|
|
* For example, a ModelAdmin search event should contain the search terms
|
|
|
|
* as URL parameters, and the result display should automatically appear
|
|
|
|
* if the URL is loaded without ajax.
|
|
|
|
*/
|
|
|
|
handleStateChange: function() {
|
|
|
|
// Don't allow parallel loading to avoid edge cases
|
|
|
|
if(this.getCurrentXHR()) this.getCurrentXHR().abort();
|
2012-04-18 22:11:40 +02:00
|
|
|
|
|
|
|
var self = this, h = window.History, state = h.getState(),
|
|
|
|
fragments = state.data.pjax || 'Content', headers = {},
|
2012-05-30 15:01:40 +02:00
|
|
|
contentEls = this._findFragments(fragments.split(','));
|
2012-06-14 18:23:54 +02:00
|
|
|
|
|
|
|
// For legacy IE versions (IE7 and IE8), reload without ajax
|
|
|
|
// as a crude way to fix memory leaks through whole window refreshes.
|
|
|
|
this.setStateChangeCount(this.getStateChangeCount() + 1);
|
|
|
|
var isLegacyIE = ($.browser.msie && parseInt($.browser.version, 10) < 9);
|
|
|
|
if(isLegacyIE && this.getStateChangeCount() > 20) {
|
|
|
|
document.location.href = state.url;
|
|
|
|
return;
|
|
|
|
}
|
2011-06-09 03:49:52 +02:00
|
|
|
|
2012-05-30 15:01:40 +02:00
|
|
|
this.trigger('beforestatechange', {state: state, element: contentEls});
|
2011-07-15 10:37:46 +02:00
|
|
|
|
2012-05-29 11:34:47 +02:00
|
|
|
// Set Pjax headers, which can declare a preference for the returned view.
|
|
|
|
// The actually returned view isn't always decided upon when the request
|
|
|
|
// is fired, so the server might decide to change it based on its own logic.
|
2012-04-18 22:11:40 +02:00
|
|
|
headers['X-Pjax'] = fragments;
|
2012-03-24 03:19:02 +01:00
|
|
|
|
2012-04-18 22:11:40 +02:00
|
|
|
contentEls.addClass('loading');
|
2011-06-09 03:49:52 +02:00
|
|
|
var xhr = $.ajax({
|
2012-03-24 03:19:02 +01:00
|
|
|
headers: headers,
|
2011-06-09 03:49:52 +02:00
|
|
|
url: state.url,
|
2012-05-30 15:01:40 +02:00
|
|
|
complete: function() {
|
2012-04-18 22:11:40 +02:00
|
|
|
// Remove loading indication from old content els (regardless of which are replaced)
|
|
|
|
contentEls.removeClass('loading');
|
2011-07-15 10:37:46 +02:00
|
|
|
},
|
2012-05-30 15:01:40 +02:00
|
|
|
success: function(data, status, xhr) {
|
|
|
|
var els = self.handleAjaxResponse(data, status, xhr);
|
|
|
|
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: els});
|
2011-06-09 03:49:52 +02:00
|
|
|
}
|
|
|
|
});
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-06-09 03:49:52 +02:00
|
|
|
this.setCurrentXHR(xhr);
|
2012-03-24 02:20:33 +01:00
|
|
|
},
|
2012-04-18 22:11:40 +02:00
|
|
|
|
2012-05-30 15:01:40 +02:00
|
|
|
/**
|
|
|
|
* Handles ajax responses containing plain HTML, or mulitple
|
|
|
|
* PJAX fragments wrapped in JSON (see PjaxResponseNegotiator PHP class).
|
|
|
|
* Can be hooked into an ajax 'success' callback.
|
|
|
|
*/
|
|
|
|
handleAjaxResponse: function(data, status, xhr) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// Pseudo-redirects via X-ControllerURL might return empty data, in which
|
|
|
|
// case we'll ignore the response
|
|
|
|
if(!data) return;
|
|
|
|
|
|
|
|
// Update title
|
|
|
|
var title = xhr.getResponseHeader('X-Title');
|
|
|
|
if(title) document.title = title;
|
|
|
|
|
2012-06-12 17:13:36 +02:00
|
|
|
var newFragments = {}, newContentEls;
|
2012-05-30 15:01:40 +02:00
|
|
|
if(xhr.getResponseHeader('Content-Type') == 'text/json') {
|
|
|
|
newFragments = data;
|
|
|
|
} else {
|
|
|
|
// Fall back to replacing the content fragment if HTML is returned
|
|
|
|
newFragments['Content'] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace each fragment individually
|
|
|
|
$.each(newFragments, function(newFragment, html) {
|
|
|
|
var contentEl = $('[data-pjax-fragment]').filter(function() {
|
|
|
|
return $.inArray(newFragment, $(this).data('pjaxFragment').split(' ')) != -1;
|
|
|
|
}), newContentEl = $(html);
|
|
|
|
|
|
|
|
// Add to result collection
|
2012-06-12 17:13:36 +02:00
|
|
|
if(newContentEls) newContentEls.add(newContentEl);
|
|
|
|
else newContentEls = newContentEl;
|
2012-05-30 15:01:40 +02:00
|
|
|
|
|
|
|
// Update panels
|
|
|
|
if(newContentEl.find('.cms-container').length) {
|
|
|
|
throw 'Content loaded via ajax is not allowed to contain tags matching the ".cms-container" selector to avoid infinite loops';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set loading state and store element state
|
|
|
|
var origStyle = contentEl.attr('style');
|
|
|
|
var origVisible = contentEl.is(':visible');
|
|
|
|
var layoutClasses = ['east', 'west', 'center', 'north', 'south'];
|
|
|
|
var elemClasses = contentEl.attr('class');
|
|
|
|
var origLayoutClasses = [];
|
|
|
|
if(elemClasses) {
|
|
|
|
origLayoutClasses = $.grep(
|
|
|
|
elemClasses.split(' '),
|
|
|
|
function(val) { return ($.inArray(val, layoutClasses) >= 0);}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
newContentEl
|
|
|
|
.removeClass(layoutClasses.join(' '))
|
|
|
|
.addClass(origLayoutClasses.join(' '));
|
|
|
|
if(origStyle) newContentEl.attr('style', origStyle);
|
|
|
|
newContentEl.css('visibility', 'hidden');
|
|
|
|
|
|
|
|
// Allow injection of inline styles, as they're not allowed in the document body.
|
|
|
|
// Not handling this through jQuery.ondemand to avoid parsing the DOM twice.
|
|
|
|
var styles = newContentEl.find('style').detach();
|
|
|
|
if(styles.length) $(document).find('head').append(styles);
|
|
|
|
|
|
|
|
// Replace panel completely (we need to override the "layout" attribute, so can't replace the child instead)
|
|
|
|
contentEl.replaceWith(newContentEl);
|
|
|
|
|
|
|
|
// Unset loading and restore element state (to avoid breaking existing panel visibility, e.g. with preview expanded)
|
|
|
|
if(origVisible) newContentEl.css('visibility', 'visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.redraw();
|
|
|
|
|
|
|
|
return newContentEls;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - fragments {Array}
|
|
|
|
* Returns: jQuery collection
|
|
|
|
*/
|
|
|
|
_findFragments: function(fragments) {
|
|
|
|
return $('[data-pjax-fragment]').filter(function() {
|
|
|
|
// Allows for more than one fragment per node
|
|
|
|
var i, nodeFragments = $(this).data('pjaxFragment').split(' ');
|
|
|
|
for(i in fragments) {
|
|
|
|
if($.inArray(fragments[i], nodeFragments) != -1) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-03-24 02:20:33 +01:00
|
|
|
/**
|
|
|
|
* Function: refresh
|
|
|
|
*
|
|
|
|
* Updates the container based on the current url
|
|
|
|
*
|
|
|
|
* Returns: void
|
|
|
|
*/
|
|
|
|
refresh: function() {
|
|
|
|
$(window).trigger('statechange');
|
|
|
|
|
|
|
|
$(this).redraw();
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
});
|
2012-03-24 02:20:33 +01:00
|
|
|
|
2012-05-30 15:38:08 +02:00
|
|
|
/**
|
|
|
|
* Add loading overlay to selected regions in the CMS automatically.
|
|
|
|
* Not applied to all "*.loading" elements to avoid secondary regions
|
|
|
|
* like the breadcrumbs showing unnecessary loading status.
|
|
|
|
*/
|
|
|
|
$('form.loading,.cms-content.loading,.cms-content-fields.loading,.cms-content-view.loading').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this.append('<div class="cms-content-loading-overlay ui-widget-overlay-light"></div><div class="cms-content-loading-spinner"></div>');
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this.find('.cms-content-loading-overlay,.cms-content-loading-spinner').remove();
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-06-15 00:05:41 +02:00
|
|
|
/** Make all buttons "hoverable" with jQuery theming. */
|
|
|
|
$('.cms input[type="submit"], .cms button, .cms input[type="reset"], .cms .ss-ui-button').entwine({
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2012-06-15 00:05:41 +02:00
|
|
|
this.addClass('ss-ui-button');
|
2012-02-17 00:35:10 +01:00
|
|
|
if(!this.data('button')) this.button();
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
|
|
|
this.button('destroy');
|
2012-02-17 00:35:10 +01:00
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-07 17:17:18 +01:00
|
|
|
/**
|
|
|
|
* Loads the link's 'href' attribute into a panel via ajax,
|
|
|
|
* as opposed to triggering a full page reload.
|
|
|
|
* Little helper to avoid repetition, and make it easy to
|
|
|
|
* "opt in" to panel loading, while by default links still exhibit their default behaviour.
|
2012-05-30 15:01:40 +02:00
|
|
|
* The PJAX target can be specified via a 'data-pjax-target' attribute.
|
2012-03-07 17:17:18 +01:00
|
|
|
*/
|
2012-04-10 08:16:03 +02:00
|
|
|
$('.cms .cms-panel-link').entwine({
|
2012-03-07 17:17:18 +01:00
|
|
|
onclick: function(e) {
|
2012-04-17 22:28:36 +02:00
|
|
|
var href = this.attr('href'),
|
|
|
|
url = (href && !href.match(/^#/)) ? href : this.data('href'),
|
2012-05-30 15:01:40 +02:00
|
|
|
data = {pjax: this.data('pjaxTarget')};
|
2012-04-10 08:16:03 +02:00
|
|
|
|
2012-03-07 17:17:18 +01:00
|
|
|
$('.cms-container').loadPanel(url, null, data);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does an ajax loads of the link's 'href' attribute via ajax and displays any FormResponse messages from the CMS.
|
|
|
|
* Little helper to avoid repetition, and make it easy to trigger actions via a link,
|
|
|
|
* without reloading the page, changing the URL, or loading in any new panel content.
|
|
|
|
*/
|
2012-03-24 02:20:33 +01:00
|
|
|
$('.cms .ss-ui-button-ajax').entwine({
|
2012-03-07 17:17:18 +01:00
|
|
|
onclick: function(e) {
|
2012-03-24 02:20:33 +01:00
|
|
|
$(this).removeClass('ui-button-text-only');
|
|
|
|
$(this).addClass('ss-ui-button-loading ui-button-text-icons');
|
|
|
|
|
|
|
|
var loading = $(this).find(".ss-ui-loading-icon");
|
|
|
|
|
|
|
|
if(loading.length < 1) {
|
|
|
|
loading = $("<span></span>").addClass('ss-ui-loading-icon ui-button-icon-primary ui-icon');
|
|
|
|
|
|
|
|
$(this).prepend(loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
loading.show();
|
|
|
|
|
2012-03-07 17:17:18 +01:00
|
|
|
var href = this.attr('href'), url = href ? href : this.data('href');
|
|
|
|
|
|
|
|
jQuery.ajax({
|
|
|
|
url: url,
|
|
|
|
// Ensure that form view is loaded (rather than whole "Content" template)
|
|
|
|
complete: function(xmlhttp, status) {
|
|
|
|
var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.responseText;
|
2012-03-24 02:20:33 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (typeof msg != "undefined" && msg != null) eval(msg);
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
|
|
|
|
$(".cms-container").refresh();
|
|
|
|
|
|
|
|
$(this).removeClass('ss-ui-button-loading ui-button-text-icons');
|
|
|
|
$(this).addClass('ui-button-text-only');
|
2012-03-07 17:17:18 +01:00
|
|
|
},
|
|
|
|
dataType: 'html'
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2012-02-08 15:34:06 +01:00
|
|
|
* Trigger dialogs with iframe based on the links href attribute (see ssui-core.js).
|
2011-03-23 10:51:00 +01:00
|
|
|
*/
|
2012-03-01 11:59:28 +01:00
|
|
|
$('.cms .ss-ui-dialog-link').entwine({
|
2012-02-08 15:34:06 +01:00
|
|
|
UUID: null,
|
2011-03-23 10:51:00 +01:00
|
|
|
onmatch: function() {
|
2012-02-08 15:34:06 +01:00
|
|
|
this._super();
|
|
|
|
this.setUUID(new Date().getTime());
|
2011-12-17 00:51:32 +01:00
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-02-08 15:34:06 +01:00
|
|
|
onclick: function() {
|
|
|
|
this._super();
|
2011-12-17 00:51:32 +01:00
|
|
|
|
2012-02-08 15:34:06 +01:00
|
|
|
var self = this, id = 'ss-ui-dialog-' + this.getUUID();
|
|
|
|
var dialog = $('#' + id);
|
|
|
|
if(!dialog.length) {
|
|
|
|
dialog = $('<div class="ss-ui-dialog" id="' + id + '" />');
|
|
|
|
$('body').append(dialog);
|
|
|
|
}
|
2012-04-03 02:48:43 +02:00
|
|
|
|
|
|
|
var extraClass = this.data('popupclass')?this.data('popupclass'):'';
|
|
|
|
|
|
|
|
dialog.ssdialog({iframeUrl: this.attr('href'), autoOpen: true, dialogExtraClass: extraClass});
|
2011-03-23 10:51:00 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-04-03 02:48:43 +02:00
|
|
|
|
2012-01-23 09:01:30 +01:00
|
|
|
/**
|
|
|
|
* Add styling to all contained buttons, and create buttonsets if required.
|
|
|
|
*/
|
2012-06-06 21:02:13 +02:00
|
|
|
$('.cms-content .Actions').entwine({
|
2012-05-11 05:31:12 +02:00
|
|
|
onmatch: function() {
|
|
|
|
this.find('.ss-ui-button').click(function() {
|
|
|
|
var form = this.form;
|
|
|
|
// forms don't natively store the button they've been triggered with
|
|
|
|
if(form) {
|
|
|
|
form.clickedButton = this;
|
|
|
|
// Reset the clicked button shortly after the onsubmit handlers
|
|
|
|
// have fired on the form
|
|
|
|
setTimeout(function() {form.clickedButton = null;}, 10);
|
|
|
|
}
|
|
|
|
});
|
2012-01-23 09:01:30 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
this.redraw();
|
|
|
|
this._super();
|
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-05-11 05:31:12 +02:00
|
|
|
redraw: function() {
|
2012-05-30 20:57:18 +02:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
// Remove whitespace to avoid gaps with inline elements
|
|
|
|
this.contents().filter(function() {
|
|
|
|
return (this.nodeType == 3 && !/\S/.test(this.nodeValue));
|
|
|
|
}).remove();
|
|
|
|
|
|
|
|
// Init buttons if required
|
|
|
|
this.find('.ss-ui-button').each(function() {
|
|
|
|
if(!$(this).data('button')) $(this).button();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mark up buttonsets
|
|
|
|
this.find('.ss-ui-buttonset').buttonset();
|
|
|
|
}
|
|
|
|
});
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2011-04-30 08:34:14 +02:00
|
|
|
/**
|
|
|
|
* Duplicates functionality in DateField.js, but due to using entwine we can match
|
|
|
|
* the DOM element on creation, rather than onclick - which allows us to decorate
|
|
|
|
* the field with a calendar icon
|
|
|
|
*/
|
2012-03-01 11:59:28 +01:00
|
|
|
$('.cms .field.date input.text').entwine({
|
2011-04-30 08:34:14 +02:00
|
|
|
onmatch: function() {
|
2012-02-16 17:13:33 +01:00
|
|
|
var holder = $(this).parents('.field.date:first'), config = holder.data();
|
2012-05-11 06:07:07 +02:00
|
|
|
if(!config.showcalendar) {
|
|
|
|
this._super();
|
|
|
|
return;
|
|
|
|
}
|
2011-04-30 08:34:14 +02:00
|
|
|
|
|
|
|
config.showOn = 'button';
|
|
|
|
if(config.locale && $.datepicker.regional[config.locale]) {
|
|
|
|
config = $.extend(config, $.datepicker.regional[config.locale], {});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).datepicker(config);
|
|
|
|
// // Unfortunately jQuery UI only allows configuration of icon images, not sprites
|
|
|
|
// this.next('button').button('option', 'icons', {primary : 'ui-icon-calendar'});
|
|
|
|
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
2011-04-30 08:34:14 +02:00
|
|
|
this._super();
|
|
|
|
}
|
2011-08-05 05:46:57 +02:00
|
|
|
});
|
2011-04-30 08:34:14 +02:00
|
|
|
|
2011-08-05 05:46:57 +02:00
|
|
|
/**
|
|
|
|
* Styled dropdown select fields via chosen. Allows things like search and optgroup
|
|
|
|
* selection support. Rather than manually adding classes to selects we want
|
|
|
|
* styled, we style everything but the ones we tell it not to.
|
|
|
|
*
|
|
|
|
* For the CMS we also need to tell the parent div that his has a select so
|
|
|
|
* we can fix the height cropping.
|
|
|
|
*/
|
|
|
|
|
2012-03-05 09:21:24 +01:00
|
|
|
$('.cms .field.dropdown select, .cms .field select[multiple]').entwine({
|
2011-08-05 05:46:57 +02:00
|
|
|
onmatch: function() {
|
2012-05-11 06:07:07 +02:00
|
|
|
if(this.is('.no-chzn')) {
|
|
|
|
this._super();
|
|
|
|
return;
|
|
|
|
}
|
2012-03-05 09:21:24 +01:00
|
|
|
|
2012-03-05 16:26:28 +01:00
|
|
|
// Explicitly disable default placeholder if no custom one is defined
|
|
|
|
if(!this.data('placeholder')) this.data('placeholder', ' ');
|
|
|
|
|
2012-05-11 06:06:25 +02:00
|
|
|
// We could've gotten stale classes and DOM elements from deferred cache.
|
|
|
|
this.removeClass('has-chzn chzn-done');
|
|
|
|
this.siblings('.chzn-container').remove();
|
|
|
|
|
2012-03-27 17:06:58 +02:00
|
|
|
// Apply Chosen
|
|
|
|
applyChosen(this);
|
2011-08-05 05:46:57 +02:00
|
|
|
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
2011-08-05 05:46:57 +02:00
|
|
|
this._super();
|
|
|
|
}
|
2012-05-14 01:43:36 +02:00
|
|
|
});
|
2011-10-29 02:01:06 +02:00
|
|
|
|
|
|
|
$(".cms-panel-layout").entwine({
|
|
|
|
redraw: function() {
|
2012-05-30 20:57:18 +02:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
2012-06-06 21:02:13 +02:00
|
|
|
this.layout({resize: false});
|
2011-10-29 02:01:06 +02:00
|
|
|
}
|
|
|
|
});
|
2012-02-17 00:38:21 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
/**
|
|
|
|
* Overload the default GridField behaviour (open a new URL in the browser)
|
|
|
|
* with the CMS-specific ajax loading.
|
|
|
|
*/
|
|
|
|
$('.cms .ss-gridfield').entwine({
|
|
|
|
showDetailView: function(url) {
|
|
|
|
// Include any GET parameters from the current URL, as the view state might depend on it.
|
|
|
|
// For example, a list prefiltered through external search criteria might be passed to GridField.
|
2012-06-29 13:47:12 +02:00
|
|
|
url = $.path.addSearchParams(url, window.location.search.replace(/^\?/, ''));
|
2012-05-11 05:31:12 +02:00
|
|
|
$('.cms-container').loadPanel(url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-17 00:38:21 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
/**
|
|
|
|
* Generic search form in the CMS, often hooked up to a GridField results display.
|
|
|
|
*/
|
|
|
|
$('.cms-search-form').entwine({
|
|
|
|
|
|
|
|
onsubmit: function() {
|
|
|
|
// Remove empty elements and make the URL prettier
|
|
|
|
var nonEmptyInputs = this.find(':input:not(:submit)').filter(function() {
|
|
|
|
// Use fieldValue() from jQuery.form plugin rather than jQuery.val(),
|
|
|
|
// as it handles checkbox values more consistently
|
|
|
|
var vals = $.grep($(this).fieldValue(), function(val) { return (val);});
|
|
|
|
return (vals.length);
|
|
|
|
});
|
|
|
|
var url = this.attr('action');
|
|
|
|
if(nonEmptyInputs.length) url = $.path.addSearchParams(url, nonEmptyInputs.serialize());
|
2012-02-17 00:38:21 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
var container = this.closest('.cms-container');
|
|
|
|
container.find('.cms-edit-form').tabs('select',0); //always switch to the first tab (list view) when searching
|
|
|
|
container.loadPanel(url);
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets are processed on the serverside, so need to trigger a submit.
|
|
|
|
*/
|
|
|
|
onreset: function(e) {
|
|
|
|
this.clearForm();
|
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2012-02-17 00:38:21 +01:00
|
|
|
|
|
|
|
/**
|
2012-05-11 05:31:12 +02:00
|
|
|
* Simple toggle link, which points to a DOm element by its ID selector
|
|
|
|
* in the href attribute (which doubles as an anchor link to that element).
|
2012-02-17 00:38:21 +01:00
|
|
|
*/
|
2012-05-11 05:31:12 +02:00
|
|
|
$('.cms .cms-help-toggle').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this._super();
|
2012-03-02 15:20:17 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
$(this.attr('href')).hide();
|
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-05-11 05:31:12 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
$(this.attr('href')).toggle();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2012-03-05 17:18:30 +01:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
/**
|
|
|
|
* Allows to lazy load a panel, by leaving it empty
|
|
|
|
* and declaring a URL to load its content via a 'url' HTML5 data attribute.
|
|
|
|
* The loaded HTML is cached, with cache key being the 'url' attribute.
|
|
|
|
* In order for this to work consistently, we assume that the responses are stateless.
|
|
|
|
* To avoid caching, add a 'deferred-no-cache' to the node.
|
|
|
|
*/
|
|
|
|
window._panelDeferredCache = {};
|
|
|
|
$('.cms-panel-deferred').entwine({
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2012-05-11 05:31:12 +02:00
|
|
|
this._super();
|
|
|
|
this.redraw();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
2012-06-14 10:08:16 +02:00
|
|
|
if(window.debug) console.log('saving', this.data('url'), this);
|
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
// Save the HTML state at the last possible moment.
|
|
|
|
// Don't store the DOM to avoid memory leaks.
|
|
|
|
if(!this.data('deferredNoCache')) window._panelDeferredCache[this.data('url')] = this.html();
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
redraw: function() {
|
2012-05-30 20:57:18 +02:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
var self = this, url = this.data('url');
|
|
|
|
if(!url) throw 'Elements of class .cms-panel-deferred need a "data-url" attribute';
|
2012-04-17 17:17:45 +02:00
|
|
|
|
2012-05-11 05:31:12 +02:00
|
|
|
this._super();
|
|
|
|
|
|
|
|
// If the node is empty, try to either load it from cache or via ajax.
|
|
|
|
if(!this.children().length) {
|
|
|
|
if(!this.data('deferredNoCache') && typeof window._panelDeferredCache[url] !== 'undefined') {
|
|
|
|
this.html(window._panelDeferredCache[url]);
|
|
|
|
} else {
|
|
|
|
this.addClass('loading');
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
complete: function() {
|
|
|
|
self.removeClass('loading');
|
|
|
|
},
|
|
|
|
success: function(data, status, xhr) {
|
|
|
|
self.html(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-04-17 17:17:45 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 05:31:12 +02:00
|
|
|
});
|
2012-04-17 22:29:45 +02:00
|
|
|
|
|
|
|
/**
|
2012-05-11 05:31:12 +02:00
|
|
|
* Lightweight wrapper around jQuery UI tabs.
|
|
|
|
* Ensures that anchor links are set properly,
|
|
|
|
* and any nested tabs are scrolled if they have
|
|
|
|
* their height explicitly set. This is important
|
|
|
|
* for forms inside the CMS layout.
|
2012-04-17 22:29:45 +02:00
|
|
|
*/
|
2012-05-11 05:31:12 +02:00
|
|
|
$('.cms-tabset').entwine({
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2012-05-11 05:31:12 +02:00
|
|
|
// Can't name redraw() as it clashes with other CMS entwine classes
|
|
|
|
this.redrawTabs();
|
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
|
|
|
this.tabs('destroy');
|
2012-05-11 07:36:18 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-05-11 05:31:12 +02:00
|
|
|
redrawTabs: function() {
|
|
|
|
this.rewriteHashlinks();
|
|
|
|
|
|
|
|
var id = this.attr('id'), cookieId = 'ui-tabs-' + id,
|
2012-05-30 16:05:30 +02:00
|
|
|
selectedTab = this.find('ul:first .ui-tabs-selected');
|
2012-05-11 05:31:12 +02:00
|
|
|
|
|
|
|
// Fix for wrong cookie storage of deselected tabs
|
|
|
|
if($.cookie && id && $.cookie(cookieId) == -1) $.cookie(cookieId, 0);
|
2012-06-14 17:17:48 +02:00
|
|
|
if(!this.data('tabs')) this.tabs({
|
2012-05-11 05:31:12 +02:00
|
|
|
cookie: ($.cookie && id) ? { expires: 30, path: '/', name: cookieId } : false,
|
|
|
|
ajaxOptions: {
|
|
|
|
// Overwrite ajax loading to use CMS logic instead
|
|
|
|
beforeSend: function(xhr, settings) {
|
|
|
|
var makeAbs = $.path.makeUrlAbsolute,
|
|
|
|
baseUrl = $('base').attr('href'),
|
|
|
|
isSame = (makeAbs(settings.url, baseUrl) == makeAbs(document.location.href));
|
|
|
|
|
|
|
|
if(!isSame) $('.cms-container').loadPanel(settings.url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selected: (selectedTab.index() != -1) ? selectedTab.index() : 0
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace prefixes for all hashlinks in tabs.
|
|
|
|
* SSViewer rewrites them from "#Root_MyTab" to
|
|
|
|
* e.g. "/admin/#Root_MyTab" which makes them
|
|
|
|
* unusable for jQuery UI.
|
|
|
|
*/
|
|
|
|
rewriteHashlinks: function() {
|
|
|
|
$(this).find('ul a').each(function() {
|
|
|
|
var href = $(this).attr('href').replace(/.*(#.*)/, '$1');
|
|
|
|
if(href) $(this).attr('href', href);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-04-17 22:29:45 +02:00
|
|
|
});
|
2012-03-05 17:18:30 +01:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
}(jQuery));
|
|
|
|
|
|
|
|
var statusMessage = function(text, type) {
|
|
|
|
jQuery.noticeAdd({text: text, type: type});
|
|
|
|
};
|
|
|
|
|
|
|
|
var errorMessage = function(text) {
|
|
|
|
jQuery.noticeAdd({text: text, type: 'error'});
|
2012-04-02 04:29:02 +02:00
|
|
|
};
|