diff --git a/javascript/LeftAndMain.js b/javascript/LeftAndMain.js index 0ea4a2fe..db14983e 100644 --- a/javascript/LeftAndMain.js +++ b/javascript/LeftAndMain.js @@ -376,6 +376,57 @@ } } }}); + + /** + * @class Links for viewing the currently loaded page + * in different modes: 'live', 'stage' or 'archived'. + * Automatically updates on loading a new page. + * @name ss.switchViewLinks + * @requires jquery.metadata + */ + $('#switchView a').concrete('ss', function($){ + + return/** @lends ss.switchViewLinks */{ + + /** + * @type DOMElement + */ + Form: null, + + onmatch: function() { + var self = this; + this.setForm($('#Form_EditForm')); + + jQuery('#Form_EditForm').bind('loadnewpage delete', function(e) {self.refresh();}); + self.refresh(); + }, + + /** + * Parse new links based on the underlying form URLSegment, + * preserving the ?stage URL parameters if necessary. + */ + refresh: function() { + // TODO Compatible with nested urls? + var urlSegment = this.Form().find(':input[name=URLSegment]').val(); + if(urlSegment) { + var locale = this.Form().find(':input[name=Locale]').val(); + var url = urlSegment; + if(this.metadata().params) url += '?' + this.metadata().params; + if(locale) url += ((url.indexOf('?') > 0) ? '&' : '?') + "locale=" + locale; + this.attr('href', url); + } + + // hide fields if no URLSegment is present + this.toggle((urlSegment)); + }, + + onclick: function(e) { + // Open in popup + window.open($(e.target).attr('href')); + return false; + } + } + }); })(jQuery); diff --git a/javascript/LeftAndMain_right.js b/javascript/LeftAndMain_right.js index b5f64eb7..538e086e 100755 --- a/javascript/LeftAndMain_right.js +++ b/javascript/LeftAndMain_right.js @@ -377,47 +377,4 @@ function autoSave(confirmation, callAfter) { } else { if(__callAfter) __callAfter(); } -} - - -StageLink = Class.create(); -StageLink.prototype = { - initialize: function(getVars, urlField) { - this.getVars = getVars; - this.urlField = urlField; - - var boundNewPage = this.newPage.bind(this); - - $('Form_EditForm').observeMethod('PageLoaded', boundNewPage); - $('Form_EditForm').observeMethod('PageSaved', boundNewPage); - $('Form_EditForm').observeMethod('PagePublished', boundNewPage); - $('Form_EditForm').observeMethod('PageUnpublished', boundNewPage); - - this.newPage(); - }, - newPage : function() { - var linkField = $('Form_EditForm').elements[this.urlField]; - var linkVal = linkField ? linkField.value : null; - if(linkVal) { - if(this.id != 'viewArchivedSite') this.style.display = ''; - this.href = linkVal + this.getVars; - } else { - if(this.id != 'viewArchivedSite') this.style.display = 'none'; - } - if($('Form_EditForm_Locale')) { - this.href += "&locale=" + $('Form_EditForm_Locale').value; - } - }, - onclick : function() { - var w = window.open(this.href); - w.focus(); - return false; - }, - baseURL : function() { - return document.getElementsByTagName('base')[0].href; - } -} - -StageLink.applyTo('#viewStageSite', '?stage=Stage', 'StageURLSegment'); -StageLink.applyTo('#viewLiveSite', '?stage=Live', 'LiveURLSegment'); -StageLink.applyTo('#viewArchivedSite', '', 'URLSegment'); \ No newline at end of file +} \ No newline at end of file diff --git a/templates/LeftAndMain.ss b/templates/LeftAndMain.ss index 7aba7e57..12075e97 100644 --- a/templates/LeftAndMain.ss +++ b/templates/LeftAndMain.ss @@ -45,8 +45,8 @@ <% if ShowSwitchView %>