JavaScript Prefix Menu Code

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

PliskinDev

Avid Poster
CC Dev Team
Determined Poster
Active Member
Console ID Poster
Jun 19, 2019
322
788
153
Minnesota


2_1535618627.jpg




----------------------------------------------------------
----------------------------------



[hide-reply][/hide-reply]
[hide-reply]
var SV=window.SV||{};SV.MultiPrefix=SV.MultiPrefix||{};
(function(c,m,n,p){c.extend(SV.MultiPrefix,{svMultiPrefixCounter:1});c.fn.extend({multiPrefixSelectorUniqueId:function(){var a=this.attr("id");a||(a="js-SVMultiPrefixUniqueId"+SV.MultiPrefix.svMultiPrefixCounter,this.attr("id",a),this.attr("data-sv-multiprefix-unique",SV.MultiPrefix.svMultiPrefixCounter),SV.MultiPrefix.svMultiPrefixCounter++);return a}});SV.MultiPrefix.PrefixMenu=XF.Element.newHandler({options:{realInput:null},init:function(){var a=this.$target,b=a.clone().insertAfter(a).removeAttr("data-xf-init").removeAttr("id").removeClass("u-noJsOnly");
this.template=this.$target.parent().find('script[type="text/template"]').html();this.template||(console.error("No prefix template could be found"),this.template="");a.remove();b.on("config-update",c.proxy(this,"initSelect2"));b.on("select2:unselecting",function(a){XF.MenuWatcher.preventDocClick()});b.on("select2:unselect",function(a){setTimeout(function(){XF.MenuWatcher.allowDocClick()},0)});a=b.closest(".overlay-container");if(a.length)a.on("overlay:hiding",function(){b.select2("close")});this.options.realInput=
b;b.trigger("config-update")},loadPrefixes:function(a){var b=[];a.find("option").each(function(){var a=c(this);b[a.attr("value")]={prefix_id:a.attr("value"),title:a.text(),css_class:a.attr("data-prefix-class")}});this.prefixes=b},initSelect2:function(){var a=this.options.realInput,b={width:"100%",minimumSelectionLength:parseInt(a.data("min-tokens"),1),maximumSelectionLength:parseInt(a.data("max-tokens"),10),containerCssClass:"input prefix--title",selectOnClose:!1,placeholder:XF.phrase("sv_prefix_placeholder",
null,"Prefix..."),disabled:this.options.realInput.prop("disabled"),templateResult:c.proxy(this,"renderPrefix"),templateSelection:c.proxy(this,"renderPrefix"),dropdownParent:a.parent(),debug:!1},e=a.val();"string"===typeof e&&(e=null);var d=b.maximumSelectionLength;e=e&&d&&e.length>d;var g=!1,h=a.find('option[value="0"]');if(e||1!==d)h.remove(),a.attr("multiple","multiple");else{b.minimumSelectionLength=void 0;b.maximumSelectionLength=void 0;h.length||a.prepend(c('<option value="0" data-prefix-class="label" />').text(XF.phrase("sv_multiprefix_none",
null,"(None)")));g=!0;d=a.attr("name");a.attr("name",d+"_original");var k=c("<input>").attr({type:"hidden",name:d}).insertAfter(a);var l=function(a){k.val(f.val()).trigger("select2:select");k.trigger("change",a);f.val("")}}this.loadPrefixes(a);a.multiPrefixSelectorUniqueId();a.data("select2")&&a.select2("destroy");var f=a.select2(b);if(g){f.on("change",l);l();b=f.data("select2");this.$container=b.$container;this.$selection=b.$selection;b.on("results:message",function(a){this.dropdown._resizeDropdown();
this.dropdown._positionDropdown()});a.attr("autofocus")&&(f.select2("open"),b.$selection.addClass("is-focused"));a=f.closest(".overlay-container");if(a.length)a.on("overlay:hiding",function(){f.select2("close")});f.on("select2:unselecting",function(a){XF.MenuWatcher.preventDocClick()});f.on("select2:unselect",function(a){setTimeout(function(){XF.MenuWatcher.allowDocClick()},0)})}e&&c(".select2-search__field").click()},renderPrefix:function(a){return a.id&&""!==this.template?c(Mustache.render(this.template,
{rich_prefix:this.prefixes[a.id]})):a.text}});SV.MultiPrefix.PrefixLoader=XF.Element.newHandler({options:{listenTo:"",initUpdate:!0,href:"",uniqueId:""},init:function(){if(this.$target.is("select")){if(this.options.uniqueId=this.$target.multiPrefixSelectorUniqueId(),this.options.href){var a=this.options.listenTo?XF.findRelativeIf(this.options.listenTo,this.$target):c([]);a.length?(a.on("change",c.proxy(this,"loadPrefixes")),this.options.initUpdate&&a.trigger("change")):console.error("Cannot load prefixes dynamically as no element set to listen to for changes")}}else console.error("Must trigger on select")},
loadPrefixes:function(a){XF.ajax("POST",this.options.href,{val:c(a.target).val()},c.proxy(this,"loadSuccess"))},loadSuccess:function(a){if(a.html){var b=c("#js-SVMultiPrefixUniqueId"+(parseInt(this.$target.attr("data-sv-multiprefix-unique"),10)+1));XF.setupHtmlInsert(a.html,function(a){var d=b.val();"string"===typeof d&&(d=[d]);a.each(function(){var a=c(this).find("select");if(a.length){b.empty().append(a.children());d?c.each(d,function(a,c){b.find('option[value="'+c+'"]').prop("selected",!0)}):b.find("option").first().prop("checked",
!0);var e=a.data("min-tokens");a=a.data("max-tokens");b.data("min-tokens",e).attr("data-max-tokens",a).data("max-tokens",a).attr("data-min-tokens",e);b.find("option:selected");b.trigger("config-update");return!1}})})}}});XF.QuickThread&&(SV.MultiPrefix.QuickThread=XF.extend(XF.QuickThread,{__backup:{reset:"svMultiPrefix_reset"},reset:function(a,b){c('select[name="prefix_id[]"]').val("").trigger("change");this.svMultiPrefix_reset(a,b)}}),XF.Element.register("quick-thread","SV.MultiPrefix.QuickThread"));
XF.Element.register("sv-multi-prefix-loader","SV.MultiPrefix.PrefixLoader");XF.Element.register("sv-multi-prefix-menu","SV.MultiPrefix.PrefixMenu")})(jQuery,window,document);
[/hide-reply]





--------------------------------------
 
General chit-chat
Help Users
      Chat Bot: QM|T_JinX has joined the room.