mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Improved modals styling and code formatting
Solves: * max-height 120px less than height of viewport * fade-in a dark overlay as well as blur * animation speeds/transitions should be smoother * modal sizing fucks up when viewport is resized Also improves Modal code compliance to Ghost Backbone coding patterns
This commit is contained in:
parent
28937f9426
commit
6bd3333d6d
3 changed files with 46 additions and 38 deletions
|
@ -902,6 +902,7 @@ nav {
|
|||
left: 0;
|
||||
right: 0;
|
||||
z-index: 999;
|
||||
@include transition(background 300ms ease);
|
||||
|
||||
&.dark {
|
||||
background: rgba(0,0,0,0.4);
|
||||
|
@ -920,8 +921,14 @@ nav {
|
|||
}
|
||||
|
||||
body.blur > *:not(#modal-container) {
|
||||
@include transition(all 300ms ease);
|
||||
-webkit-filter: blur(2px);
|
||||
filter: blur(2px); // Not used yet
|
||||
-moz-filter: blur(2px);
|
||||
-ms-filter: blur(2px);
|
||||
-o-filter: blur(2px);
|
||||
filter: blur(2px);
|
||||
@include transform(translateZ(0));
|
||||
|
||||
}
|
||||
|
||||
%modal, .modal {
|
||||
|
|
|
@ -166,99 +166,100 @@
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* This is the view to generate the markup for the individual
|
||||
* modal. Will be included into #modals.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Types can be
|
||||
* - (empty)
|
||||
*
|
||||
*/
|
||||
// ## Modals
|
||||
Ghost.Views.Modal = Ghost.View.extend({
|
||||
el: '#modal-container',
|
||||
templateName: 'modal',
|
||||
className: 'js-bb-modal',
|
||||
// Render and manages modal dismissal
|
||||
initialize: function () {
|
||||
this.render();
|
||||
var self = this;
|
||||
if (!this.model.options.confirm) {
|
||||
shortcut.add("ESC", function () {
|
||||
self.removeItem();
|
||||
self.removeElement();
|
||||
});
|
||||
$(document).on('click', '.modal-background', function (e) {
|
||||
self.removeItem(e);
|
||||
self.removeElement(e);
|
||||
});
|
||||
} else {
|
||||
// Initiate functions for buttons here so models don't get tied up.
|
||||
this.acceptModal = function () {
|
||||
this.model.options.confirm.accept.func();
|
||||
self.removeItem();
|
||||
self.removeElement();
|
||||
};
|
||||
this.rejectModal = function () {
|
||||
this.model.options.confirm.reject.func();
|
||||
self.removeItem();
|
||||
self.removeElement();
|
||||
};
|
||||
shortcut.remove("ESC");
|
||||
$(document).off('click', '.modal-background');
|
||||
}
|
||||
},
|
||||
template: function (data) {
|
||||
return JST[this.templateName](data);
|
||||
templateData: function () {
|
||||
return this.model;
|
||||
},
|
||||
events: {
|
||||
'click .close': 'removeItem',
|
||||
'click .close': 'removeElement',
|
||||
'click .js-button-accept': 'acceptModal',
|
||||
'click .js-button-reject': 'rejectModal'
|
||||
},
|
||||
render: function () {
|
||||
this.$el.html(this.template(this.model));
|
||||
afterRender: function () {
|
||||
this.$(".modal-content").html(this.addSubview(new Ghost.Views.Modal.ContentView({model: this.model})).render().el);
|
||||
this.$el.children(".js-modal").center();
|
||||
this.$el.addClass("active");
|
||||
this.$el.children(".js-modal").center().css("max-height", $(window).height() - 120); // same as resize(), but the debounce causes init lag
|
||||
this.$el.addClass("active dark");
|
||||
|
||||
if (document.body.style.webkitFilter !== undefined) { // Detect webkit filters
|
||||
$("body").addClass("blur");
|
||||
} else {
|
||||
this.$el.addClass("dark");
|
||||
}
|
||||
return this;
|
||||
|
||||
var self = this;
|
||||
$(window).on('resize', self.resize);
|
||||
|
||||
},
|
||||
// #### resize
|
||||
// Center and resize modal based on window height
|
||||
resize: _.debounce(function () {
|
||||
$(".js-modal").center().css("max-height", $(window).height() - 120);
|
||||
}, 50),
|
||||
// #### remove
|
||||
// Removes Backbone attachments from modals
|
||||
remove: function () {
|
||||
this.undelegateEvents();
|
||||
this.$el.empty();
|
||||
this.stopListening();
|
||||
return this;
|
||||
},
|
||||
removeItem: function (e) {
|
||||
// #### removeElement
|
||||
// Visually removes the modal from the user interface
|
||||
removeElement: function (e) {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this.$el.removeClass('dark');
|
||||
$('.js-modal').fadeOut(300, function () {
|
||||
$(this).remove();
|
||||
$("#modal-container").removeClass('active dark');
|
||||
if (document.body.style.filter !== undefined) {
|
||||
$("body").removeClass("blur");
|
||||
}
|
||||
self.remove();
|
||||
self.$el.removeClass('active');
|
||||
});
|
||||
this.remove();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Modal Content
|
||||
* @type {*}
|
||||
*/
|
||||
// ## Modal Content
|
||||
Ghost.Views.Modal.ContentView = Ghost.View.extend({
|
||||
|
||||
template: function (data) {
|
||||
return JST['modals/' + this.model.content.template](data);
|
||||
},
|
||||
|
||||
render: function () {
|
||||
this.$el.html(this.template(this.model));
|
||||
return this;
|
||||
templateData: function () {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -23,14 +23,14 @@
|
|||
{'key': 'Ctrl+Shift+L', 'style': 'link'},
|
||||
{'key': 'Ctrl+Shift+I', 'style': 'image'},
|
||||
{'key': 'Ctrl+Q', 'style': 'blockquote'},
|
||||
{'key': 'Ctrl+Shift+1', 'style': 'currentdate'},
|
||||
{'key': 'Ctrl+Shift+1', 'style': 'currentDate'},
|
||||
{'key': 'Ctrl+U', 'style': 'uppercase'},
|
||||
{'key': 'Ctrl+Shift+U', 'style': 'lowercase'},
|
||||
{'key': 'Ctrl+Alt+Shift+U', 'style': 'titlecase'},
|
||||
{'key': 'Ctrl+Alt+W', 'style': 'selectword'},
|
||||
{'key': 'Ctrl+L', 'style': 'list'},
|
||||
{'key': 'Ctrl+Alt+C', 'style': 'copyHTML'},
|
||||
{'key': 'CMD+Alt+C', 'style': 'copyHTML'}
|
||||
{'key': 'Meta+Alt+C', 'style': 'copyHTML'}
|
||||
];
|
||||
|
||||
// The publish bar associated with a post, which has the TagWidget and
|
||||
|
|
Loading…
Add table
Reference in a new issue