diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmystreet/admin.js | 128 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 48 | ||||
-rw-r--r-- | web/cobrands/sass/_admin.scss | 134 | ||||
-rw-r--r-- | web/cobrands/sass/_base.scss | 3 | ||||
-rwxr-xr-x | web/vendor/html5sortable.min.js | 2 |
6 files changed, 212 insertions, 105 deletions
diff --git a/web/cobrands/fixmystreet/admin.js b/web/cobrands/fixmystreet/admin.js index b598f52dd..d3df27f33 100644 --- a/web/cobrands/fixmystreet/admin.js +++ b/web/cobrands/fixmystreet/admin.js @@ -115,39 +115,7 @@ $(function(){ $(".js-extra-fields-ui").removeClass("hidden-js"); }); - // If type is changed to 'singlevaluelist' show the options list - $(".js-metadata-items").on("change", ".js-metadata-item-type", function() { - var $this = $(this); - var shown = $this.val() === 'singlevaluelist'; - var $list = $this.closest(".js-metadata-item").find('.js-metadata-options'); - $list.toggle(shown); - }); - // call immediately to perform page setup - $(".js-metadata-item-type").change(); - - // Options can be removed by clicking the 'remove' button - $(".js-metadata-items").on("click", ".js-metadata-option-remove", function(e) { - e.preventDefault(); - var $this = $(this); - var $item = $this.closest(".js-metadata-item"); - $this.closest('li').remove(); - return true; - }); - - // New options can be added by clicking the appropriate button - $(".js-metadata-items").on("click", ".js-metadata-option-add", function(e) { - e.preventDefault(); - var $ul = $(this).closest("ul"); - var $template_option = $ul.find(".js-metadata-option-template"); - var $new_option = $template_option.clone(); - $new_option.removeClass("hidden-js js-metadata-option-template"); - $new_option.show(); - $new_option.insertBefore($template_option); - $new_option.find("input").first().focus(); - renumber_metadata_options($(this).closest(".js-metadata-item")); - return true; - }); - + // For "parent categories" $(".js-group-item-add").on("click", function(e) { e.preventDefault(); var $template_item = $(".js-group-item-template"); @@ -158,49 +126,67 @@ $(function(){ return true; }); - // Fields can be added/removed - $(".js-metadata-item-add").on("click", function(e) { - e.preventDefault(); - var $template_item = $(".js-metadata-items .js-metadata-item-template"); - var $new_item = $template_item.clone(); - $new_item.data('index', Math.max.apply( - null, - $(".js-metadata-item").map(function() { - return $(this).data('index'); - }).get() - ) + 1); - renumber_metadata_fields($new_item); - $new_item.removeClass("hidden-js js-metadata-item-template"); - $new_item.show(); - $new_item.insertBefore($template_item); - $new_item.find("input").first().focus(); - return true; - }); - $(".js-metadata-items").on("click", ".js-metadata-item-remove", function(e) { - e.preventDefault(); - $(this).closest(".js-metadata-item").remove(); - return true; + $('.js-metadata-item-add').on('click', function(){ + var $container = $(this).prevAll('.js-metadata-items'); + var i = $container.children().length + 1; + var html = $('#js-template-extra-metadata-item').html().replace(/9999/g, i); + $container.append(html); + fixmystreet.set_up.toggle_visibility(); + reloadSortableMetadataItems(); }); - function renumber_metadata_fields($item) { - var item_index = $item.data("index"); - $item.find("[data-field-name]").each(function(i) { - var $input = $(this); - var prefix = "metadata["+item_index+"]."; - var name = prefix + $input.data("fieldName"); - $input.attr("name", name); + $('.js-metadata-items').on('click', '.js-metadata-item-remove', function(){ + $(this).parents('.js-metadata-item').remove(); + }).on('change', '.js-metadata-item', updateMetadataItemTitle); + + sortable('.js-metadata-items', { + forcePlaceholderSize: true, + handle: '.js-metadata-item-header-grab', + placeholder: '<div class="extra-metadata-item-placeholder"></div>' + })[0].addEventListener('sortupdate', function(e) { + $(e.detail.destination.items).each(function(i){ + $(this).find('.js-sort-order input').val(i); }); + }); + $('.js-sort-order').addClass('hidden-js'); + + function reloadSortableMetadataItems(){ + sortable('.js-metadata-items', 'reload'); + $('.js-sort-order').addClass('hidden-js'); } - function renumber_metadata_options($item) { - var item_index = $item.data("index"); - $item.find(".js-metadata-option").each(function(i) { - var $li = $(this); - var prefix = "metadata["+item_index+"].values["+i+"]"; - $li.find(".js-metadata-option-key").attr("name", prefix+".key"); - $li.find(".js-metadata-option-name").attr("name", prefix+".name"); - $li.find(".js-metadata-option-disable").attr("name", prefix+".disable"); - }); + $('.js-metadata-item').each(updateMetadataItemTitle); + + function updateMetadataItemTitle(){ + var $title = $(this).find('.js-metadata-item-header-title'); + var defaultTitle = $title.attr('data-default'); + var html = '<strong>' + defaultTitle + '</strong>'; + var code = $(this).find('input[name$=".code"]').val(); + if ( code ) { + html = '<strong>' + code + '</strong>'; + var behaviour = $(this).find('input[name$=".behaviour"]:checked'); + if ( behaviour.length ) { + html += ' / ' + behaviour.val(); + } + var description = $(this).find('textarea[name$=".description"]').val(); + if ( description && (behaviour.val() == 'question' || behaviour.val() == 'notice') ) { + html += ' / ' + description.substring(0, 50); + } + } + $title.html(html); } + + $('.js-metadata-items').on('click', '.js-metadata-option-add', function(){ + var $container = $(this).prevAll('.js-metadata-options'); + var i = $(this).parents('.js-metadata-item').attr('data-i'); + var j = $container.children().length + 1; + var html = $('#js-template-extra-metadata-option').html().replace(/9999/g, i).replace(/8888/g, j); + $container.append(html); + fixmystreet.set_up.toggle_visibility(); + }); + + $('.js-metadata-items').on('click', '.js-metadata-option-remove', function(){ + $(this).parents('.js-metadata-option').remove(); + }); }); diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 0b2205076..a0cf2e29d 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -1030,7 +1030,7 @@ fixmystreet.message_controller = (function() { function show_responsibility_error(id, asset_item, asset_type) { $("#js-roads-responsibility").removeClass("hidden"); $("#js-roads-responsibility .js-responsibility-message").addClass("hidden"); - var asset_strings = $('.js-roads-asset'); + var asset_strings = $(id).find('.js-roads-asset'); if (asset_item) { asset_strings.html('a <b class="asset-' + asset_type + '">' + asset_item + '</b>'); } else { diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index c7749c729..6b88bc3d3 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -992,14 +992,48 @@ $.extend(fixmystreet.set_up, { }, toggle_visibility: function() { - $('input[type="checkbox"][data-toggle-visibility]').each(function(){ - var input = this; - var $target = $( $(this).attr('data-toggle-visibility') ); - var update = function() { - $target.toggleClass('hidden-js', ! input.checked ); + $('[data-toggle-visibility]').each(function(){ + var $target = $( $(this).attr('data-toggle-visibility') ); + if ( $(this).is(':checkbox') ){ + var input = this; + var update = function() { + $target.toggleClass('hidden-js', ! input.checked ); + }; + $(this).off('change.togglevisibility').on('change.togglevisibility', update); + update(); + } else { + $(this).off('click.togglevisibility').on('click.togglevisibility', function(){ + $target.toggleClass('hidden-js'); + }); + } + }); + + $('input[type="radio"][data-show], input[type="radio"][data-hide]').each(function(){ + var update = function(){ + if ( this.checked ) { + var $showTarget = $( $(this).attr('data-show') ); + var $hideTarget = $( $(this).attr('data-hide') ); + $showTarget.removeClass('hidden-js'); + $hideTarget.addClass('hidden-js'); + } + }; + // off/on to make sure event handler is only bound once. + $(this).off('change.togglevisibility').on('change.togglevisibility', update); + update.call(this); // pass DOM element as `this` + }); + + $('option[data-show], option[data-hide]').each(function(){ + var $select = $(this).parent(); + var update = function(){ + var $option = $(this).find('option:selected'); + var $showTarget = $( $option.attr('data-show') ); + var $hideTarget = $( $option.attr('data-hide') ); + $showTarget.removeClass('hidden-js'); + $hideTarget.addClass('hidden-js'); }; - $(input).on('change', update); - update(); + // off/on to make sure event handler is only bound once. + $select.off('change.togglevisibility').on('change.togglevisibility', update); + update.call($select[0]); // pass DOM element as `this` }); }, diff --git a/web/cobrands/sass/_admin.scss b/web/cobrands/sass/_admin.scss index d36c8ced0..3b47ea9aa 100644 --- a/web/cobrands/sass/_admin.scss +++ b/web/cobrands/sass/_admin.scss @@ -173,41 +173,125 @@ $button_bg_col: #a1a1a1; // also search bar (tables) } } -.js-metadata-items { - margin: 0; +.extra-metadata-item, +.extra-metadata-option { + border: 1px solid $table_border_color; + margin: 1em 0; + border-radius: 4px; + overflow: hidden; - li { - list-style: none; - position: relative; + // Make it look more "grabbable" if javascript available. + html.js & { + box-shadow: 0 0.1em 0.2em rgba(0, 0, 0, 0.1); } +} - .js-metadata-item:nth-child(odd) { - background-color: #eee; - } +.extra-metadata-item-placeholder { + border: 1px solid #fff; + margin: 1em 0; +} - .js-metadata-options { - li { - list-style: none; +.extra-metadata-item__header { + @include flex-container(); + line-height: 1; + background: #f3f3f3; - label, input[type=text] { - display: inline-block; - margin: 0; - padding: 0.25em; - } + & > * { + padding: 1em; + border: none; + background: transparent; + text-align: inherit; + font-family: inherit; + font-size: 1em; + -webkit-appearance: none; + } - &:nth-child(even) { - background-color: #ddd; - } - &:nth-child(odd) { - background-color: #ccc; - } + .extra-metadata-item__header__remove { + color: #DB0030; + + &:hover, + &:focus { + background: #ffe1e1; + color: #AD0026; } } +} + +.extra-metadata-item__header__grab { + cursor: grab; - .js-metadata-item-remove { + // Overlap padding-left of the title element + margin-#{$right}: -1em; + position: relative; + z-index: 1; + width: 1em; + + &:before { + content: ""; + display: block; + width: 1em; + height: 2px; + background: #000; + box-shadow: 0 -4px 0 0 #000, 0 4px 0 0 #000; position: absolute; - top: 0.25em; - #{$right}: 0.25em; + top: 50%; + left: 1em; + margin-top: -1px; + } + + .sortable-dragging & { + cursor: grabbing; + } +} + +.extra-metadata-item__header__title { + @include flex(1 0 auto); + cursor: pointer; +} + +.extra-metadata-item__body { + padding: 0 1em 1em 1em; // 0em to compensate for first label margin-top + border-top: 1px solid $table_border_color; +} + +.extra-metadata-option { + margin: 0 0 1em 0; + padding: 0 1em; + + .row { + @include flex-container(); + margin: 0 -1em; + } + + .col { + @include box-sizing(border-box); + @include flex(1 0 auto); + padding: 0 1em; + width: 50%; + } + + .form-control { + margin: 0; + } + + button { + border: none; + background: transparent; + text-align: inherit; + font-family: inherit; + font-size: 1em; + -webkit-appearance: none; + color: #DB0030; + float: right; + padding: 0.5em; + margin-top: 1em; + border-radius: 4px; + + &:hover, + &:focus { + background: #ffe1e1; + color: #AD0026; + } } } diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index 63ff19524..8e460f102 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -278,7 +278,8 @@ textarea { } label, -legend { +legend, +.label { display: block; margin-top: 1.25em; margin-bottom: 0.5em; diff --git a/web/vendor/html5sortable.min.js b/web/vendor/html5sortable.min.js new file mode 100755 index 000000000..3a7241283 --- /dev/null +++ b/web/vendor/html5sortable.min.js @@ -0,0 +1,2 @@ +var sortable=function(){"use strict";function c(e,t,n){if(void 0===n)return e&&e.h5s&&e.h5s.data&&e.h5s.data[t];e.h5s=e.h5s||{},e.h5s.data=e.h5s.data||{},e.h5s.data[t]=n}var d=function(e,t){if(!(e instanceof NodeList||e instanceof HTMLCollection||e instanceof Array))throw new Error("You must provide a nodeList/HTMLCollection/Array of elements to be filtered.");return"string"!=typeof t?Array.from(e):Array.from(e).filter(function(e){return 1===e.nodeType&&e.matches(t)})},u=new Map,t=function(){function e(){this._config=new Map,this._placeholder=void 0,this._data=new Map}return Object.defineProperty(e.prototype,"config",{get:function(){var n={};return this._config.forEach(function(e,t){n[t]=e}),n},set:function(e){if("object"!=typeof e)throw new Error("You must provide a valid configuration object to the config setter.");var t=Object.assign({},e);this._config=new Map(Object.entries(t))},enumerable:!0,configurable:!0}),e.prototype.setConfig=function(e,t){if(!this._config.has(e))throw new Error("Trying to set invalid configuration item: "+e);this._config.set(e,t)},e.prototype.getConfig=function(e){if(!this._config.has(e))throw new Error("Invalid configuration item requested: "+e);return this._config.get(e)},Object.defineProperty(e.prototype,"placeholder",{get:function(){return this._placeholder},set:function(e){if(!(e instanceof HTMLElement)&&null!==e)throw new Error("A placeholder must be an html element or null.");this._placeholder=e},enumerable:!0,configurable:!0}),e.prototype.setData=function(e,t){if("string"!=typeof e)throw new Error("The key must be a string.");this._data.set(e,t)},e.prototype.getData=function(e){if("string"!=typeof e)throw new Error("The key must be a string.");return this._data.get(e)},e.prototype.deleteData=function(e){if("string"!=typeof e)throw new Error("The key must be a string.");return this._data.delete(e)},e}(),p=function(e){if(!(e instanceof HTMLElement))throw new Error("Please provide a sortable to the store function.");return u.has(e)||u.set(e,new t),u.get(e)};function a(e,t,n){if(e instanceof Array)for(var r=0;r<e.length;++r)a(e[r],t,n);else e.addEventListener(t,n),p(e).setData("event"+t,n)}function i(e,t){if(e instanceof Array)for(var n=0;n<e.length;++n)i(e[n],t);else e.removeEventListener(t,p(e).getData("event"+t)),p(e).deleteData("event"+t)}function l(e,t,n){if(e instanceof Array)for(var r=0;r<e.length;++r)l(e[r],t,n);else e.setAttribute(t,n)}function r(e,t){if(e instanceof Array)for(var n=0;n<e.length;++n)r(e[n],t);else e.removeAttribute(t)}var m=function(e){if(!e.parentElement||0===e.getClientRects().length)throw new Error("target element must be part of the dom");var t=e.getClientRects()[0];return{left:t.left+window.pageXOffset,right:t.right+window.pageXOffset,top:t.top+window.pageYOffset,bottom:t.bottom+window.pageYOffset}},h=function(n,r){var o;return void 0===r&&(r=0),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];clearTimeout(o),o=setTimeout(function(){n.apply(void 0,e)},r)}},g=function(e,t){if(!(e instanceof HTMLElement&&(t instanceof NodeList||t instanceof HTMLCollection||t instanceof Array)))throw new Error("You must provide an element and a list of elements.");return Array.from(t).indexOf(e)},v=function(e){if(!(e instanceof HTMLElement))throw new Error("Element is not a node element.");return null!==e.parentNode},n=function(e,t,n){if(!(e instanceof HTMLElement&&e.parentElement instanceof HTMLElement))throw new Error("target and element must be a node");e.parentElement.insertBefore(t,"before"===n?e:e.nextElementSibling)},y=function(e,t){return n(e,t,"before")},E=function(e,t){return n(e,t,"after")},o=function(t,n,e){if(void 0===n&&(n=function(e,t){return e}),void 0===e&&(e=function(e){return e}),!(t instanceof HTMLElement)||!0==!t.isSortable)throw new Error("You need to provide a sortableContainer to be serialized.");if("function"!=typeof n||"function"!=typeof e)throw new Error("You need to provide a valid serializer for items and the container.");var r=c(t,"opts").items,o=d(t.children,r),i=o.map(function(e){return{parent:t,node:e,html:e.outerHTML,index:g(e,o)}});return{container:e({node:t,itemCount:i.length}),items:i.map(function(e){return n(e,t)})}},w=function(e,t,n){var r;if(void 0===n&&(n="sortable-placeholder"),!(e instanceof HTMLElement))throw new Error("You must provide a valid element as a sortable.");if(!(t instanceof HTMLElement)&&void 0!==t)throw new Error("You must provide a valid element as a placeholder or set ot to undefined.");return void 0===t&&(["UL","OL"].includes(e.tagName)?t=document.createElement("li"):["TABLE","TBODY"].includes(e.tagName)?(t=document.createElement("tr")).innerHTML='<td colspan="100"></td>':t=document.createElement("div")),"string"==typeof n&&(r=t.classList).add.apply(r,n.split(" ")),t},b=function(e){if(!(e instanceof HTMLElement))throw new Error("You must provide a valid dom element");var n=window.getComputedStyle(e);return["height","padding-top","padding-bottom"].map(function(e){var t=parseInt(n.getPropertyValue(e),10);return isNaN(t)?0:t}).reduce(function(e,t){return e+t})},s=function(e,t){if(!(e instanceof Array))throw new Error("You must provide a Array of HTMLElements to be filtered.");return"string"!=typeof t?e:e.filter(function(e){return e.querySelector(t)instanceof HTMLElement||e.shadowRoot&&e.shadowRoot.querySelector(t)instanceof HTMLElement}).map(function(e){return e.querySelector(t)||e.shadowRoot&&e.shadowRoot.querySelector(t)})},T=function(e){return e.composedPath&&e.composedPath()[0]||e.target},f=function(e,t,n){return{element:e,posX:n.pageX-t.left,posY:n.pageY-t.top}},L=function(e,t,n){if(!(e instanceof Event))throw new Error("setDragImage requires a DragEvent as the first argument.");if(!(t instanceof HTMLElement))throw new Error("setDragImage requires the dragged element as the second argument.");if(n||(n=f),e.dataTransfer&&e.dataTransfer.setDragImage){var r=n(t,m(t),e);if(!(r.element instanceof HTMLElement)||"number"!=typeof r.posX||"number"!=typeof r.posY)throw new Error("The customDragImage function you provided must return and object with the properties element[string], posX[integer], posY[integer].");e.dataTransfer.effectAllowed="copyMove",e.dataTransfer.setData("text/plain",T(e).id),e.dataTransfer.setDragImage(r.element,r.posX,r.posY)}},C=function(e,t){if(!0===e.isSortable){var n=p(e).getConfig("acceptFrom");if(null!==n&&!1!==n&&"string"!=typeof n)throw new Error('HTML5Sortable: Wrong argument, "acceptFrom" must be "null", "false", or a valid selector string.');if(null!==n)return!1!==n&&0<n.split(",").filter(function(e){return 0<e.length&&t.matches(e)}).length;if(e===t)return!0;if(void 0!==p(e).getConfig("connectWith")&&null!==p(e).getConfig("connectWith"))return p(e).getConfig("connectWith")===p(t).getConfig("connectWith")}return!1},M={items:null,connectWith:null,disableIEFix:null,acceptFrom:null,copy:!1,placeholder:null,placeholderClass:"sortable-placeholder",draggingClass:"sortable-dragging",hoverClass:!1,debounce:0,throttleTime:100,maxItems:0,itemSerializer:void 0,containerSerializer:void 0,customDragImage:null};var D,x,H,A,I,S,_,Y,O=function(e,t){if("string"==typeof p(e).getConfig("hoverClass")){var o=p(e).getConfig("hoverClass").split(" ");!0===t?(a(e,"mousemove",function(r,o){var i=this;if(void 0===o&&(o=250),"function"!=typeof r)throw new Error("You must provide a function as the first argument for throttle.");if("number"!=typeof o)throw new Error("You must provide a number as the second argument for throttle.");var a=null;return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=Date.now();(null===a||o<=n-a)&&(a=n,r.apply(i,e))}}(function(r){0===r.buttons&&d(e.children,p(e).getConfig("items")).forEach(function(e){var t,n;e!==r.target?(t=e.classList).remove.apply(t,o):(n=e.classList).add.apply(n,o)})},p(e).getConfig("throttleTime"))),a(e,"mouseleave",function(){d(e.children,p(e).getConfig("items")).forEach(function(e){var t;(t=e.classList).remove.apply(t,o)})})):(i(e,"mousemove"),i(e,"mouseleave"))}},P=function(e){i(e,"dragstart"),i(e,"dragend"),i(e,"dragover"),i(e,"dragenter"),i(e,"drop"),i(e,"mouseenter"),i(e,"mouseleave")},W=function(e,t){var n=e;return!0===p(t).getConfig("copy")&&(l(n=e.cloneNode(!0),"aria-copied","true"),e.parentElement.appendChild(n),n.style.display="none",n.oldDisplay=e.style.display),n},F=function(e){var t;(t=e).h5s&&delete t.h5s.data,r(e,"aria-dropeffect")},N=function(e){r(e,"aria-grabbed"),r(e,"aria-copied"),r(e,"draggable"),r(e,"role")};function j(e,t){if(t.composedPath)return t.composedPath().find(function(e){return e.isSortable});for(;!0!==e.isSortable;)e=e.parentElement;return e}function q(e,t){var n=c(e,"opts"),r=d(e.children,n.items).filter(function(e){return e.contains(t)||e.shadowRoot&&e.shadowRoot.contains(t)});return 0<r.length?r[0]:t}var z=function(e){var t=c(e,"opts"),n=d(e.children,t.items),r=s(n,t.handle);(l(e,"aria-dropeffect","move"),c(e,"_disabled","false"),l(r,"draggable","true"),!1===t.disableIEFix)&&("function"==typeof(document||window.document).createElement("span").dragDrop&&a(r,"mousedown",function(){if(-1!==n.indexOf(this))this.dragDrop();else{for(var e=this.parentElement;-1===n.indexOf(e);)e=e.parentElement;e.dragDrop()}}))},R=function(e){var t=c(e,"opts"),n=d(e.children,t.items),r=s(n,t.handle);c(e,"_disabled","false"),P(n),i(r,"mousedown"),i(e,"dragover"),i(e,"dragenter"),i(e,"drop")};function X(e,f){var i=String(f);return f=f||{},"string"==typeof e&&(e=document.querySelectorAll(e)),e instanceof HTMLElement&&(e=[e]),e=Array.prototype.slice.call(e),/serialize/.test(i)?e.map(function(e){var t=c(e,"opts");return o(e,t.itemSerializer,t.containerSerializer)}):(e.forEach(function(s){if(/enable|disable|destroy/.test(i))return X[i](s);["connectWith","disableIEFix"].forEach(function(e){f.hasOwnProperty(e)&&null!==f[e]&&console.warn('HTML5Sortable: You are using the deprecated configuration "'+e+'". This will be removed in an upcoming version, make sure to migrate to the new options when updating.')}),f=Object.assign({},M,p(s).config,f),p(s).config=f,c(s,"opts",f),s.isSortable=!0,R(s);var e,t=d(s.children,f.items);if(null!==f.placeholder&&void 0!==f.placeholder){var n=document.createElement(s.tagName);f.placeholder instanceof HTMLElement?n.appendChild(f.placeholder):n.innerHTML=f.placeholder,e=n.children[0]}p(s).placeholder=w(s,e,f.placeholderClass),c(s,"items",f.items),f.acceptFrom?c(s,"acceptFrom",f.acceptFrom):f.connectWith&&c(s,"connectWith",f.connectWith),z(s),l(t,"role","option"),l(t,"aria-grabbed","false"),O(s,!0),a(s,"dragstart",function(e){var t=T(e);if(!0!==t.isSortable&&(e.stopImmediatePropagation(),(!f.handle||t.matches(f.handle))&&"false"!==t.getAttribute("draggable"))){var n=j(t,e),r=q(n,t);S=d(n.children,f.items),A=S.indexOf(r),I=g(r,n.children),H=n,L(e,r,f.customDragImage),x=b(r),r.classList.add(f.draggingClass),l(D=W(r,n),"aria-grabbed","true"),n.dispatchEvent(new CustomEvent("sortstart",{detail:{origin:{elementIndex:I,index:A,container:H},item:D,originalTarget:t}}))}}),a(s,"dragenter",function(e){var t=T(e),n=j(t,e);n&&n!==_&&(Y=d(n.children,c(n,"items")).filter(function(e){return e!==p(s).placeholder}),n.dispatchEvent(new CustomEvent("sortenter",{detail:{origin:{elementIndex:I,index:A,container:H},destination:{container:n,itemsBeforeUpdate:Y},item:D,originalTarget:t}}))),_=n}),a(s,"dragend",function(e){if(D){D.classList.remove(f.draggingClass),l(D,"aria-grabbed","false"),"true"===D.getAttribute("aria-copied")&&"true"!==c(D,"dropped")&&D.remove(),D.style.display=D.oldDisplay,delete D.oldDisplay;var t=Array.from(u.values()).map(function(e){return e.placeholder}).filter(function(e){return e instanceof HTMLElement}).filter(v)[0];t&&t.remove(),s.dispatchEvent(new CustomEvent("sortstop",{detail:{origin:{elementIndex:I,index:A,container:H},item:D}})),x=D=_=null}}),a(s,"drop",function(e){if(C(s,D.parentElement)){e.preventDefault(),e.stopPropagation(),c(D,"dropped","true");var t=Array.from(u.values()).map(function(e){return e.placeholder}).filter(function(e){return e instanceof HTMLElement}).filter(v)[0];E(t,D),t.remove(),s.dispatchEvent(new CustomEvent("sortstop",{detail:{origin:{elementIndex:I,index:A,container:H},item:D}}));var n=p(s).placeholder,r=d(H.children,f.items).filter(function(e){return e!==n}),o=!0===this.isSortable?this:this.parentElement,i=d(o.children,c(o,"items")).filter(function(e){return e!==n}),a=g(D,Array.from(D.parentElement.children).filter(function(e){return e!==n})),l=g(D,i);I===a&&H===o||s.dispatchEvent(new CustomEvent("sortupdate",{detail:{origin:{elementIndex:I,index:A,container:H,itemsBeforeUpdate:S,items:r},destination:{index:l,elementIndex:a,container:o,itemsBeforeUpdate:Y,items:i},item:D}}))}});var o=h(function(t,e,n){if(D)if(f.forcePlaceholderSize&&(p(t).placeholder.style.height=x+"px"),-1<Array.from(t.children).indexOf(e)){var r=b(e),o=g(p(t).placeholder,e.parentElement.children),i=g(e,e.parentElement.children);if(x<r){var a=r-x,l=m(e).top;if(o<i&&n<l)return;if(i<o&&l+r-a<n)return}void 0===D.oldDisplay&&(D.oldDisplay=D.style.display),"none"!==D.style.display&&(D.style.display="none");var s=!1;try{s=m(e).top+e.offsetHeight/2<=n}catch(e){s=o<i}s?E(e,p(t).placeholder):y(e,p(t).placeholder),Array.from(u.values()).filter(function(e){return void 0!==e.placeholder}).forEach(function(e){e.placeholder!==p(t).placeholder&&e.placeholder.remove()})}else{var c=Array.from(u.values()).filter(function(e){return void 0!==e.placeholder}).map(function(e){return e.placeholder});-1!==c.indexOf(e)||t!==e||d(e.children,f.items).length||(c.forEach(function(e){return e.remove()}),e.appendChild(p(t).placeholder))}},f.debounce),r=function(e){var t=e.target,n=!0===t.isSortable?t:j(t,e);if(t=q(n,t),D&&C(n,D.parentElement)&&"true"!==c(n,"_disabled")){var r=c(n,"opts");parseInt(r.maxItems)&&d(n.children,c(n,"items")).length>=parseInt(r.maxItems)&&D.parentElement!==n||(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=!0===p(n).getConfig("copy")?"copy":"move",o(n,t,e.pageY))}};a(t.concat(s),"dragover",r),a(t.concat(s),"dragenter",r)}),e)}return X.destroy=function(e){var t,n,r,o;n=c(t=e,"opts")||{},r=d(t.children,n.items),o=s(r,n.handle),i(t,"dragover"),i(t,"dragenter"),i(t,"drop"),F(t),i(o,"mousedown"),P(r),N(r)},X.enable=function(e){z(e)},X.disable=function(e){var t,n,r,o;n=c(t=e,"opts"),r=d(t.children,n.items),o=s(r,n.handle),l(t,"aria-dropeffect","none"),c(t,"_disabled","true"),l(o,"draggable","false"),i(o,"mousedown")},X.__testing={_data:c,_removeItemEvents:P,_removeItemData:N,_removeSortableData:F},X}(); +//# sourceMappingURL=html5sortable.min.js.map |