From 31dc45768adc8a7a8a145810dc6944da4f9ca171 Mon Sep 17 00:00:00 2001 From: William Dibbern Date: Wed, 21 Aug 2013 21:31:59 -0500 Subject: [PATCH] Fixed editor actions menu Closes #352 - Updated editor.scss to break out transition shorthand into its constituent properties so that bourbon appends the correct vendor prefixes. - Added full set of publish options to the statusMap. - Added setActiveStatus function to handle toggling the active action for the publish menu. - Cleaned up handleStatus and updatePost functions to match desired functionality of menu items toggling the selected action and the actual button on the split button invoking said action. --- core/client/assets/sass/layouts/editor.scss | 8 ++- core/client/views/editor.js | 75 ++++++++++++--------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/core/client/assets/sass/layouts/editor.scss b/core/client/assets/sass/layouts/editor.scss index 035847ab2e..ade591e00e 100644 --- a/core/client/assets/sass/layouts/editor.scss +++ b/core/client/assets/sass/layouts/editor.scss @@ -416,7 +416,13 @@ body.zen { @include icon($i-chevron-down) { margin-top:-5px; @include transform(rotate(540deg)); - @include transition(transform 0.6s ease); + /* Transition properties are split out due to a defect in + the vendor prefixing of transform transitions. + See: http://github.com/thoughtbot/bourbon/pull/86 + */ + @include transition-property(transform); + @include transition-duration(0.6s); + @include transition-timing-function(ease); }; } } diff --git a/core/client/views/editor.js b/core/client/views/editor.js index e8b07eeaaa..cf9c4c4dfe 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -64,9 +64,11 @@ }, statusMap: { - 'draft' : 'Save Draft', - 'published': 'Update Post', - 'scheduled' : 'Save Schedued Post' + 'draft': 'Save Draft', + 'published': 'Publish Now', + 'scheduled': 'Save Schedued Post', + 'queue': 'Add to Queue', + 'publish-on': 'Publish on...' }, initialize: function () { @@ -119,54 +121,59 @@ }); }, + setActiveStatus: function setActiveStatus(status, displayText) { + // Set the publish button's action + $('.js-post-button') + .attr('data-status', status) + .text(displayText); + + // Set the active action in the popup + $('.splitbutton-save .editor-options li') + .removeClass('active') + .filter(['li[data-set-status="', status, '"]'].join('')) + .addClass('active'); + }, + handleStatus: function (e) { - e.preventDefault(); + if (e) { e.preventDefault(); } var view = this, - status = $(e.currentTarget).attr('data-set-status'), - prevStatus = this.model.get('status'), - model = this.model; + status = $(e.currentTarget).attr('data-set-status'); + + view.setActiveStatus(status, this.statusMap[status]); + + // Dismiss the popup menu + $('body').find('.overlay:visible').fadeOut(); + }, + + updatePost: function (e) { + if (e) { e.preventDefault(); } + var view = this, + model = view.model, + $currentTarget = $(e.currentTarget), + status = $currentTarget.attr('data-status'), + prevStatus = model.get('status'); if (status === 'publish-on') { - Ghost.notifications.addItem({ + return Ghost.notifications.addItem({ type: 'alert', message: 'Scheduled publishing not supported yet.', status: 'passive' }); } if (status === 'queue') { - Ghost.notifications.addItem({ + return Ghost.notifications.addItem({ type: 'alert', message: 'Scheduled publishing not supported yet.', status: 'passive' }); } - this.savePost({ + view.savePost({ status: status }).then(function () { Ghost.notifications.addItem({ type: 'success', - message: 'Your post: ' + model.get('title') + ' has been ' + status, - status: 'passive' - }); - }, function (response) { - // Show a notification about the error - view.reportSaveError(response, model, status); - // Set the button text back to previous - model.set({ status: prevStatus }); - }); - }, - - updatePost: function (e) { - if (e) { - e.preventDefault(); - } - var view = this, - model = this.model; - this.savePost().then(function () { - Ghost.notifications.addItem({ - type: 'success', - message: 'Your post was saved as ' + model.get('status'), + message: ['Your post "', model.get('title'), '" has been ', status, '.'].join(''), status: 'passive' }); }, function (request) { @@ -177,6 +184,8 @@ message: message, status: 'passive' }); + + model.set({ status: prevStatus }); }); }, @@ -219,7 +228,9 @@ }, render: function () { - this.$('.js-post-button').text(this.statusMap[this.model.get('status')]); + var status = this.model.get('status'); + + this.setActiveStatus(status, this.statusMap[status]); } });