-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.pstagger.min.js
17 lines (16 loc) · 2.99 KB
/
jquery.pstagger.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
* jQuery pstagger plugin
* https://www.prestashop.com
*
* Copyright PrestaShop and other contributors
* Released under the MIT license
* https://tldrlegal.com/license/mit-license
*
* Date: 2016-01-13
*/
(function(c){var b=null,g=[],d=null,k={wrapperClassAdditional:"",tagsWrapperClassAdditional:"",tagClassAdditional:"",closingCrossClassAdditionnal:"",tagInputWrapperClassAdditional:"",tagInputClassAdditional:"",delimiter:" ",inputPlaceholder:"Add tag ...",closingCross:!0,context:null,clearAllBtn:!1,clearAllIconClassAdditional:"",clearAllSpanClassAdditional:"",onTagsChanged:null,onResetTags:null},m=function(){d.keypress(function(a){13==a.keyCode&&(g=[],h())});d.focusout(function(a){if(c(".pstaggerResetTagsBtn:hover").length)return!1;
d.val().length&&(g=[],h())})},h=function(){var a=d.val(),e=a.split(b.delimiter);if(a.length){for(var f in e)a=e[f],""!==a&&g.push(a);e="";for(f in g)a=g[f],a='<span class="pstaggerTag '+b.tagClassAdditional+'"><span>'+c("<div/>").text(a).html()+"</span>",!0===b.closingCross&&(a+='<a class="pstaggerClosingCross '+b.closingCrossClassAdditionnal+'" href="#">x</a>'),a+="</span>",e+=a;c(".pstaggerTagsWrapper").empty().prepend(e).css("display","block");c(".pstaggerAddTagWrapper").css("display","none")}else c(".pstaggerTagsWrapper").css("display",
"none"),c(".pstaggerAddTagWrapper").css("display","block"),d.focus();null!==b.onTagsChanged&&b.onTagsChanged.call(b.context,g)},n=function(){c(".pstaggerTagsWrapper").on("click",function(a){a=a.target.className.match(RegExp("pstaggerClosingCross","g"));c(".pstaggerAddTagWrapper").is(":hidden")&&null===a&&(c(".pstaggerTagsWrapper").css("display","none"),c(".pstaggerAddTagWrapper").css("display","block"),d.focus())})},p=function(){c(document).delegate(".pstaggerResetTagsBtn","click",function(){l(!0)})},
l=function(a){g=[];d.val("");c(".pstaggerTagsWrapper").css("display","none");c(".pstaggerAddTagWrapper").css("display","block");d.focus();c(".pstaggerTag").remove();null!==b.onResetTags&&!0===a&&b.onResetTags.call(b.context)},r=function(){c(document).delegate(".pstaggerClosingCross","click",function(a){a=c(this).parent();var b=a.index(),b=q(b);d.val(b);a.remove();g=[];h()})},q=function(a){var b="";c(".pstaggerTag").each(function(d,g){if(a==c(this).index())return!0;b+=" "+c(this).children().first().text()});
return b};c.fn.pstagger=function(a){var e={},f;for(f in k)a.hasOwnProperty(f)?e[f]=a[f]:e[f]=k[f];e.originalInput=this;b=e;b.originalInput.css("display","none");a="";!0===b.clearAllBtn&&(a+='<span class="pstaggerResetTagsBtn '+b.clearAllSpanClassAdditional+'"><i class=" '+b.clearAllIconClassAdditional+'"></i></span>',p());b.originalInput.after('<div class="pstaggerWrapper '+b.wrapperClassAdditional+'">'+a+'<div class="pstaggerTagsWrapper '+b.tagsWrapperClassAdditional+'"></div><div class="pstaggerAddTagWrapper '+
b.tagInputWrapperClassAdditional+'"><input class="pstaggerAddTagInput '+b.tagInputClassAdditional+'"></div></div>');d=c(".pstaggerAddTagInput");d.attr("placeholder",b.inputPlaceholder);m();n();r();return{resetTags:l}}})(jQuery);