Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API CHANGE Removed StageLink javascript class, replaced with 'concret…

…e' implementation

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92649 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit 773d7c9e18f7a0fb83732198d35d3b3d0af3ee1b 1 parent 990c64c
@chillu chillu authored
View
51 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);
View
45 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');
+}
View
4 templates/LeftAndMain.ss
@@ -45,8 +45,8 @@
<% if ShowSwitchView %>
<div class="blank"> <% _t('VIEWPAGEIN','Page view:') %> </div>
<span class="current" title="<% _t('EDITINCMS', 'Edit this page in the CMS') %>"><% _t('EDIT','Edit') %></span>
- <a id="viewStageSite" title="<% _t('VIEWINDRAFT', 'View the Page in the Draft Site') %>" href="home/?stage=Stage"><% _t('DRAFTS','Draft Site') %></a>
- <a id="viewLiveSite" title="<% _t('VIEWINPUBLISHED', 'View the Page in the Published Site') %>" href="home/?stage=Live"><% _t('PUBLIS','Published Site') %></a>
+ <a id="viewStageSite" title="<% _t('VIEWINDRAFT', 'View the Page in the Draft Site') %>" href="home/?stage=Stage" class="{params:'stage=Stage'}"><% _t('DRAFTS','Draft Site') %></a>
+ <a id="viewLiveSite" title="<% _t('VIEWINPUBLISHED', 'View the Page in the Published Site') %>" href="home/?stage=Live" class="{params:'stage=Live'}"><% _t('PUBLIS','Published Site') %></a>
<a style="display: none; margin-left: 20px;" id="viewArchivedSite" href="home/"><% _t('ARCHS','Archived Site') %></a>
<% end_if %>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.