diff --git a/CHANGELOG.md b/CHANGELOG.md index 577a1ec..fb9530e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.0.3 - 2018-05-23 +### Improved +- Child Me! quickmenu now closes immediately when clicking outside the container + +### Fixed +– Fixes an issue where the Child Me! JavaScript would get initialised multiple times + ## 1.0.2 - 2018-05-23 ### Improved - Entry Type names are now translated using the "site" translation category diff --git a/composer.json b/composer.json index 6836a84..edbd6ff 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mmikkel/child-me", "description": "Easily create child elements", "type": "craft-plugin", - "version": "1.0.2", + "version": "1.0.3", "keywords": [ "craft", "cms", diff --git a/src/resources/childme.js b/src/resources/childme.js index 4935ec5..3212a5a 100644 --- a/src/resources/childme.js +++ b/src/resources/childme.js @@ -28,7 +28,13 @@ Craft.ChildMePlugin = { + initialized: false, + init: function (data) { + if (this.initialized) { + return; + } + this.initialized = true; this.data = data || {}; this.addEventListeners(); }, @@ -139,36 +145,36 @@ onDragStop: function (tableSorter) { var $items = tableSorter.$items; - $items.find('[data-childmeadd]') - //.removeAttr('aria-hidden') - //.removeAttr('tabindex') - .show() + $items.find('[data-childmeadd]').show(); var maxLevels = tableSorter.maxLevels; if (!maxLevels) return false; var $hiddenItems = $items.filter(function () { return $(this).data('level') >= maxLevels; - }).find('[data-childmeadd]') - //.attr('aria-hidden', 'true') - //.attr('tabindex', '-1') - .hide(); + }).find('[data-childmeadd]').hide(); }, + onDocClick: function (e) { + if (!$(e.target).closest('[data-childmeadd]').length) { + this.closeActiveEntryTypeMenu(); + } + }, + addEventListeners: function () { Garnish.$doc .on('focus', '[data-childmeadd]', this.onChildMeButtonClick.bind(this)) - .on('blur', '[data-childmeadd]', (function (e) { - this.closeActiveEntryTypeMenu(); - }).bind(this)) - .on('click', '[data-childmeadd] a', this.onEntryTypeOptionSelect.bind(this)); + .on('blur', '[data-childmeadd]', this.closeActiveEntryTypeMenu.bind(this)) + .on('click', '[data-childmeadd] a', this.onEntryTypeOptionSelect.bind(this)) + .on('click', this.onDocClick.bind(this)); }, removeEventListeners: function () { Garnish.$doc .off('focus blur', '[data-childmeadd]') - .off('click', '[data-childmeadd] a'); + .off('click', '[data-childmeadd] a') + .off('click', this.onDocClick.bind(this)) } }