From 01541487ca1d559dfe372c21145b14380a7ffd17 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 17 Dec 2011 16:06:56 +1300 Subject: [PATCH] MINOR: code formatting --- admin/javascript/LeftAndMain.Menu.js | 2 ++ admin/javascript/LeftAndMain.Preview.js | 32 +++++++++++-------- admin/javascript/LeftAndMain.js | 42 +++++++++++++++---------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/admin/javascript/LeftAndMain.Menu.js b/admin/javascript/LeftAndMain.Menu.js index 7a0dad213..0f1c8a085 100644 --- a/admin/javascript/LeftAndMain.Menu.js +++ b/admin/javascript/LeftAndMain.Menu.js @@ -94,6 +94,7 @@ select: function() { var parent = this.getMenuItem(); this.addClass('current').open(); + // Remove "current" class from all siblings and their children this.siblings().removeClass('current').close(); this.siblings().find('li').removeClass('current'); @@ -132,6 +133,7 @@ if(this.is(':internal')) url = $('base').attr('href') + url; var children = item.find('li'); + if(children.length) { children.first().find('a').click(); } else { diff --git a/admin/javascript/LeftAndMain.Preview.js b/admin/javascript/LeftAndMain.Preview.js index 91a03d87e..77ec85743 100644 --- a/admin/javascript/LeftAndMain.Preview.js +++ b/admin/javascript/LeftAndMain.Preview.js @@ -1,15 +1,17 @@ (function($) { - $.entwine('ss', function($){ /** - * Shows a previewable website state alongside its editable version in backend UI, typically a page. - * This allows CMS users to seamlessly switch between preview and edit mode in the same browser window. - * The preview panel is embedded in the layout of the backend UI, and loads its content via an iframe. + * Shows a previewable website state alongside its editable version in backend UI, + * typically a page. This allows CMS users to seamlessly switch between preview and + * edit mode in the same browser window. The preview panel is embedded in the layout + * of the backend UI, and loads its content via an iframe. * * The admin UI itself is collapsible, leaving most screen space to this panel. - * Relies on the server responses to indicate if a preview URL is available for the currently loaded - * admin interface. If no preview is available, the panel is "blocked" automatically. + * + * Relies on the server responses to indicate if a preview URL is available for the + * currently loaded admin interface. If no preview is available, the panel is "blocked" + * automatically. * * Internal links within the preview iframe trigger a refresh of the admin panel as well, * while all external links are disabled (via JavaScript). @@ -78,7 +80,7 @@ this._super(); }, - loadUrl: function(url) { + loadUrl: function(url) { this.find('iframe').attr('src', url); }, @@ -96,12 +98,15 @@ if(contentEl.is('.' + blockedClasses.join(',.'))) return; // Load this page in the admin interface if appropriate - var id = $(doc).find('meta[name=x-page-id]').attr('content'), - editLink = $(doc).find('meta[name=x-cms-edit-link]').attr('content'), - contentPanel = $('.cms-content'); + 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'); + if(id && contentPanel.find(':input[name=ID]').val() != id) { - // Ignore behaviour without history support (as we need ajax loading for the new form to load in the background) - if(window.History.enabled) $('.cms-container').loadPanel(editLink); + // Ignore behaviour without history support (as we need ajax loading + // for the new form to load in the background) + if(window.History.enabled) + $('.cms-container').loadPanel(editLink); } }, @@ -221,6 +226,7 @@ this.find('.active a').addClass('ui-state-highlight'); } }); + $('.cms-preview .cms-preview-states a').entwine({ onclick: function(e) { e.preventDefault(); @@ -234,8 +240,8 @@ $('.cms-preview-toggle-link').entwine({ onclick: function(e) { e.preventDefault(); - $('.cms-preview').toggle(); + $('.cms-preview').toggle(); } }); }); diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 37c301870..423b3691d 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -2,14 +2,11 @@ * File: LeftAndMain.js */ (function($) { - $.metadata.setType('html5'); - - // setup jquery.entwine - $.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE; - $.entwine('ss', function($){ - + // setup jquery.entwine + $.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE; + $.entwine('ss', function($) { /** * Position the loading spinner animation below the ss logo */ @@ -116,14 +113,20 @@ * - {Object} data Any additional data passed through to History.pushState() */ loadPanel: function(url, title, data) { - var data = data || {}, selector = data.selector || '.cms-content', contentEl = $(selector); + var data = data || {}; + var selector = data.selector || '.cms-content' + var contentEl = $(selector); + // Check change tracking (can't use events as we need a way to cancel the current state change) var trackedEls = contentEl.find(':data(changetracker)').add(contentEl.filter(':data(changetracker)')); + if(trackedEls.length) { var abort = false; + trackedEls.each(function() { if(!$(this).confirmUnsavedChanges()) abort = true; }); + if(abort) return; } @@ -168,7 +171,10 @@ if(this.getCurrentXHR()) this.getCurrentXHR().abort(); var selector = state.data.selector || '.cms-content', contentEl = $(selector); - this.trigger('beforestatechange', {state: state, element: contentEl}); + + this.trigger('beforestatechange', { + state: state, element: contentEl + }); contentEl.addClass('loading'); @@ -187,14 +193,17 @@ // Set loading state and store element state newContentEl.addClass('loading'); - var origStyle = contentEl.attr('style'), - layoutClasses = ['east', 'west', 'center', 'north', 'south'], - origLayoutClasses = $.grep( - contentEl.attr('class').split(' '), - function(val) { - return ($.inArray(val, layoutClasses) >= 0); - } - ); + var origStyle = contentEl.attr('style'); + var layoutClasses = ['east', 'west', 'center', 'north', 'south']; + var elemClasses = contentEl.attr('class'); + + var origLayoutClasses = $.grep( + elemClasses.split(' '), + function(val) { + return ($.inArray(val, layoutClasses) >= 0); + } + ); + newContentEl .removeClass(layoutClasses.join(' ')) .addClass(origLayoutClasses.join(' ')) @@ -215,6 +224,7 @@ contentEl.removeClass('loading'); } }); + this.setCurrentXHR(xhr); } });