2011-04-28 12:36:28 +02:00
|
|
|
(function($) {
|
2012-11-29 05:41:48 +01:00
|
|
|
$.entwine('ss.preview', function($){
|
2011-05-15 05:43:21 +02:00
|
|
|
|
2011-07-15 10:35:41 +02:00
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Shows a previewable website state alongside its editable version in backend UI.
|
2011-12-17 04:06:56 +01:00
|
|
|
*
|
2012-12-03 22:16:58 +01:00
|
|
|
* Relies on the server responses to indicate if a preview is available for the
|
|
|
|
* currently loaded admin interface - signified by class ".cms-previewable" being present.
|
|
|
|
*
|
|
|
|
* The preview options at the bottom are constructured by grabbing a SilverStripeNavigator
|
|
|
|
* structure also provided by the backend.
|
2011-07-15 10:35:41 +02:00
|
|
|
*/
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-preview').entwine({
|
2012-11-29 05:41:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of SilverStripeNavigator states (SilverStripeNavigatorItem classes) to search for.
|
|
|
|
* The order is significant - if the state is not available, preview will start searching the list
|
|
|
|
* from the beginning.
|
|
|
|
*/
|
2013-01-25 11:33:48 +01:00
|
|
|
AllowedStates: ['StageLink', 'LiveLink','ArchiveLink'],
|
2012-11-29 05:41:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Name of the current preview state - one of the "AllowedStates".
|
|
|
|
*/
|
|
|
|
CurrentStateName: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Current size selection.
|
|
|
|
*/
|
|
|
|
CurrentSizeName: 'auto',
|
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
/**
|
|
|
|
* Flags whether the preview is available on this CMS section.
|
|
|
|
*/
|
|
|
|
IsPreviewEnabled: false,
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Switch the preview to different state.
|
|
|
|
* stateName can be one of the "AllowedStates".
|
|
|
|
*/
|
2012-12-03 03:17:16 +01:00
|
|
|
changeState: function(stateName) {
|
2012-11-29 05:41:48 +01:00
|
|
|
this.setCurrentStateName(stateName);
|
2012-12-03 22:16:58 +01:00
|
|
|
this._loadCurrentState();
|
2012-11-29 05:41:48 +01:00
|
|
|
this.redraw();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Change the preview mode.
|
|
|
|
* modeName can be: split, content, preview.
|
|
|
|
*/
|
2012-12-04 06:10:20 +01:00
|
|
|
changeMode: function(modeName) {
|
2012-11-29 05:41:48 +01:00
|
|
|
var container = $('.cms-container');
|
|
|
|
|
2012-12-06 04:01:33 +01:00
|
|
|
if (modeName === 'split') {
|
2012-11-29 05:41:48 +01:00
|
|
|
container.entwine('.ss').splitViewMode();
|
2012-12-06 04:01:33 +01:00
|
|
|
} else if (modeName === 'content') {
|
2012-11-29 05:41:48 +01:00
|
|
|
container.entwine('.ss').contentViewMode();
|
|
|
|
} else {
|
|
|
|
container.entwine('.ss').previewMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.redraw();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Change the preview size.
|
|
|
|
* sizeName can be: auto, desktop, tablet, mobile.
|
|
|
|
*/
|
|
|
|
changeSize: function(sizeName) {
|
|
|
|
this.setCurrentSizeName(sizeName);
|
|
|
|
|
|
|
|
this.removeClass('auto desktop tablet mobile')
|
|
|
|
.addClass(sizeName);
|
|
|
|
|
|
|
|
this.redraw();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
* Update the visual appearance to match the internal preview state.
|
|
|
|
*/
|
2012-12-04 06:10:20 +01:00
|
|
|
redraw: function() {
|
2012-12-03 03:17:16 +01:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
|
|
|
// Update preview state selector.
|
|
|
|
var currentStateName = this.getCurrentStateName();
|
|
|
|
if (currentStateName) {
|
|
|
|
this.find('.cms-preview-states').changeVisibleState(currentStateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update preview mode selectors.
|
|
|
|
var layoutOptions = $('.cms-container').entwine('.ss').getLayoutOptions();
|
|
|
|
if (layoutOptions) {
|
|
|
|
// There are two mode selectors that we need to keep in sync. Redraw both.
|
|
|
|
$('.preview-mode-selector').changeVisibleMode(layoutOptions.mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update preview size selector.
|
|
|
|
var currentSizeName = this.getCurrentSizeName();
|
|
|
|
if (currentSizeName) {
|
|
|
|
this.find('.preview-size-selector').changeVisibleSize(this.getCurrentSizeName());
|
|
|
|
}
|
2012-12-03 22:16:58 +01:00
|
|
|
|
|
|
|
return this;
|
2012-11-29 05:41:48 +01:00
|
|
|
},
|
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
/**
|
|
|
|
* Disable the area - it will not appear in the GUI.
|
|
|
|
* Caveat: the preview will be automatically enabled when ".cms-previewable" class is detected.
|
|
|
|
*/
|
|
|
|
disablePreview: function() {
|
|
|
|
this._loadUrl('about:blank');
|
|
|
|
this._block();
|
|
|
|
this.changeMode('content');
|
|
|
|
this.setIsPreviewEnabled(false);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable the area and start updating to reflect the content editing.
|
|
|
|
*/
|
|
|
|
enablePreview: function() {
|
2012-12-04 04:50:35 +01:00
|
|
|
if (!this.getIsPreviewEnabled()) {
|
|
|
|
this.setIsPreviewEnabled(true);
|
2012-12-04 06:10:20 +01:00
|
|
|
|
|
|
|
// Initialise mode.
|
|
|
|
if ($.browser.msie && $.browser.version.slice(0,3)<=7) {
|
|
|
|
// We do not support the split mode in IE < 8.
|
|
|
|
this.changeMode('content');
|
|
|
|
} else {
|
|
|
|
this.changeMode('split');
|
|
|
|
}
|
2012-12-04 04:50:35 +01:00
|
|
|
}
|
2012-12-03 22:16:58 +01:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the preview element.
|
|
|
|
*/
|
2012-06-14 23:44:22 +02:00
|
|
|
onadd: function() {
|
2011-04-28 12:36:28 +02:00
|
|
|
var self = this, layoutContainer = this.parent();
|
2012-12-03 22:16:58 +01:00
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
// Create layout and controls
|
|
|
|
this.find('iframe').addClass('center');
|
2011-05-15 05:43:21 +02:00
|
|
|
this.find('iframe').bind('load', function() {
|
2012-12-03 22:16:58 +01:00
|
|
|
self._adjustIframeForPreview();
|
2011-12-19 15:06:04 +01:00
|
|
|
|
|
|
|
// Load edit view for new page, but only if the preview is activated at the moment.
|
|
|
|
// This avoids e.g. force-redirections of the edit view on RedirectorPage instances.
|
2012-11-29 05:41:48 +01:00
|
|
|
self._loadCurrentPage();
|
2012-12-10 17:47:31 +01:00
|
|
|
|
|
|
|
$(this).removeClass('loading');
|
2011-05-15 05:43:21 +02:00
|
|
|
});
|
2011-04-28 12:36:28 +02:00
|
|
|
|
2011-07-15 10:35:41 +02:00
|
|
|
// Preview might not be available in all admin interfaces - block/disable when necessary
|
2011-09-29 06:09:36 +02:00
|
|
|
this.append('<div class="cms-preview-overlay ui-widget-overlay-light"></div>');
|
2013-01-10 23:43:20 +01:00
|
|
|
this.find('.cms-preview-overlay').hide();
|
2011-12-12 21:30:16 +01:00
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
this.disablePreview();
|
2012-11-22 02:14:11 +01:00
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-11-22 02:14:11 +01:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Set the preview to unavailable - could be still visible. This is purely visual.
|
|
|
|
*/
|
|
|
|
_block: function() {
|
|
|
|
this.addClass('blocked');
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the preview to available (remove the overlay);
|
|
|
|
*/
|
|
|
|
_unblock: function() {
|
|
|
|
this.removeClass('blocked');
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-12-04 06:10:20 +01:00
|
|
|
* Update the preview according to browser and CMS section capabilities.
|
2012-12-03 22:16:58 +01:00
|
|
|
*/
|
|
|
|
_initialiseFromContent: function() {
|
|
|
|
if (!$('.cms-previewable').length) {
|
|
|
|
this.disablePreview();
|
|
|
|
} else {
|
|
|
|
this.enablePreview();
|
|
|
|
this._moveNavigator();
|
2012-12-04 04:50:35 +01:00
|
|
|
this._loadCurrentState();
|
|
|
|
this.redraw();
|
2012-12-03 22:16:58 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update preview whenever any panels are reloaded.
|
|
|
|
*/
|
|
|
|
'from .cms-container': {
|
|
|
|
onafterstatechange: function(){
|
|
|
|
this._initialiseFromContent();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update preview whenever a form is submitted.
|
|
|
|
* This is an alternative to the LeftAndmMain::loadPanel functionality which we already
|
|
|
|
* cover in the onafterstatechange handler.
|
|
|
|
*/
|
|
|
|
'from .cms-container .cms-edit-form': {
|
|
|
|
onaftersubmitform: function(){
|
|
|
|
this._initialiseFromContent();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the URL of the preview iframe.
|
2012-11-29 05:41:48 +01:00
|
|
|
*/
|
|
|
|
_loadUrl: function(url) {
|
2012-12-10 17:47:31 +01:00
|
|
|
this.find('iframe').addClass('loading').attr('src', url);
|
2012-12-03 22:16:58 +01:00
|
|
|
return this;
|
2011-04-28 12:36:28 +02:00
|
|
|
},
|
2011-07-21 20:14:33 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* Fetch available states from the current SilverStripeNavigator (SilverStripeNavigatorItems).
|
|
|
|
* Navigator is supplied by the backend and contains all state options for the current object.
|
|
|
|
*/
|
|
|
|
_getNavigatorStates: function() {
|
|
|
|
// Walk through available states and get the URLs.
|
|
|
|
var urlMap = $.map(this.getAllowedStates(), function(name) {
|
2012-12-03 03:17:16 +01:00
|
|
|
var stateLink = $('.cms-preview-states .state-name[data-name=' + name + ']');
|
2013-01-25 11:33:48 +01:00
|
|
|
if(stateLink.length) {
|
|
|
|
return {
|
|
|
|
name: name,
|
|
|
|
url: stateLink.attr('data-link'),
|
|
|
|
active: stateLink.is(':radio') ? stateLink.is(':checked') : stateLink.is(':selected')
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2012-11-29 05:41:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return urlMap;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Load current state into the preview (e.g. StageLink or LiveLink).
|
|
|
|
* We try to reuse the state we have been previously in. Otherwise we fall back
|
|
|
|
* to the first state available on the "AllowedStates" list.
|
|
|
|
*
|
|
|
|
* @returns New state name.
|
2012-11-29 05:41:48 +01:00
|
|
|
*/
|
2012-12-03 22:16:58 +01:00
|
|
|
_loadCurrentState: function() {
|
|
|
|
if (!this.getIsPreviewEnabled()) return this;
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
var states = this._getNavigatorStates();
|
|
|
|
var currentStateName = this.getCurrentStateName();
|
|
|
|
var currentState = null;
|
|
|
|
|
|
|
|
// Find current state within currently available states.
|
|
|
|
if (states) {
|
|
|
|
currentState = $.grep(states, function(state, index) {
|
2013-01-25 11:33:48 +01:00
|
|
|
return (
|
|
|
|
currentStateName === state.name ||
|
|
|
|
(!currentStateName && state.active)
|
|
|
|
);
|
2012-11-29 05:41:48 +01:00
|
|
|
});
|
|
|
|
}
|
2012-11-22 02:14:11 +01:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
if (currentState[0]) {
|
2012-12-03 22:16:58 +01:00
|
|
|
// State is available on the newly loaded content. Get it.
|
2012-11-29 05:41:48 +01:00
|
|
|
this._loadUrl(currentState[0].url);
|
|
|
|
this._unblock();
|
|
|
|
} else if (states.length) {
|
2012-12-03 22:16:58 +01:00
|
|
|
// Fall back to the first available content state.
|
2012-11-29 05:41:48 +01:00
|
|
|
this.setCurrentStateName(states[0].name);
|
|
|
|
this._loadUrl(states[0].url);
|
|
|
|
this._unblock();
|
2012-06-12 12:48:08 +02:00
|
|
|
} else {
|
2012-12-03 22:16:58 +01:00
|
|
|
// No state available at all.
|
|
|
|
this.setCurrentStateName(null);
|
2012-11-29 05:41:48 +01:00
|
|
|
this._block();
|
2012-06-12 12:48:08 +02:00
|
|
|
}
|
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
return this;
|
2012-11-22 02:14:11 +01:00
|
|
|
},
|
|
|
|
|
2012-11-27 06:03:43 +01:00
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Move the navigator from the content to the preview bar.
|
2012-11-27 06:03:43 +01:00
|
|
|
*/
|
2012-12-03 22:16:58 +01:00
|
|
|
_moveNavigator: function() {
|
|
|
|
var previewEl = $('.cms-preview .cms-preview-controls');
|
|
|
|
var navigatorEl = $('.cms-edit-form .cms-navigator');
|
2012-06-12 12:48:08 +02:00
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
if (navigatorEl.length && previewEl.length) {
|
|
|
|
// Navigator is available - install the navigator.
|
|
|
|
previewEl.html($('.cms-edit-form .cms-navigator').detach());
|
|
|
|
} else {
|
|
|
|
// Navigator not available.
|
|
|
|
this._block();
|
2012-11-27 06:03:43 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-21 20:14:33 +02:00
|
|
|
/**
|
|
|
|
* Loads the matching edit form for a page viewed in the preview iframe,
|
|
|
|
* based on metadata sent along with this document.
|
|
|
|
*/
|
2012-11-29 05:41:48 +01:00
|
|
|
_loadCurrentPage: function() {
|
2012-12-03 22:16:58 +01:00
|
|
|
if (!this.getIsPreviewEnabled()) return;
|
2011-05-15 05:43:21 +02:00
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
var doc = this.find('iframe')[0].contentDocument,
|
|
|
|
containerEl = $('.cms-container');
|
2011-05-15 05:43:21 +02:00
|
|
|
|
|
|
|
// Load this page in the admin interface if appropriate
|
2011-12-17 04:06:56 +01:00
|
|
|
var id = $(doc).find('meta[name=x-page-id]').attr('content');
|
|
|
|
var editLink = $(doc).find('meta[name=x-cms-edit-link]').attr('content');
|
|
|
|
var contentPanel = $('.cms-content');
|
|
|
|
|
2011-06-09 03:49:52 +02:00
|
|
|
if(id && contentPanel.find(':input[name=ID]').val() != id) {
|
2011-12-17 04:06:56 +01:00
|
|
|
// Ignore behaviour without history support (as we need ajax loading
|
|
|
|
// for the new form to load in the background)
|
|
|
|
if(window.History.enabled)
|
2012-11-29 05:41:48 +01:00
|
|
|
$('.cms-container').entwine('.ss').loadPanel(editLink);
|
2011-06-09 03:49:52 +02:00
|
|
|
}
|
2011-05-15 05:43:21 +02:00
|
|
|
},
|
2012-01-03 14:42:26 +01:00
|
|
|
|
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Prepare the iframe content for preview.
|
2012-01-03 14:42:26 +01:00
|
|
|
*/
|
2012-12-03 22:16:58 +01:00
|
|
|
_adjustIframeForPreview: function() {
|
2012-11-22 02:14:11 +01:00
|
|
|
var iframe = this.find('iframe')[0];
|
|
|
|
if(iframe){
|
|
|
|
var doc = iframe.contentDocument;
|
|
|
|
}else{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 21:08:31 +02:00
|
|
|
if(!doc) return;
|
2011-04-28 12:36:28 +02:00
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
// Open external links in new window to avoid "escaping" the internal page context in the preview
|
|
|
|
// iframe, which is important to stay in for the CMS logic.
|
2011-04-28 12:36:28 +02:00
|
|
|
var links = doc.getElementsByTagName('A');
|
|
|
|
for (var i = 0; i < links.length; i++) {
|
|
|
|
var href = links[i].getAttribute('href');
|
2011-07-15 10:35:41 +02:00
|
|
|
if(!href) continue;
|
|
|
|
|
2012-08-27 14:40:11 +02:00
|
|
|
if (href.match(/^http:\/\//)) links[i].setAttribute('target', '_blank');
|
2011-04-28 12:36:28 +02:00
|
|
|
}
|
2012-08-27 14:40:11 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
// Hide the navigator from the preview iframe and use only the CMS one.
|
2012-08-27 14:40:11 +02:00
|
|
|
var navi = doc.getElementById('SilverStripeNavigator');
|
|
|
|
if(navi) navi.style.display = 'none';
|
|
|
|
var naviMsg = doc.getElementById('SilverStripeNavigatorMessage');
|
|
|
|
if(naviMsg) naviMsg.style.display = 'none';
|
2012-11-29 05:41:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-edit-form').entwine({
|
|
|
|
onadd: function() {
|
2012-12-03 22:16:58 +01:00
|
|
|
$('.cms-preview')._initialiseFromContent();
|
2011-04-28 12:36:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-03 22:16:58 +01:00
|
|
|
/**
|
|
|
|
* Update the "preview unavailable" overlay according to the class.
|
|
|
|
*/
|
2011-07-15 10:35:41 +02:00
|
|
|
$('.cms-preview.blocked').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this.find('.cms-preview-overlay').show();
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2011-07-15 10:35:41 +02:00
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this.find('.cms-preview-overlay').hide();
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2011-07-15 10:35:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* "Preview state" functions.
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
$('.cms-preview-states').entwine({
|
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Change the appearance of the state selector.
|
2012-11-29 05:41:48 +01:00
|
|
|
*/
|
|
|
|
changeVisibleState: function(state) {
|
2012-12-04 04:50:35 +01:00
|
|
|
this.find('input[data-name="'+state+'"]').prop('checked', true);
|
2011-05-02 01:43:51 +02:00
|
|
|
}
|
2012-11-29 05:41:48 +01:00
|
|
|
});
|
2012-11-26 05:26:06 +01:00
|
|
|
|
2012-12-03 03:17:16 +01:00
|
|
|
$('.cms-preview-states .state-name').entwine({
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* Reacts to the user changing the state of the preview.
|
|
|
|
*/
|
2012-12-04 06:10:20 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
//Add and remove classes to make switch work ok in old IE
|
|
|
|
this.parent().find('.active').removeClass('active');
|
|
|
|
this.next('label').addClass('active');
|
|
|
|
|
2012-12-03 03:17:16 +01:00
|
|
|
var targetStateName = $(this).attr('data-name');
|
2012-11-29 05:41:48 +01:00
|
|
|
// Reload preview with the selected state.
|
2012-12-03 03:17:16 +01:00
|
|
|
$('.cms-preview').changeState(targetStateName);
|
2012-11-29 05:41:48 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Preview mode" functions
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
$('.preview-mode-selector').entwine({
|
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Change the appearance of the mode selector.
|
2012-11-29 05:41:48 +01:00
|
|
|
*/
|
|
|
|
changeVisibleMode: function(mode) {
|
|
|
|
this.find('select')
|
|
|
|
.val(mode)
|
2012-11-27 06:03:43 +01:00
|
|
|
.trigger('liszt:updated')
|
2012-11-29 05:41:48 +01:00
|
|
|
._addIcon();
|
2011-05-15 05:43:21 +02:00
|
|
|
}
|
2012-12-04 06:10:20 +01:00
|
|
|
});
|
2012-05-04 01:29:50 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
$('.preview-mode-selector select').entwine({
|
|
|
|
/**
|
|
|
|
* Reacts to the user changing the preview mode.
|
|
|
|
*/
|
2012-12-04 06:10:20 +01:00
|
|
|
onchange: function(e) {
|
2012-12-16 03:53:22 +01:00
|
|
|
this._super(e);
|
2012-11-27 06:03:43 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
var targetStateName = $(this).val();
|
|
|
|
$('.cms-preview').changeMode(targetStateName);
|
2012-11-27 06:03:43 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-04 06:10:20 +01:00
|
|
|
|
|
|
|
$('.preview-mode-selector .chzn-results li').entwine({
|
|
|
|
/**
|
|
|
|
* IE8 doesn't support programatic access to onchange event
|
|
|
|
* so react on click
|
|
|
|
*/
|
|
|
|
onclick:function(e){
|
|
|
|
if ($.browser.msie) {
|
|
|
|
e.preventDefault();
|
|
|
|
var index = this.index();
|
|
|
|
var targetStateName = this.closest('.preview-mode-selector').find('select option:eq('+index+')').val();
|
|
|
|
|
|
|
|
//var targetStateName = $(this).val();
|
|
|
|
$('.cms-preview').changeMode(targetStateName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-27 06:03:43 +01:00
|
|
|
/**
|
2012-11-29 05:41:48 +01:00
|
|
|
* Adjust the visibility of the preview-mode selector in the CMS part (hidden if preview is visible).
|
2012-11-27 06:03:43 +01:00
|
|
|
*/
|
|
|
|
$('.cms-preview.column-hidden').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
$('#preview-mode-dropdown-in-content').show();
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
$('#preview-mode-dropdown-in-content').hide();
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2012-11-29 05:41:48 +01:00
|
|
|
* Initialise the preview-mode selector in the CMS part (could be hidden if preview is visible).
|
2012-11-27 06:03:43 +01:00
|
|
|
*/
|
|
|
|
$('#preview-mode-dropdown-in-content').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
if ($('.cms-preview').is('.column-hidden')) {
|
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
2012-05-04 01:29:50 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* "Preview size" functions
|
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
$('.preview-size-selector').entwine({
|
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* Change the appearance of the size selector.
|
2012-11-29 05:41:48 +01:00
|
|
|
*/
|
2012-12-04 06:10:20 +01:00
|
|
|
changeVisibleSize: function(size) {
|
2012-11-29 05:41:48 +01:00
|
|
|
this.find('select')
|
|
|
|
.val(size)
|
|
|
|
.trigger('liszt:updated')
|
|
|
|
._addIcon();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.preview-size-selector select').entwine({
|
|
|
|
/**
|
|
|
|
* Trigger change in the preview size.
|
|
|
|
*/
|
|
|
|
onchange: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var targetSizeName = $(this).val();
|
|
|
|
$('.cms-preview').changeSize(targetSizeName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-04 06:10:20 +01:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
2012-12-03 22:16:58 +01:00
|
|
|
* "Chosen" plumbing.
|
2012-11-29 05:41:48 +01:00
|
|
|
* -------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2012-11-22 04:30:50 +01:00
|
|
|
/*
|
|
|
|
* Add a class to the chzn select trigger based on the currently
|
|
|
|
* selected option. Update as this changes
|
|
|
|
*/
|
2012-11-27 06:03:43 +01:00
|
|
|
$('.preview-selector select.preview-dropdown').entwine({
|
|
|
|
'onliszt:showing_dropdown': function() {
|
2012-11-29 05:41:48 +01:00
|
|
|
this.siblings().find('.chzn-drop').addClass('open')._alignRight();
|
2012-11-27 06:03:43 +01:00
|
|
|
},
|
2012-12-16 03:53:22 +01:00
|
|
|
|
2012-11-27 06:03:43 +01:00
|
|
|
'onliszt:hiding_dropdown': function() {
|
2012-11-29 05:41:48 +01:00
|
|
|
this.siblings().find('.chzn-drop').removeClass('open')._removeRightAlign();
|
2012-12-16 03:53:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger additional initial icon update when the control is fully loaded.
|
|
|
|
* Solves an IE8 timing issue.
|
|
|
|
*/
|
|
|
|
'onliszt:ready': function() {
|
|
|
|
this._super();
|
|
|
|
this._addIcon();
|
|
|
|
},
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
_addIcon: function(){
|
2012-11-22 04:30:50 +01:00
|
|
|
var selected = this.find(':selected');
|
|
|
|
var iconClass = selected.attr('data-icon');
|
|
|
|
|
|
|
|
var target = this.parent().find('.chzn-container a.chzn-single');
|
|
|
|
var oldIcon = target.attr('data-icon');
|
2012-12-16 03:53:22 +01:00
|
|
|
if(typeof oldIcon !== 'undefined'){
|
2012-11-22 04:30:50 +01:00
|
|
|
target.removeClass(oldIcon);
|
|
|
|
}
|
|
|
|
target.addClass(iconClass);
|
|
|
|
target.attr('data-icon', iconClass);
|
2012-11-22 02:14:11 +01:00
|
|
|
|
2012-12-16 03:53:22 +01:00
|
|
|
return this;
|
2012-11-22 04:30:50 +01:00
|
|
|
}
|
|
|
|
});
|
2012-11-22 02:14:11 +01:00
|
|
|
|
2012-11-27 06:03:43 +01:00
|
|
|
$('.preview-selector .chzn-drop').entwine({
|
2012-11-29 05:41:48 +01:00
|
|
|
_alignRight: function(){
|
2012-11-27 06:03:43 +01:00
|
|
|
var that = this;
|
|
|
|
$(this).hide();
|
|
|
|
/* Delay so styles applied after chosen applies css
|
|
|
|
(the line after we find out the dropdown is open)
|
|
|
|
*/
|
|
|
|
setTimeout(function(){
|
|
|
|
$(that).css({left:'auto', right:0});
|
|
|
|
$(that).show();
|
|
|
|
}, 100);
|
|
|
|
},
|
2012-11-29 05:41:48 +01:00
|
|
|
_removeRightAlign:function(){
|
2012-11-27 06:03:43 +01:00
|
|
|
$(this).css({right:'auto'});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-11-22 04:30:50 +01:00
|
|
|
/*
|
|
|
|
* Means of having extra styled data in chzn 'preview-selector' selects
|
|
|
|
* When chzn ul is ready, grab data-description from original select.
|
|
|
|
* If it exists, append to option and add description class to list item
|
|
|
|
*/
|
2012-11-27 06:03:43 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
Currently buggy (adds dexcription, then re-renders). This may need to
|
|
|
|
be done inside chosen. Chosen recommends to do this stuff in the css,
|
|
|
|
but that option is inaccessible and untranslatable
|
|
|
|
(https://github.com/harvesthq/chosen/issues/399)
|
|
|
|
|
2012-11-22 04:30:50 +01:00
|
|
|
$('.preview-selector .chzn-drop ul').entwine({
|
|
|
|
onmatch: function() {
|
2012-11-27 06:03:43 +01:00
|
|
|
this.extraData();
|
|
|
|
this._super();
|
2012-11-22 04:30:50 +01:00
|
|
|
},
|
2012-11-27 06:03:43 +01:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
extraData: function(){
|
2012-11-22 04:30:50 +01:00
|
|
|
var that = this;
|
2012-11-27 06:03:43 +01:00
|
|
|
var options = this.closest('.preview-selector').find('select option');
|
|
|
|
|
2012-11-22 04:30:50 +01:00
|
|
|
$.each(options, function(index, option){
|
2012-11-27 06:03:43 +01:00
|
|
|
var target = $(that).find("li:eq(" + index + ")");
|
|
|
|
var description = $(option).attr('data-description');
|
|
|
|
if(description != undefined && !$(target).hasClass('description')){
|
2012-11-22 04:30:50 +01:00
|
|
|
$(target).append('<span>' + description + '</span>');
|
2012-11-27 06:03:43 +01:00
|
|
|
$(target).addClass('description');
|
2012-11-22 04:30:50 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-11-27 06:03:43 +01:00
|
|
|
}); */
|
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
/**
|
|
|
|
* Recalculate the preview space to allow for horizontal scrollbar and the preview actions panel
|
|
|
|
*/
|
|
|
|
$('.preview-scroll').entwine({
|
2012-08-28 18:31:15 +02:00
|
|
|
/**
|
2012-11-29 05:41:48 +01:00
|
|
|
* Height of the preview actions panel
|
2012-08-28 18:31:15 +02:00
|
|
|
*/
|
2012-11-29 05:41:48 +01:00
|
|
|
ToolbarSize: 53,
|
2012-08-28 18:31:15 +02:00
|
|
|
|
2012-11-29 05:41:48 +01:00
|
|
|
_redraw: function() {
|
|
|
|
var toolbarSize = this.getToolbarSize();
|
2012-11-22 04:30:50 +01:00
|
|
|
|
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
var previewHeight = (this.height() - toolbarSize);
|
|
|
|
this.height(previewHeight);
|
|
|
|
},
|
2012-11-29 05:41:48 +01:00
|
|
|
|
2012-11-22 04:30:50 +01:00
|
|
|
onmatch: function() {
|
2012-11-29 05:41:48 +01:00
|
|
|
this._redraw();
|
2012-11-27 06:03:43 +01:00
|
|
|
this._super();
|
|
|
|
},
|
2012-11-29 05:41:48 +01:00
|
|
|
|
2012-11-27 06:03:43 +01:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
2012-11-22 04:30:50 +01:00
|
|
|
}
|
2012-11-29 05:41:48 +01:00
|
|
|
// TODO: Need to recalculate on resize of browser
|
2012-11-22 04:30:50 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-12-06 03:22:45 +01:00
|
|
|
/**
|
|
|
|
* Rotate preview to landscape
|
|
|
|
*/
|
|
|
|
$('.preview-device-outer').click(function() {
|
|
|
|
if(!$('.preview-device-outer').hasClass('rotate')) {
|
|
|
|
$('.preview-device-outer').addClass('rotate');
|
|
|
|
} else {
|
|
|
|
$('.preview-device-outer').removeClass('rotate');
|
|
|
|
}
|
|
|
|
});
|
2011-04-28 12:36:28 +02:00
|
|
|
});
|
2012-11-22 04:30:50 +01:00
|
|
|
}(jQuery));
|