2011-04-28 12:36:28 +02:00
|
|
|
(function($) {
|
2011-05-15 05:43:21 +02:00
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
$.entwine('ss', function($){
|
2011-05-15 05:43:21 +02:00
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-preview').entwine({
|
2011-04-28 12:36:28 +02:00
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
// Minimum width to keep the CMS operational
|
2011-05-02 01:43:51 +02:00
|
|
|
SharedWidth: null,
|
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
onmatch: function() {
|
|
|
|
var self = this, layoutContainer = this.parent();
|
|
|
|
// this.resizable({
|
|
|
|
// handles: 'w',
|
|
|
|
// stop: function(e, ui) {
|
|
|
|
// $('.cms-container').layout({resize: false});
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
2011-05-02 01:43:51 +02:00
|
|
|
// TODO Compute dynamically
|
|
|
|
this.setSharedWidth(500);
|
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
// Create layout and controls
|
2011-05-15 05:43:21 +02:00
|
|
|
this.prepend('<div class="cms-preview-toggle west"><a href="#">«</a></div>');
|
2011-04-28 12:36:28 +02:00
|
|
|
this.find('iframe').addClass('center');
|
|
|
|
this.layout({type: 'border'});
|
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
this.find('iframe').bind('load', function() {
|
|
|
|
self._fixIframeLinks();
|
|
|
|
self.loadCurrentPage();
|
|
|
|
});
|
2011-04-28 12:36:28 +02:00
|
|
|
self._fixIframeLinks();
|
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
// Limit to CMS forms for the moment
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-edit-form').bind('loadnewpage', function(e, ui) {
|
2011-04-28 12:36:28 +02:00
|
|
|
// var url = ui.xmlhttp.getResponseHeader('x-frontend-url');
|
|
|
|
var url = $(this).find(':input[name=StageURLSegment]').val();
|
2011-05-15 05:43:21 +02:00
|
|
|
if(url) self.loadUrl(url + '&cms-preview-disabled=1');
|
2011-04-28 12:36:28 +02:00
|
|
|
});
|
2011-06-09 03:49:52 +02:00
|
|
|
|
|
|
|
$('.cms-container').bind('afterstatechange', function(e) {
|
|
|
|
// var url = ui.xmlhttp.getResponseHeader('x-frontend-url');
|
|
|
|
var url = $('.cms-edit-form').find(':input[name=StageURLSegment]').val();
|
|
|
|
if(url) self.loadUrl(url + '&cms-preview-disabled=1');
|
|
|
|
});
|
2011-05-15 05:43:21 +02:00
|
|
|
|
|
|
|
if(this.hasClass('is-expanded')) this.expand();
|
|
|
|
else this.collapse();
|
2011-04-28 12:36:28 +02:00
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
loadUrl: function(url) {
|
|
|
|
this.find('iframe').attr('src', url);
|
|
|
|
},
|
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
loadCurrentPage: function() {
|
2011-07-05 14:34:31 +02:00
|
|
|
var doc = this.find('iframe')[0].contentDocument,
|
|
|
|
containerEl = this.getLayoutContainer(),
|
|
|
|
contentEl = containerEl.find('.cms-content');
|
2011-05-15 05:43:21 +02:00
|
|
|
|
|
|
|
// Only load if we're in the "edit page" view
|
2011-07-05 14:34:31 +02:00
|
|
|
if(!contentEl.hasClass('CMSMain') || contentEl.hasClass('CMSPagesController') || contentEl.hasClass('CMSSettingsController')) return;
|
2011-05-15 05:43:21 +02:00
|
|
|
|
|
|
|
// Load this page in the admin interface if appropriate
|
2011-05-20 01:38:36 +02:00
|
|
|
var id = $(doc).find('meta[name=x-page-id]').attr('content'), contentPanel = $('.cms-content');
|
2011-05-15 05:43:21 +02:00
|
|
|
// TODO Remove hardcoding
|
2011-06-09 03:49:52 +02:00
|
|
|
if(id && contentPanel.find(':input[name=ID]').val() != id) {
|
|
|
|
window.History.pushState({}, '', 'admin/page/edit/show/' + id);
|
|
|
|
}
|
2011-05-15 05:43:21 +02:00
|
|
|
},
|
|
|
|
|
2011-04-28 12:36:28 +02:00
|
|
|
_fixIframeLinks: function() {
|
|
|
|
var doc = this.find('iframe')[0].contentDocument;
|
|
|
|
|
|
|
|
// Block outside links from going anywhere
|
|
|
|
var links = doc.getElementsByTagName('A');
|
|
|
|
for (var i = 0; i < links.length; i++) {
|
|
|
|
var href = links[i].getAttribute('href');
|
|
|
|
if (href && href.match(/^http:\/\//)) {
|
|
|
|
links[i].setAttribute('href', 'javascript:false');
|
2011-05-15 05:43:21 +02:00
|
|
|
} else {
|
2011-06-09 03:49:52 +02:00
|
|
|
links[i].setAttribute('href', href + '?cms-preview-disabled=1');
|
2011-04-28 12:36:28 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-15 05:43:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
expand: function() {
|
|
|
|
var self = this, containerEl = this.getLayoutContainer(), contentEl = containerEl.find('.cms-content');
|
|
|
|
this.removeClass('east').addClass('center').removeClass('is-collapsed');
|
|
|
|
// this.css('overflow', 'auto');
|
|
|
|
contentEl.removeClass('center').hide();
|
|
|
|
this.find('iframe').show();
|
|
|
|
containerEl.find('.cms-menu').collapsePanel();
|
|
|
|
this.find('.cms-preview-toggle a').html('»');
|
|
|
|
containerEl.redraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
collapse: function() {
|
|
|
|
var self = this, containerEl = this.getLayoutContainer(), contentEl = containerEl.find('.cms-content');
|
|
|
|
this.addClass('east').removeClass('center').addClass('is-collapsed').width(10);
|
|
|
|
// this.css('overflow', 'hidden');
|
|
|
|
contentEl.addClass('center').show();
|
|
|
|
this.find('iframe').hide();
|
|
|
|
containerEl.find('.cms-menu').expandPanel();
|
|
|
|
this.find('.cms-preview-toggle a').html('«');
|
|
|
|
containerEl.redraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
getLayoutContainer: function() {
|
2011-07-05 14:34:31 +02:00
|
|
|
return this.parents('.cms-container');
|
2011-04-28 12:36:28 +02:00
|
|
|
},
|
|
|
|
|
2011-05-02 01:43:51 +02:00
|
|
|
toggle: function(bool) {
|
2011-05-15 05:43:21 +02:00
|
|
|
this[this.hasClass('is-collapsed') ? 'expand' : 'collapse']();
|
2011-04-28 12:36:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-preview.collapsed').entwine({
|
2011-04-28 12:36:28 +02:00
|
|
|
onmatch: function() {
|
|
|
|
this.find('a').text('<');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-preview.expanded').entwine({
|
2011-04-28 12:36:28 +02:00
|
|
|
onmatch: function() {
|
|
|
|
this.find('a').text('>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-preview .cms-preview-toggle').entwine({
|
2011-04-28 12:36:28 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.parents('.cms-preview').toggle();
|
|
|
|
}
|
|
|
|
});
|
2011-05-02 01:43:51 +02:00
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-switch-view a').entwine({
|
2011-05-02 01:43:51 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var preview = $('.cms-preview');
|
|
|
|
preview.toggle(true);
|
|
|
|
preview.loadUrl($(e.target).attr('href'));
|
|
|
|
}
|
|
|
|
});
|
2011-05-15 05:43:21 +02:00
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-menu li').entwine({
|
2011-05-15 05:43:21 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
// Prevent reloading of interface when opening the edit panel
|
|
|
|
if(this.hasClass('Menu-CMSMain')) {
|
|
|
|
var preview = $('.cms-preview');
|
|
|
|
preview.toggle(true);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-04-28 12:36:28 +02:00
|
|
|
});
|
|
|
|
}(jQuery));
|