This commit is contained in:
Didier Lafforgue 2012-03-23 01:29:12 +01:00
parent e9bf29f297
commit a8d57794de
5 changed files with 48 additions and 1 deletions

View File

@ -48,6 +48,11 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
enable_richtexteditor: ->
_.each @$('li.input.rte textarea.html'), (textarea) =>
settings = _.extend {}, @tinyMCE_settings(),
oninit: ((editor) =>
$.cmd 'S', (() =>
$(textarea).val(editor.getBody().innerHTML).trigger('change')
@$('form').trigger('submit')
), [], ignoreCase: true, document: editor.dom.doc),
onchange_callback: (editor) =>
$(textarea).val(editor.getBody().innerHTML).trigger('change')

View File

@ -13,6 +13,11 @@ class Locomotive.Views.EditableElements.ShortTextView extends Backbone.View
after_render: ->
settings = _.extend {}, @tinymce_settings(),
oninit: ((editor) =>
$.cmd 'S', (() =>
@model.set(content: editor.getBody().innerHTML)
$(@el).parents('form').trigger('submit')
), [], ignoreCase: true, document: editor.dom.doc),
onchange_callback: (editor) =>
@model.set(content: editor.getBody().innerHTML)

View File

@ -13,6 +13,9 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
# make inputs foldable (if specified)
@make_inputs_foldable()
# allow users to save with CTRL+S or CMD+s
@enable_save_with_keys_combination()
return @
save: (event) ->
@ -68,6 +71,9 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
else
content.slideUp 100, -> parent.addClass('folded')
enable_save_with_keys_combination: ->
$.cmd 'S', (() => @$('form').trigger('submit')), [], ignoreCase: true
after_inputs_fold: ->
# overide this method if necessary

View File

@ -0,0 +1,31 @@
/**
* Version 0.0.1
* Catch the CTRL+S keys combination and trigger a callback
* Didier Lafforgue
*/
$.cmd = function(key, callback, args, options) {
var keyCode = key.charCodeAt(0);
var altKeyCode = keyCode + (32 * (keyCode < 97 ? 1 : -1));
options = (options || { ignoreCase: false });
if (!options.ignoreCase) altKeyCode = null;
doc = options.document || window.document;
$(doc).keydown(function(e) {
var isCtrl = false;
if (!args) args = []; // IE barks when args is null
if (e.ctrlKey || e.metaKey) isCtrl = true;
if ((keyCode == e.which || altKeyCode == e.which) && isCtrl) {
e.preventDefault();
callback.apply(this, args);
return false;
}
});
};

View File

@ -28,6 +28,6 @@ $.fn.toggleMe = function(settings) {
});
};
return $(this).bind("click", toggle);
return $(this).bind('click', toggle);
};