diff --git a/core/misc/form.autosave.js b/core/misc/form.autosave.js index 2e0f4c3..df10f2a 100644 --- a/core/misc/form.autosave.js +++ b/core/misc/form.autosave.js @@ -7,7 +7,6 @@ */ Drupal.behaviors.formAutoSave = { attach: function (context, settings) { - var that = this; for (var formID in settings.formAutoSave) { if (settings.formAutoSave.hasOwnProperty(formID)) { var changed = settings.formAutoSave[formID]; @@ -17,55 +16,58 @@ Drupal.behaviors.formAutoSave = { // Attach garlic. .garlic({ expires: 86400 * 30, - conflictManager: { enabled: false }, - getPath: that.generateGarlicLocalStorageKey + conflictManager: { + enabled: false + }, + getPath: generateGarlicLocalStorageKey }); } } - }, - /** - * Override for garlic.js' localStorage key generation. - * - * garlic.js' getPath() implementation contains a lot of complexity, because - * they can't make any assumptions about the HTML of the form; because all - * forms in Drupal are generated by Form API, we can simplify a lot. - * We don't need to store the entire DOM node path, because each form item - * (as well as the form itself) is uniquely identified by its id attribute. - * We also don't need to look at the current URL thanks to - * drupalSettings.currentPath; without that, we could run into edge cases of - * e.g. www vs. no-www URLs of the same site. - * Finally, it takes a "last modification" identifier into account, which - * allows us to ignore localStorage data that doesn't apply anymore to the - * latest version of the object that the form allows the user to edit. - * - * @param {jQuery} $element - * A jQuery element of a form item. - */ - generateGarlicLocalStorageKey: function ($element) { - var key = ''; - var $form = $element.closest('form'); + } +}; - // garlic.js prefix. Allows garlic.js to do clean-up. - key += 'garlic:'; +/** + * Override for garlic.js' localStorage key generation. + * + * garlic.js' getPath() implementation contains a lot of complexity, because + * they can't make any assumptions about the HTML of the form; because all + * forms in Drupal are generated by Form API, we can simplify a lot. + * We don't need to store the entire DOM node path, because each form item + * (as well as the form itself) is uniquely identified by its id attribute. + * We also don't need to look at the current URL thanks to + * drupalSettings.currentPath; without that, we could run into edge cases of + * e.g. www vs. no-www URLs of the same site. + * Finally, it takes a "last modification" identifier into account, which + * allows us to ignore localStorage data that doesn't apply anymore to the + * latest version of the object that the form allows the user to edit. + * + * @param {jQuery} $element + * A jQuery element of a form item. + */ +function generateGarlicLocalStorageKey ($element) { + var key = ''; + var $form = $element.closest('form'); - // Drupal path at which this form lives. - key += drupalSettings.currentPath; + // garlic.js prefix. Allows garlic.js to do clean-up. + key += 'garlic:'; - // "last modification" identifier. - key += '~'; - key += $form.attr('data-localStorage-changed'); + // Drupal path at which this form lives. + key += drupalSettings.currentPath; - // Unique form identifier; CSS selector-like syntax. - key += '>'; - key += 'form#' + $form.attr('id'); - key += ' '; + // "last modification" identifier. + key += '~'; + key += $form.attr('data-localStorage-changed'); - // Unique form item identifier; CSS selector-like syntax. - key += $element.prop('tagName').toLowerCase(); - key += '#' + $element.attr('id'); + // Unique form identifier; CSS selector-like syntax. + key += '>'; + key += 'form#' + $form.attr('id'); + key += ' '; - return key; - } -}; + // Unique form item identifier; CSS selector-like syntax. + key += $element.prop('tagName').toLowerCase(); + key += '#' + $element.attr('id'); + + return key; +} })(jQuery, Drupal, drupalSettings);