-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjquery.formStylerModern.min.js
9 lines (8 loc) · 29.7 KB
/
jquery.formStylerModern.min.js
1
2
3
4
5
6
7
8
9
/**
* jquery.formstyler-modern - JQuery HTML form styling plugin
* @version v2.1.6
* @link https://github.com/ange007/JQueryFormStyler-Modern
* @license MIT
* @author Borisenko Vladimir
*/
"use strict";function _typeof(e){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function e(t){return typeof t}}else{_typeof=function e(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t}}return _typeof(e)}(function(e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else if((typeof exports==="undefined"?"undefined":_typeof(exports))==="object"){module.exports=e($||require("jquery"))}else{e(jQuery)}})(function(j){"use strict";var v="styler";var c="-"+v;var s={locale:navigator.browserLanguage||navigator.language||navigator.userLanguage||"en-US",select:{search:{limit:10,ajax:undefined},triggerHTML:'<div class="jq-selectbox__trigger-arrow"></div>',visibleOptions:0,smartPosition:true,onOpened:function e(){},onClosed:function e(){}},checkbox:{indeterminate:false},password:{switchHTML:'<button type="button" class="'+v+'"></button>'},number:{horizontal:false},onFormStyled:function e(){}};var o={"en-US":{file:{placeholder:"No file selected",browse:"Browse...",counter:"Selected files: %s"},select:{placeholder:"Select...",empty:"List is Empty!",search:{notFound:"No matches found",placeholder:"Search...",loading:"Loading...",error:"Error!"}},password:{show:"⦿",hide:"⦾"}},"ru-RU":{file:{placeholder:"Файл не выбран",browse:"Обзор...",counter:"Выбрано файлов: %s"},select:{placeholder:"Выберите...",empty:"Список пуст!",search:{notFound:"Совпадений не найдено",placeholder:"Поиск...",loading:"Идёт поиск...",error:"Ошибка!"}}},"uk-UA":{file:{placeholder:"Файл не обрано",browse:"Огляд...",counter:"Обрано файлів: %s"},select:{placeholder:"Виберіть...",empty:"Список пустий!",search:{notFound:"Збігів не знайдено",placeholder:"Пошук...",loading:"Йде пошук...",error:"Помилка!"}}}};o["en"]=o["en-US"];o["ru"]=o["ru-RU"];o["ua"]=o["uk-UA"];function m(e){if(e.attr("id")!==undefined&&e.attr("id")!==""){this.id=e.attr("id")+c}this.title=e.attr("title");this.classes=(e.attr("class")||"")+" "+v;this.data=e.data()}function n(e,t){this.element=e;this.customElement=undefined;this.options=j.extend(true,{},s,t);var i=j.extend(true,{},o["en-US"],o[this.options.locale]);this.locales=j.extend(true,{},i,this.options.locales);this.init()}n.prototype={init:function e(){var t=this,i=j(this.element);var f=navigator.userAgent.match(/(iPad|iPhone|iPod)/i)&&!navigator.userAgent.match(/(Windows\sPhone)/i),c=navigator.userAgent.match(/Android/i)&&!navigator.userAgent.match(/(Windows\sPhone)/i),s=navigator.userAgent.match(/(MSI|Windows\sPhone|Trident(?=\/))/i);if(i.is(":checkbox")){var o=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=new m(this.element);this.checkbox=j('<div class="jq-checkbox"><div class="jq-checkbox__flag"></div></div>').attr({id:o.id,title:o.title,unselectable:"on"}).addClass(o.classes).data(o.data);this.element.addClass("jq-hidden").after(this.checkbox).prependTo(this.checkbox);this.setEvents().repaint()};e.prototype={setEvents:function e(){var t=this,i=this.options,s=this.element,o=this.checkbox;o.on("repaint",function(){t.repaint()}).on("click",function(e){e.preventDefault();if(o.is(".disabled")){return}if(s.is(":checked")||s.is(":indeterminate")){s.prop("checked",i.indeterminate&&s.is(":indeterminate"));s.prop("indeterminate",false)}else{if(i.indeterminate){s.prop("checked",false).prop("indeterminate",true)}else{s.prop("checked",true).prop("indeterminate",false)}}s.focus().trigger("change").triggerHandler("click")});s.closest("label").add('label[for="'+this.element.attr("id")+'"]').on("click."+v,function(e){if(!j(e.target).is("a")&&!j(e.target).closest(o).length){o.triggerHandler("click");e.preventDefault()}});s.on("change."+v,function(){o.triggerHandler("repaint")}).on("keydown."+v,function(e){if(e.which===32){e.preventDefault();o.triggerHandler("click")}}).on("focus."+v,function(){if(!o.is(".disabled")){o.addClass("focused")}}).on("blur."+v,function(){o.removeClass("focused")});return this},repaint:function e(){var t=this.element,i=this.checkbox;if(t.is(":checked")||t.is(":indeterminate")){if(t.is(":indeterminate")){i.removeClass("checked").addClass("indeterminate")}else{i.removeClass("indeterminate").addClass("checked")}}else{i.removeClass("indeterminate").removeClass("checked")}i.toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").removeAttr("style").parent().before(t).remove();t.closest("label").add('label[for="'+t.attr("id")+'"]').off("."+v);return this}};return e}();this.customElement=new o(i,this.options.checkbox,this.locales.checkbox)}else if(i.is(":radio")){var n=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=new m(this.element);this.radio=j('<div class="jq-radio"><div class="jq-radio__div"></div></div>').attr({id:o.id,title:o.title,unselectable:"on"}).addClass(o.classes).data(o.data);this.element.addClass("jq-hidden").after(this.radio).prependTo(this.radio);this.setEvents().repaint()};e.prototype={setEvents:function e(){var i=this,s=this.element,o=this.radio;o.on("repaint",function(){i.repaint()}).on("click",function(e){e.preventDefault();if(o.is(".disabled")){return}var t=i.commonParent(s);t.prop("checked",false).trigger("change");s.prop("checked",true).focus().trigger("change").triggerHandler("click")});s.on("change."+v,function(){o.triggerHandler("repaint")}).on("keydown."+v,function(e){if(e.which===32){e.preventDefault();o.trigger("click")}}).on("focus."+v,function(){if(o.is(".disabled")){return}o.addClass("focused")}).on("blur."+v,function(){o.removeClass("focused")});s.closest("label").add('label[for="'+s.attr("id")+'"]').on("click."+v,function(e){if(!j(e.target).is("a")&&!j(e.target).closest(o).length){o.triggerHandler("click");e.preventDefault()}});return this},commonParent:function e(t){var i=t.attr("name"),s='input[name="'+i+'"]:radio';var o=t.closest(".jq-radio").closest("form").find(s);if(o.length<=0){o=j("body").find(s)}return o},repaint:function e(){var t=this.element,i=this.radio;t.parent().toggleClass("checked",t.is(":checked"));i.toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").removeAttr("style").parent().before(t).remove();t.closest("label").add('label[for="'+t.attr("id")+'"]').off("."+v);return this}};return e}();this.customElement=new n(i,this.options.radio,this.locales.radio)}if(i.is('input[type="switcher"]')){var r=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=new m(this.element);this.switcher=j('<div class="jq-switcher">'+'<div class="toggle-button"></div>'+'<div class="toggle-text toggle-text-off">OFF</div>'+'<div class="toggle-text toggle-text-on">ON</div>'+"</div>").attr({id:o.id,title:o.title,unselectable:"on"}).addClass(o.classes).data(o.data);this.element.attr("type","checkbox").addClass("jq-hidden").after(this.switcher).prependTo(this.switcher);this.setEvents().repaint()};e.prototype={setEvents:function e(){var t=this,i=this.options,s=this.element,o=this.switcher;o.on("repaint",function(){t.repaint()}).on("click",function(e){e.preventDefault();if(!o.is(".disabled")){s.prop("checked",!s.is(":checked"));s.focus().trigger("change").triggerHandler("click")}});s.closest("label").add('label[for="'+this.element.attr("id")+'"]').on("click."+v,function(e){if(!j(e.target).is("a")&&!j(e.target).closest(o).length){o.triggerHandler("click");e.preventDefault()}});s.on("change."+v,function(){o.triggerHandler("repaint")}).on("keydown."+v,function(e){if(e.which===32){e.preventDefault();o.triggerHandler("click")}}).on("focus."+v,function(){if(o.is(".disabled")){return}o.addClass("focused")}).on("blur."+v,function(){o.removeClass("focused")});return this},repaint:function e(){var t=this.element,i=this.switcher;i.toggleClass("checked",t.is(":checked"));i.toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").removeAttr("style").parent().before(t).remove();t.closest("label").add('label[for="'+t.attr("id")+'"]').off("."+v);return this}};return e}();this.customElement=new r(i,this.options.switcher,this.locales.switcher)}else if(i.is(":file")){var l=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;this.placeholderText=this.element.data("placeholder")||s["placeholder"];this.browseText=this.element.data("browse")||s["browse"];var o=new m(this.element);this.file=j('<div class="jq-file">'+'<div class="jq-file__name">'+this.placeholderText+"</div>"+'<div class="jq-file__browse">'+this.browseText+"</div>"+"</div>").attr({id:o.id,title:o.title}).addClass(o.classes).data(o.data);this.element.addClass("jq-hidden").after(this.file).appendTo(this.file);this.setEvents().repaint()};e.prototype={setEvents:function e(){var t=this,i=this.element,s=this.file;s.on("repaint",function(){t.repaint()});i.on("change."+v,function(){s.triggerHandler("repaint")}).on("focus."+v,function(){s.addClass("focused")}).on("blur."+v,function(){s.removeClass("focused")}).on("click."+v,function(){s.removeClass("focused")});return this},repaint:function e(){var t=this.element,i=this.file,s=this.options,o=j("div.jq-file__name",i);var n=t.val();if(t.is("[multiple]")){var r=t[0].files.length;if(r>0){n=(t.data("number")||s.counter).replace("%s",r)}else{n=""}}o.text(n.replace(/.+[\\\/]/,"")||this.placeholderText);i.toggleClass("changed",n!=="").toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").removeAttr("style").parent().before(t).remove();return this}};return e}();this.customElement=new l(i,this.options.file,this.locales.file)}else if(i.is('input[type="number"]')){var a=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=new m(this.element);this.number=j('<div class="jq-number">'+'<div class="jq-number__spin minus"></div>'+'<div class="jq-number__spin plus"></div>'+"</div>").attr({id:o.id,title:o.title}).addClass(o.classes).data(o.data);this.element.after(this.number).prependTo(this.number).wrap('<div class="jq-number__field"></div>');if(this.options.horizontal){this.number.addClass("horizontal")}this.setEvents().repaint()};e.prototype={setEvents:function e(){var t=this,i=this.element,s=this.number;var o=null,n=null;s.on("repaint",function(){t.repaint()}).on("mousedown","div.jq-number__spin",function(){if(i.is(":disabled")){return}var e=j(this);t.changeValue(e);o=setTimeout(function(){n=setInterval(function(){t.changeValue(e)},40)},350)}).on("mouseup mouseout","div.jq-number__spin",function(){if(i.is(":disabled")){return}clearTimeout(o);clearInterval(n)});i.on("focus."+v,function(){s.addClass("focused")}).on("blur."+v,function(){s.removeClass("focused")});return this},repaint:function e(){this.number.toggleClass("disabled",this.element.is(":disabled"));return this},changeValue:function e(t){var i=this.element;var s=i.attr("min")||undefined,o=i.attr("max")||undefined,n=parseFloat(i.attr("step"))||1;var r=j.isNumeric(i.val())?i.val():0,l=parseFloat(r)+(t.is(".plus")?n:-n);var a=(n.toString().split(".")[1]||[]).length.prototype;var d="1";if(a>0){while(d.length<=a){d=d+"0"}l=Math.round(l*d)/d}if(j.isNumeric(s)&&j.isNumeric(o)){if(l>=s&&l<=o){i.val(l).change()}}else if(j.isNumeric(s)&&!j.isNumeric(o)){if(l>=s){i.val(l).change()}}else if(!j.isNumeric(s)&&j.isNumeric(o)){if(l<=o){i.val(l).change()}}else{i.val(l).change()}return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").closest(".jq-number").before(t).remove();return this}};return e}();this.customElement=new a(i,this.options.number,this.locales.number)}else if(i.is('input[type="password"]')&&!i.is("[nobutton]")&&this.options.password.switchHTML!==undefined&&this.options.password.switchHTML!=="none"){var d=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=j('<div class="jq-password__switch">'+(this.options.switchHTML||"")+"</div>");this.password=j('<div class="jq-password">').append(o);this.button=o.children("button").length>0?o.children("button"):o;if(this.button.html()===""&&s["show"]!==""){this.button.html(s["show"]);if(o.children("button").length<=0){o.addClass("jq-password__switch-text")}}this.element.after(this.password).prependTo(this.password);this.setEvents().repaint()};e.prototype={setEvents:function e(){var s=this.locale,o=this.element,t=this.password,n=this.button;t.on("repaint",function(){t.toggleClass("disabled",o.is(":disabled"));n.prop("disabled",o.is(":disabled"))}).on("click",".jq-password__switch",function(){var e=j(this),t=e.closest(".jq-password"),i=t.is(".jq-password_seen");t.toggleClass("jq-password_seen",!i);if(s["show"]!==""&&s["hide"]!==""){n.html(i?s["show"]:s["hide"])}o.attr("type",i?"password":"text")});o.on("focus."+v,function(){t.addClass("focused")}).on("blur."+v,function(){t.removeClass("focused")});return this},repaint:function e(){var t=this.element,i=this.password,s=this.button;i.toggleClass("disabled",t.is(":disabled"));s.prop("disabled",t.is(":disabled"));return this},destroy:function e(){var t=this.element;t.off("."+v+", refresh").closest(".jq-password").before(t).remove();return this}};return e}();this.customElement=new d(i,this.options.password,this.locales.password)}else if(i.is('input[type="hidden"]')){return}else if(i.is("select")){var h=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;this.ajaxOptions=i.search.ajax;this.ajaxData={term:"",page:0};this.ajaxTimeout=undefined;var o=new m(this.element);this.searchBlock=j('<div class="jq-selectbox__search">'+'<input type="search" autocomplete="off" placeholder="'+(t.attr("placeholder")||t.data("placeholder")||s.search["placeholder"])+'">'+"</div>"+'<div class="jq-selectbox__search-status">'+(t.data("search-not-found")||s.search["notFound"])+"</div>").hide();this.dropdown=j('<div class="jq-selectbox__dropdown" style="position: absolute">'+"<ul></ul>"+'<div class="jq-selectbox__empty">'+s["empty"]+"</div>"+"</div>").prepend(this.searchBlock);this.selectbox=j('<div class="jq-selectbox jqselect">'+'<div class="jq-selectbox__select">'+'<div class="jq-selectbox__select-text"></div>'+'<div class="jq-selectbox__trigger">'+(i.triggerHTML||"")+"</div>"+"</div></div>").attr({id:o.id,title:o.title}).data(o.data).addClass(o.classes).append(this.dropdown);t.after(this.selectbox).prependTo(this.selectbox);this.selectboxSelect=j("div.jq-selectbox__select",this.selectbox);this.selectboxText=j("div.jq-selectbox__select-text",this.selectbox);this.loadDropdown();this.dropdown.hide();this.setEvents().repaint();t.addClass("jq-hidden")};e.prototype={loadDropdown:function e(){var t=this.element,i=this.options,s=this.locale,o=this.selectbox,n=this.dropdown,r=this.searchBlock,l=this.searchBlock.find("input");var a=j("option",t),d=a.filter(":selected"),c=C.makeList(a),h=t.data("search")||i.search,u=t.data("search-limit")||(i.search||{}).limit,f=j("div.jq-selectbox__search-status",n),p=j("div.jq-selectbox__empty",n);n.find("ul").replaceWith(c);var v=j("li",n).css({display:"inline-block"}),m=v.filter(".selected");if(n.css("left")==="auto"){n.css({left:0})}if(v.filter(":visible").length<=0&&l.val()===""){p.show()}else{p.hide()}if(h&&(v.length>u||this.ajaxOptions!==undefined&&this.ajaxOptions.url!=="")){r.show();f.html(s.search["notFound"]).toggle(v.filter(":visible").length<=0)}else{r.hide()}this.calculateDropdownWidth();this.calculateDropdownHeight();if(m.length){if(a.first().text()!==d.text()){o.addClass("changed")}o.data("jqfs-class",m.data("jqfs-class")).addClass(m.data("jqfs-class"))}return this},closeDropdown:function e(){var t=this.element,i=this.options,s=this.selectbox,o=this.dropdown;o.hide();s.removeClass("opened dropup dropdown");i.onClosed.call(s);return this},openDropdown:function e(){var t=this.element,i=this.options,s=this.selectbox,o=this.dropdown,n=this.searchBlock.find("input");var r=j("div.jq-selectbox__search-status",o);j("div.jqselect").removeClass("opened");j("div.jq-selectbox__dropdown:visible").hide();s.addClass("opened focused");o.show();this.smartPosition();if(n.parent().is(":visible")){n.trigger("focus");r.hide()}i.onOpened.call(s);return this},calculateDropdownWidth:function e(){var t=this.element,i=this.selectbox,s=this.selectboxText,o=this.dropdown;var n=t.attr("placeholder")||t.data("placeholder")||this.placeholder;var r=j("li",o);var l=0,a=0;r.each(function(){var e=j(this);if(e.innerWidth()>l){l=e.innerWidth();a=e.width()}});r.css({display:""});var d=i.clone().appendTo("body").width("auto");var c=d.outerWidth();d.remove();if(c===i.outerWidth()&&a>0){s.width(a)}if(l>i.width()){o.width(l)}if(j("option",t).first().text()===""&&n!==""){r.first().hide()}return this},calculateDropdownHeight:function e(){var t=this.element,i=this.options,s=this.selectbox,o=this.dropdown;var n=j("li",o);if(n.data("li-height")===undefined){n.data("li-height",n.outerHeight())}if(o.css("top")==="auto"){o.css({top:s.outerHeight(true)||0})}return this},smartPosition:function e(){var t=this.element,i=this.options,s=this.ajaxOptions,o=this.selectbox,n=this.dropdown,r=this.searchBlock.find("input");var l=t.data("smart-position")||i.smartPosition;var a=j("ul",n),d=j("li",n),c=j("div.jq-selectbox__search-status",n),h=d.length,u=o.outerHeight(true)||0,f=a.css("max-height")||0,p=u||0;var v=d.data("li-height")||0;var m=t.data("visible-options")||i.visibleOptions,g=o.offset().top||0,b=j(window).height()-u-(g-j(window).scrollTop()),w=r.parent().outerHeight(true)||0,x=m===0?"auto":v*m,y=m>0&&m<6?x:v*(h<5?h:5);if(l&&b<=y+w+v){this.dropUp(a,g,x,v,f)}else{this.dropDown(a,b,x,v,f)}if(o.offset().left+n.outerWidth()>j(window).width()){n.css({left:"auto",right:0})}if(a.outerHeight(true)<y){a.css("min-height",y)}if(d.filter(".selected").length){if(t.val()===""){a.scrollTop(0)}else{if(a.innerHeight()/v%2!==0){v=v/2}a.scrollTop(a.scrollTop()+d.filter(".selected").position().top-a.innerHeight()/2+v)}}C.preventScrolling(a);return this},dropDown:function e(t,i,s,o,n){var r=j("input",this.dropdown).parent().outerHeight(true)||0;this.selectbox.removeClass("dropup").addClass("dropdown");var l=function e(){t.css("max-height",Math.floor((i-r-o)/o)*o)};l();t.css("max-height",n!=="none"&&parseInt(n)>0?parseInt(n):s);if(i<this.dropdown.outerHeight()+o){l()}return this},dropUp:function e(t,i,s,o,n){var r=j("input",this.dropdown).parent().outerHeight(true)||0;this.selectbox.removeClass("dropdown").addClass("dropup");var l=function e(){t.css("max-height",Math.floor((i-j(window).scrollTop()-r-o)/o)*o)};l();t.css("max-height",n!=="none"&&n>0?n:s);if(i-j(window).scrollTop()-o<this.dropdown.outerHeight()+o){l()}this.dropdown.css({top:"auto"});return this},setEvents:function e(){var o=this,n=this.element,r=this.options,l=this.locale,a=this.ajaxOptions,s=this.selectbox,d=this.dropdown,t=this.searchBlock.find("input"),i=this.selectboxSelect;var c=j("ul",d),h=j("li",d),u=j("div.jq-selectbox__search-status",d);s.on("repaint",function(){o.repaint()}).on("dropdown:close",function(){o.closeDropdown()}).on("dropdown:open",function(){o.openDropdown()});i.on("click",function(e){if(n.is(":disabled")){return}if(j("div.jq-selectbox").filter(".opened").length){r.onClosed.call(j("div.jq-selectbox").filter(".opened"))}n.trigger("focus");if(f){return}if(d.is(":visible")){s.triggerHandler("dropdown:close")}else{s.triggerHandler("dropdown:open")}});t.on("keyup",function(){var t=j(this).val(),e=j("option",o.element),i=n.attr("placeholder")||n.data("placeholder")||r.placeholder,s=j("div.jq-selectbox__search-status",d);if(a!==undefined&&a.url!==""){if(t!==""){s.html(l.search["loading"]);if(o.ajaxTimeout){window.clearTimeout(o.ajaxTimeout)}o.ajaxTimeout=window.setTimeout(function(){o.ajaxSearch(t,true)},a.delay||100)}else{n.find("option").remove();o.loadDropdown()}}else{h.each(function(){var e=j(this).html().match(new RegExp(".*?"+t+".*?","i"));j(this).toggle(e?true:false)})}if(e.first().text()===""&&i!==""){h.first().hide()}if(t!==""){s.toggle(h.filter(":visible").length<=0)}else{s.hide()}});d.on("mouseout",function(){j("li.sel",this).addClass("selected")}).on("hover","li",function(){j(this).siblings().removeClass("selected")}).on("click","li",function(){var e=j(this),t=j("option",o.element);if(e.is(".disabled, .optgroup")){return}if(!e.is(".selected")){var i=e.index()-e.prevAll(".optgroup").length;t.prop("selected",false).eq(i).prop("selected",true);n.change()}s.triggerHandler("dropdown:close")});n.on("change."+v,function(){s.triggerHandler("repaint")}).on("focus."+v,function(){s.addClass("focused")}).on("blur."+v,function(e){s.removeClass("focused")}).on("keydown."+v+" keyup."+v,function(e){var t=h.data("li-height");if(e.which===38||e.which===37||e.which===33||e.which===36){if(n.val()===""){c.scrollTop(0)}else{c.scrollTop(c.scrollTop()+h.filter(".selected").position().top)}}if(e.which===40||e.which===39||e.which===34||e.which===35){c.scrollTop(c.scrollTop()+h.filter(".selected").position().top-c.innerHeight()+t)}if(e.which===13){e.preventDefault();s.triggerHandler("dropdown:close")}}).on("keydown."+v,function(e){if(e.which===32){i.triggerHandler("click");return false}});return this},ajaxSearch:function e(t,o){var n=this,r=this.element,i=this.dropdown,s=this.options,l=this.locale,a=this.ajaxOptions;var d=j("div.jq-selectbox__search-status",i);d.html(l.search["loading"]);this.ajaxData.term=t;var c={type:"GET",success:function e(t,i,s){d.html(l.search["notFound"]);return n.ajaxSearchSuccess(t,o)},error:function e(t,i,s){if(o){r.find("option").remove();n.loadDropdown()}if(n.options.debug&&window.console&&console.error){console.error("JQuery.FormStyler-Modern: Ошибка при запросе!")}}};var h=j.extend(c,a);if(typeof h.url==="function"){h.url=a.url.call(r,n.ajaxData)}if(typeof h.data==="function"){h.data=a.data.call(r,n.ajaxData)}j.ajax(h);return this},ajaxSearchSuccess:function e(t,i){var s=this,o=this.element,n=this.options,r=this.ajaxOptions;var l=r.processResults(t,s.ajaxData);if(this.options.debug&&window.console&&console.error){if(!l||!l.items||!j.isArray(l.items)){console.error("JQuery.FormStyler-Modern: В ответе не найдены данные по ключу - `items`.")}}if(i){o.find("option").remove()}var a=l.items||l;j(a).each(function(e,t){j("<option>").val(t.value||t.id||e).text(t.caption||t.name||t.text||t).appendTo(o)});this.loadDropdown();this.smartPosition();return this},repaint:function e(){var t=this.element,i=this.options,s=this.selectbox,o=this.dropdown,n=this.selectboxText;var r=j("option",t),l=j("li",o);var a=r.filter(":selected");var d=t.attr("placeholder")||t.data("placeholder")||i.placeholder;if(a.val()===undefined||a.val()===""){n.html(d).addClass("placeholder");this.calculateDropdownWidth()}else{n.html(a.html()).removeClass("placeholder")}if(s.data("jqfs-class")){s.removeClass(s.data("jqfs-class"))}s.data("jqfs-class",a.attr("class")).addClass(a.attr("class"));l.removeClass("selected sel").not(".optgroup").eq(t[0].selectedIndex).addClass("selected sel");l.removeClass("disabled").not(".optgroup").filter(function(e){return r.eq(e).is(":disabled")}).addClass("disabled");s.toggleClass("changed",r.first().text()!==l.filter(".selected").text());s.toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){this.element.off("."+v).removeAttr("style").parent().before(this.element).remove();return this}};return e}();var u=function(){var e=function e(t,i,s){this.element=t;this.options=i;this.locale=s;var o=new m(this.element);this.selectbox=j('<div class="jq-select-multiple jqselect"></div>').attr({id:o.id,title:o.title}).addClass(o.classes).data(o.data);t.after(this.selectbox).prependTo(this.selectbox);this.loadList();var n=j("ul",this.selectbox),r=j("li",this.selectbox).attr("unselectable","on"),l=this.element.attr("size")||4,a=n.outerHeight()||0,d=r.outerHeight()||0;n.css({height:d*l});if(a>this.selectbox.height()){n.css("overflowY","scroll");C.preventScrolling(n);if(r.filter(".selected").length){n.scrollTop(n.scrollTop()+r.filter(".selected").position().top)}}this.element.addClass("jq-hidden");this.setEvents().repaint()};e.prototype={loadList:function e(){var t=this.element,i=this.selectbox;var s=j("option",t),o=C.makeList(s);i.remove("ul").append(o);return this},setEvents:function e(){var t=this,o=this.element,i=this.selectbox;var n=j("option",o),s=j("ul",i),r=j("li",i),l=s.outerHeight()||0,a=r.outerHeight()||0,d=c||f;i.on("repaint",function(){t.repaint()});r.on("click tap",function(e){var t=j(this);if(o.is(":disabled")||t.is(".disabled")){return}o.focus();if(d&&!o.is("[multiple]")||!d&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){t.siblings().removeClass("selected first")}if(d&&!o.is("[multiple]")||!d&&!e.ctrlKey&&!e.metaKey){t.addClass("selected")}if(o.is("[multiple]")&&t.is(".optgroup")){var i=t.nextUntil(".optgroup");i.each(function(){if(!j(this).is(".disabled, .optgroup")){if(j(this).is(".first")){j(this).removeClass("first")}j(this).toggleClass("selected")}})}else if(o.is("[multiple]")){if(!e.shiftKey){t.addClass("first")}if(d||e.ctrlKey||e.metaKey){t.toggleClass("selected first",!t.is(".selected")).siblings().removeClass("first")}else if(e.shiftKey){var s=function e(){if(j(this).is(".selected")){return false}else{j(this).not(".disabled, .optgroup").addClass("selected")}};t.siblings().removeClass("selected").siblings(".first").addClass("selected");if(t.prevAll(".first").length>0){t.prevAll().each(s)}if(t.nextAll(".first").length>0){t.nextAll().each(s)}if(r.filter(".selected").length===1){t.addClass("first")}}}n.prop("selected",false);r.filter(".selected").each(function(){var e=j(this),t=e.index()-(e.is(".option")?e.prevAll(".optgroup").length:0);n.eq(t).prop("selected",true)});o.change()});n.each(function(e){j(this).data("optionIndex",e)});o.on("change."+v,function(){i.triggerHandler("repaint")}).on("focus."+v,function(){i.addClass("focused")}).on("blur."+v,function(){i.removeClass("focused")});if(l>i.height()){o.on("keydown."+v,function(e){if(e.which===38||e.which===37||e.which===33){s.scrollTop(s.scrollTop()+r.filter(".selected").position().top-a)}if(e.which===40||e.which===39||e.which===34){s.scrollTop(s.scrollTop()+r.filter(".selected:last").position().top-s.innerHeight()+a*2)}})}return this},repaint:function e(){var t=this.element,i=this.selectbox;var s=j("option",t),o=j("li",i);var n=[];s.filter(":selected").each(function(){n.push(j(this).data("optionIndex"))});o.removeClass("selected").not(".optgroup").filter(function(e){return j.inArray(e,n)>-1}).addClass("selected");o.removeClass("disabled").not(".optgroup").filter(function(e){return s.eq(e).is(":disabled")}).addClass("disabled");i.toggleClass("disabled",t.is(":disabled"));return this},destroy:function e(){this.element.off("."+v+", refresh").removeAttr("style").parent().before(this.element).remove();return this}};return e}();if(i.is("[multiple]")||i.attr("size")>1){this.customElement=new u(i,this.options.select,this.locales.select)}else{this.customElement=new h(i,this.options.select,this.locales.select);if(!C.initEvent){C.init()}}}else if(i.is("input")||i.is("textarea")||i.is("button")||i.is("a.button")){i.addClass(v);if(i.is('input[type="reset"]')){i.on("click",function(){i.closest("form").children().trigger("repaint")})}if(i.is('input[type="range"]')&&s){var p=i.css("display");i.css("display","block");setTimeout(function(){i.css("display",p)},1)}}i.on("refresh reinitialize",function(){t.reinitialize()})},destroy:function e(t){var i=j(this.element);if(!t){i.removeData("_"+v)}i.removeClass("jq-hidden");if(this.customElement!==undefined){this.customElement.destroy()}},reinitialize:function e(t){this.destroy(true);this.options=j.extend(true,{},this.options,t);this.locales=j.extend(true,{},this.locales,this.options.locales);this.init()}};j.fn[v]=function(t){var i=arguments;if(t===undefined||_typeof(t)==="object"){this.each(function(){if(!j.data(this,"_"+v)){j.data(this,"_"+v,new n(this,t))}}).promise().done(function(){var e=j(this[0]).data("_"+v);if(e){e.options.onFormStyled.call()}});return this}else if(typeof t==="string"&&t[0]!=="_"&&t!=="init"){var s=undefined;this.each(function(){var e=j.data(this,"_"+v);if(e instanceof n&&typeof e[t]==="function"){s=e[t].apply(e,Array.prototype.slice.call(i,1))}});return s!==undefined?s:this}};var C=function(){return{initEvent:false,init:function e(){this.initEvent=true;j(document).on("click",function(e){if(!j(e.target).parents().hasClass("jq-selectbox")&&e.target.nodeName!=="OPTION"&&j(".jq-selectbox.opened").length){j(".jq-selectbox.opened").triggerHandler("dropdown:close")}});j(document).on("focus","select, input, textarea, button, a",function(e){var t=j(".jq-selectbox.opened"),i=j(e.currentTarget).parents(".jq-selectbox");if(t.get(0)===i.get(0)){return}t.triggerHandler("dropdown:close")})},preventScrolling:function e(t){var i=t.prop("scrollHeight")-t.outerHeight();var s=null,o=null;t.off("mousewheel DOMMouseScroll").on("mousewheel DOMMouseScroll",function(e){s=e.originalEvent.detail<0||e.originalEvent.wheelDelta>0?1:-1;o=t.scrollTop();if(o>=i&&s<0||o<=0&&s>0){e.stopPropagation();e.preventDefault()}});return this},makeList:function e(t){var i=j("<ul>");for(var s=0;s<t.length;s++){var o=t.eq(s),n=(o.attr("id")||"")!==""?o.attr("id")+c:"",r=o.attr("title");var l=o.attr("class")||"";if(o.is(":selected")){l+=(l!==""?" ":"")+"selected sel"}if(o.is(":disabled")){l+=(l!==""?" ":"")+"disabled"}var a={title:r,data:o.data(),html:o.html()};if(n!==""){a["id"]=n}if(o.parent().is("optgroup")){var d="";if(o.parent().attr("class")!==undefined){d=" "+o.parent().attr("class")}if(o.is(":first-child")){j("<li>",{class:"optgroup"+d,html:o.parent().attr("label")}).appendTo(i)}j("<li>",j.extend(a,{class:"option"})).addClass(l).addClass(d).data("jqfs-class",o.attr("class")).appendTo(i)}else{j("<li>",a).addClass(l).data("jqfs-class",o.attr("class")).appendTo(i)}}return i}}}();j.fn.commonParents=function(){var e=this;return e.first().parents().filter(function(){return j(this).find(e).length===e.length})};j.fn.commonParent=function(){return j(this).commonParents().first()}});