mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-03 06:38:51 +02:00
NEW Storing page preview states (fixes #8092)
This commit is contained in:
parent
6a1fe05191
commit
0cb6b4630f
@ -68,8 +68,18 @@
|
|||||||
* API
|
* API
|
||||||
* Switch the preview to different state.
|
* Switch the preview to different state.
|
||||||
* stateName can be one of the "AllowedStates".
|
* stateName can be one of the "AllowedStates".
|
||||||
|
*
|
||||||
|
* @param {String}
|
||||||
|
* @param {Boolean} Set to FALSE to avoid persisting the state
|
||||||
*/
|
*/
|
||||||
changeState: function(stateName) {
|
changeState: function(stateName, save) {
|
||||||
|
var self = this, states = this._getNavigatorStates();
|
||||||
|
if(save !== false) {
|
||||||
|
$.each(states, function(index, state) {
|
||||||
|
self.saveState('state', stateName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.setCurrentStateName(stateName);
|
this.setCurrentStateName(stateName);
|
||||||
this._loadCurrentState();
|
this._loadCurrentState();
|
||||||
this.redraw();
|
this.redraw();
|
||||||
@ -82,7 +92,7 @@
|
|||||||
* Change the preview mode.
|
* Change the preview mode.
|
||||||
* modeName can be: split, content, preview.
|
* modeName can be: split, content, preview.
|
||||||
*/
|
*/
|
||||||
changeMode: function(modeName) {
|
changeMode: function(modeName, save) {
|
||||||
var container = $('.cms-container');
|
var container = $('.cms-container');
|
||||||
|
|
||||||
if (modeName === 'split') {
|
if (modeName === 'split') {
|
||||||
@ -93,6 +103,8 @@
|
|||||||
container.entwine('.ss').previewMode();
|
container.entwine('.ss').previewMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(save !== false) this.saveState('mode', modeName);
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -114,6 +126,8 @@
|
|||||||
this.find('.preview-device-inner')
|
this.find('.preview-device-inner')
|
||||||
.width(sizes[sizeName].width);
|
.width(sizes[sizeName].width);
|
||||||
|
|
||||||
|
this.saveState('size', sizeName);
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -149,6 +163,24 @@
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the preview options for this page.
|
||||||
|
*/
|
||||||
|
saveState : function(name, value) {
|
||||||
|
if(!window.localStorage) return;
|
||||||
|
|
||||||
|
window.localStorage.setItem('cms-preview-state-' + name, value);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load previously stored preferences
|
||||||
|
*/
|
||||||
|
loadState : function(name) {
|
||||||
|
if(!window.localStorage) return;
|
||||||
|
|
||||||
|
return window.localStorage.getItem('cms-preview-state-' + name);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable the area - it will not appear in the GUI.
|
* Disable the area - it will not appear in the GUI.
|
||||||
* Caveat: the preview will be automatically enabled when ".cms-previewable" class is detected.
|
* Caveat: the preview will be automatically enabled when ".cms-previewable" class is detected.
|
||||||
@ -156,7 +188,7 @@
|
|||||||
disablePreview: function() {
|
disablePreview: function() {
|
||||||
this._loadUrl('about:blank');
|
this._loadUrl('about:blank');
|
||||||
this._block();
|
this._block();
|
||||||
this.changeMode('content');
|
this.changeMode('content', false);
|
||||||
this.setIsPreviewEnabled(false);
|
this.setIsPreviewEnabled(false);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -173,7 +205,7 @@
|
|||||||
// We do not support the split mode in IE < 8.
|
// We do not support the split mode in IE < 8.
|
||||||
this.changeMode('content');
|
this.changeMode('content');
|
||||||
} else {
|
} else {
|
||||||
this.changeMode(this.getDefaultMode());
|
this.changeMode(this.getDefaultMode(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -235,6 +267,13 @@
|
|||||||
this._moveNavigator();
|
this._moveNavigator();
|
||||||
this._loadCurrentState();
|
this._loadCurrentState();
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
|
// now check the cookie to see if we have any preview settings that have been
|
||||||
|
// retained for this page from the last visit
|
||||||
|
var mode = this.loadState('mode');
|
||||||
|
if(mode) this.changeMode(mode);
|
||||||
|
var size = this.loadState('size');
|
||||||
|
if(size) this.changeSize(size);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user