diff --git a/CHANGES.rst b/CHANGES.rst index 8e5eb13a..f07f7496 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,9 @@ Bug fixes: which are using the check, are working on add forms in a context w/o "Modify portal content". [jensens] +- JavaScript formating according to style guides. + [thet] + 2.4.1 (2017-03-26) ------------------ diff --git a/plone/app/dexterity/browser/modeleditor.js b/plone/app/dexterity/browser/modeleditor.js index 9ddbf599..dcb22c79 100644 --- a/plone/app/dexterity/browser/modeleditor.js +++ b/plone/app/dexterity/browser/modeleditor.js @@ -1,124 +1,105 @@ -/*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true, - plusplus: true, bitwise: true, regexp: false, indent: 4 */ - -/*globals jQuery, form_modified_message, ajax_noresponse_message */ - -/* global message strings are from jsvariables.py in CMFPlone */ - -if(require === undefined){ - // plone 4 - require = function(reqs, torun){ - 'use strict'; - return torun(window.jQuery); - }; -} - -if (window.jQuery && define) { - define( 'jquery', [], function () { +/* globals require, define, form_modified_message, ajax_noresponse_message */ +// global message strings are from jsvariables.py in CMFPlone. +require(['jquery'], function($) { 'use strict'; - return window.jQuery; - } ); -} - - -require([ - 'jquery', - 'ace' -], function($) { - 'use strict'; - -var init = function(){ - if (!window.ace){ - // XXX hack... - // wait, try loading later - setTimeout(function() { - init(); - }, 200); - return; - } - - var editor = ace.edit("modelEditor"), - session = editor.getSession(), - myform = $("#saveform"), - doc_changed = false; - - // editor tuneup - editor.setTheme("ace/theme/monokai"); - session.setMode("ace/mode/xml"); - session.setTabSize(4); - session.setUseSoftTabs(true); - session.setUseWrapMode(true); - editor.setHighlightActiveLine(false); - // Make save keystroke trigger save-form submit - editor.commands.addCommand({ - name: "save", - bindKey: {win: "Ctrl-S", mac: "Command-S"}, - exec: function() { - myform.submit(); + var init = function() { + + if (!window.ace){ + // XXX hack... + // wait, try loading later + setTimeout(function() { + init(); + }, 200); + return; } - }); - // enable save submit button on change - session.on('change', function(e) { - $('#saveform :submit').removeAttr('disabled'); - doc_changed = true; - }); - - // unload protection - // See http://dev.w3.org/html5/spec-LC/history.html#unloading-documents - $(window).on("beforeunload", function(event) { - if (doc_changed) { - return form_modified_message; - } else { - event.returnValue = ""; - } - }); - - // form submit handler; ajax posts data - myform.on("submit", function(event) { - var action = myform.attr('action'); - - // prevent real submit - event.preventDefault(); - - // stuff the editor contents into the form - // for easy serialization - $('#savesource').val(editor.getValue()); + var editor = window.ace.edit('modelEditor'), + session = editor.getSession(), + myform = $('#saveform'), + doc_changed = false; + + // editor tuneup + editor.setTheme('ace/theme/monokai'); + session.setMode('ace/mode/xml'); + session.setTabSize(4); + session.setUseSoftTabs(true); + session.setUseWrapMode(true); + editor.setHighlightActiveLine(false); + // Make save keystroke trigger save-form submit + editor.commands.addCommand({ + name: 'save', + bindKey: { + win: 'Ctrl-S', + mac: 'Command-S' + }, + exec: function() { + myform.submit(); + } + }); - $.post(action, myform.serialize(), function (rez) { - if (rez.success) { - var messagespan = $("#messagespan"); + // enable save submit button on change + session.on('change', function (e) { + $('#saveform :submit').removeAttr('disabled'); + doc_changed = true; + }); - doc_changed = false; - // disable save button - $('#saveform :submit') - .attr('disabled', 'disabled') - .removeClass('submitting'); - messagespan.html(rez.message); - messagespan.show().fadeOut(1000); + // unload protection + // See http://dev.w3.org/html5/spec-LC/history.html#unloading-documents + $(window).on('beforeunload', function(event) { + if (doc_changed) { + return form_modified_message; } else { - alert(rez.message); + event.returnValue = ''; } - }, 'json') - .fail(function() { - alert(ajax_noresponse_message); }); - }); - - function setEditorSize () { - var wheight = $(window).height(); - $("#rules-editor").height(wheight); - $("#modelEditor").height(wheight-80); - } - $(window).resize(function() { - setEditorSize(); - }); - setEditorSize(); -}; + // form submit handler; ajax posts data + myform.on('submit', function(event) { + var action = myform.attr('action'); + + // prevent real submit + event.preventDefault(); + + // stuff the editor contents into the form + // for easy serialization + $('#savesource').val(editor.getValue()); + + $.post( + action, + myform.serialize(), + function(rez) { + if (rez.success) { + var messagespan = $('#messagespan'); + + doc_changed = false; + // disable save button + $('#saveform :submit') + .attr('disabled', 'disabled') + .removeClass('submitting'); + messagespan.html(rez.message); + messagespan.show().fadeOut(1000); + } else { + alert(rez.message); + } + }, + 'json' + ).fail(function() { + alert(ajax_noresponse_message); + }); + }); -$().ready(function() { - init(); -}); + function setEditorSize() { + var wheight = $(window).height(); + $('#rules-editor').height(wheight); + $('#modelEditor').height(wheight - 80); + } + $(window).resize(function() { + setEditorSize(); + }); + setEditorSize(); + }; + $().ready(function() { + init(); + }); }); diff --git a/plone/app/dexterity/browser/types_listing.js b/plone/app/dexterity/browser/types_listing.js index f1162d5d..2e4d55a4 100644 --- a/plone/app/dexterity/browser/types_listing.js +++ b/plone/app/dexterity/browser/types_listing.js @@ -1,44 +1,49 @@ -require([ - 'jquery', - 'mockup-patterns-modal' -], function($, Modal) { - "use strict"; +/* globals require, define */ +require(['jquery', 'mockup-patterns-modal'], function($, Modal) { + 'use strict'; + $('.action').css('display', 'inline'); // clone type form $('#crud-edit-form-buttons-clone').click(function(e) { - var selected = $('input[id$=-widgets-select-0]:checked'); - if (selected.length === 1) { - e.preventDefault(); - $(this).removeClass('submitting'); - var type_link = $('a', selected.closest('tr')); - var $el = $('<' + 'a href="' + type_link.attr('href') + '/@@clone"><' + '/a>').appendTo('body'); - var modal = new Modal($el, { - actionOptions: {displayInModal: false} - }); - $el.click(); - } + var selected = $('input[id$=-widgets-select-0]:checked'); + if (selected.length === 1) { + e.preventDefault(); + $(this).removeClass('submitting'); + var type_link = $('a', selected.closest('tr')); + var $el = $( + '<' + 'a href="' + type_link.attr('href') + '/@@clone"><' + '/a>' + ).appendTo('body'); + var modal = new Modal($el, { + actionOptions: { + displayInModal: false + } + }); + $el.click(); + } }); // delete type confirmation $('#crud-edit-form-buttons-delete').click(function(e) { - var items = 0, msg; + var items = 0, + msg; $('td.count').closest('tr').has('input:checked').each(function() { - items += parseInt($('td.count .int-field', this).html().trim()); + items += parseInt($('td.count .int-field', this).html().trim()); }); if (items) { - msg = 'WARNING: There are existing instances of these content types which will break.\n\nAre you sure you want to delete these types?'; + msg = + 'WARNING: There are existing instances of these content types which will break.\n\nAre you sure you want to delete these types?'; } else { - msg = 'Are you sure you want to delete these types?'; + msg = 'Are you sure you want to delete these types?'; } - if(!window.confirm(msg)) { + if (!window.confirm(msg)) { $(this).removeClass('submitting'); e.preventDefault(); } }); // set id from title - $('body').on('change', '#form-widgets-title', function () { + $('body').on('change', '#form-widgets-title', function() { var id = $.plone_schemaeditor_normalize_string($(this).val()); $('#form-widgets-id').val(id); });