Sha256: bfec8ee326e30a14ad1e76a834d3c4882e4608556191fae450ebf8437c9b439c
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
// Save -> Command S (need a form) jQuery.fn.saveWithShortcut = function() { var resetFormErrors = function(form) { jQuery('div.form-errors').remove(); jQuery('div.formError').remove(); jQuery('p.inline-errors').remove(); form.find('li.error').removeClass('error'); } var updateFromCodeMirror = function() { if (typeof CodeMirror == undefined) return; jQuery.each(CodeMirrorEditors, function() { this.el.val(this.editor.getCode()); }); } var save = function(form) { $.post(form.attr('action'), form.serializeArray(), function(data) { onSaveCallback(form, data) }, 'json'); }; var onSaveCallback = function(form, data) { resetFormErrors(form); if (data.alert != undefined) { $.growl('error', data.alert); for (var field in data.errors) { var error = data.errors[field]; var node = form.find('li:has(#' + data.model + '_' + field + ')'); node.addClass('error'); node.append("<p class='inline-errors'>" + error + "</p>"); } form.find('li.error input').eq(0).focus(); } else { $.growl('success', data.notice); } }; return this.each(function() { var form = jQuery(this); jQuery(document).bind('keypress.shortcut', function(event) { if (!(event.which == 115 && (event.ctrlKey || event.metaKey))) return true; updateFromCodeMirror(); save(form); event.preventDefault(); return false; }); }); };
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locomotive_cms-0.0.3.1 | public/javascripts/admin/plugins/shortcut.js |