/* * jQuery Form Styler v2.0.2 * https://github.com/Dimox/jQueryFormStyler * * Copyright 2012-2017 Dimox (http://dimox.name/) * Released under the MIT license. * * Date: 2017.10.22 * */ (function(b){"function"===typeof define&&define.amd?define(["jquery"],b):"object"===typeof exports?module.exports=b($||require("jquery")):b(jQuery)})(function(b){function x(c,a){this.element=c;this.options=b.extend({},Q,a);var e=this.options.locale;void 0!==this.options.locales[e]&&b.extend(this.options,this.options.locales[e]);this.init()}function D(c){if(!b(c.target).parents().hasClass("jq-selectbox")&&"OPTION"!=c.target.nodeName&&b("div.jq-selectbox.opened").length){c=b("div.jq-selectbox.opened"); var a=b("div.jq-selectbox__search input",c),e=b("div.jq-selectbox__dropdown",c);c.find("select").data("_styler").options.onSelectClosed.call(c);a.length&&a.val("").keyup();e.hide().find("li.sel").addClass("selected");c.removeClass("focused opened dropup dropdown")}}var Q={idSuffix:"-styler",filePlaceholder:"\u0424\u0430\u0439\u043b \u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d",fileBrowse:"\u041e\u0431\u0437\u043e\u0440...",fileNumber:"\u0412\u044b\u0431\u0440\u0430\u043d\u043e \u0444\u0430\u0439\u043b\u043e\u0432: %s", selectPlaceholder:"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435...",selectSearch:!1,selectSearchLimit:10,selectSearchNotFound:"\u0421\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e",selectSearchPlaceholder:"\u041f\u043e\u0438\u0441\u043a...",selectVisibleOptions:0,selectSmartPositioning:!0,locale:"ru",locales:{en:{filePlaceholder:"No file selected",fileBrowse:"Browse...",fileNumber:"Selected files: %s",selectPlaceholder:"Select...", selectSearchNotFound:"No matches found",selectSearchPlaceholder:"Search..."}},onSelectOpened:function(){},onSelectClosed:function(){},onFormStyled:function(){}};x.prototype={init:function(){function c(){void 0!==a.attr("id")&&""!==a.attr("id")&&(this.id=a.attr("id")+e.idSuffix);this.title=a.attr("title");this.classes=a.attr("class");this.data=a.data()}var a=b(this.element),e=this.options,t=navigator.userAgent.match(/(iPad|iPhone|iPod)/i)&&!navigator.userAgent.match(/(Windows\sPhone)/i)?!0:!1,x=navigator.userAgent.match(/Android/i)&& !navigator.userAgent.match(/(Windows\sPhone)/i)?!0:!1;if(a.is(":checkbox")){var A=function(){var e=new c,d=b('
').attr({id:e.id,title:e.title}).addClass(e.classes).data(e.data);a.after(d).prependTo(d);a.is(":checked")&&d.addClass("checked");a.is(":disabled")&&d.addClass("disabled");d.click(function(b){b.preventDefault();a.triggerHandler("click");d.is(".disabled")||(a.is(":checked")?(a.prop("checked",!1),d.removeClass("checked")):(a.prop("checked", !0),d.addClass("checked")),a.focus().change())});a.closest("label").add('label[for="'+a.attr("id")+'"]').on("click.styler",function(a){b(a.target).is("a")||b(a.target).closest(d).length||(d.triggerHandler("click"),a.preventDefault())});a.on("change.styler",function(){a.is(":checked")?d.addClass("checked"):d.removeClass("checked")}).on("keydown.styler",function(a){32==a.which&&d.click()}).on("focus.styler",function(){d.is(".disabled")||d.addClass("focused")}).on("blur.styler",function(){d.removeClass("focused")})}; A();a.on("refresh",function(){a.closest("label").add('label[for="'+a.attr("id")+'"]').off(".styler");a.off(".styler").parent().before(a).remove();A()})}else if(a.is(":radio")){var K=function(){var e=new c,d=b('
').attr({id:e.id,title:e.title}).addClass(e.classes).data(e.data);a.after(d).prependTo(d);a.is(":checked")&&d.addClass("checked");a.is(":disabled")&&d.addClass("disabled");b.fn.commonParents=function(){var a=this;return a.first().parents().filter(function(){return b(this).find(a).length=== a.length})};b.fn.commonParent=function(){return b(this).commonParents().first()};d.click(function(c){c.preventDefault();a.triggerHandler("click");d.is(".disabled")||(c=b('input[name="'+a.attr("name")+'"]'),c.commonParent().find(c).prop("checked",!1).parent().removeClass("checked"),a.prop("checked",!0).parent().addClass("checked"),a.focus().change())});a.closest("label").add('label[for="'+a.attr("id")+'"]').on("click.styler",function(a){b(a.target).is("a")||b(a.target).closest(d).length||(d.triggerHandler("click"), a.preventDefault())});a.on("change.styler",function(){a.parent().addClass("checked")}).on("focus.styler",function(){d.is(".disabled")||d.addClass("focused")}).on("blur.styler",function(){d.removeClass("focused")})};K();a.on("refresh",function(){a.closest("label").add('label[for="'+a.attr("id")+'"]').off(".styler");a.off(".styler").parent().before(a).remove();K()})}else if(a.is(":file")){var M=function(){var v=new c,d=a.data("placeholder");void 0===d&&(d=e.filePlaceholder);var k=a.data("browse");if(void 0=== k||""===k)k=e.fileBrowse;var f=b('
'+d+'
'+k+"
").attr({id:v.id,title:v.title}).addClass(v.classes).data(v.data);a.after(f).appendTo(f);a.is(":disabled")&&f.addClass("disabled");var v=a.val(),l=b("div.jq-file__name",f);v&&l.text(v.replace(/.+[\\\/]/,""));a.on("change.styler",function(){var b=a.val();if(a.is("[multiple]")){var b="",c=a[0].files.length;0
').attr({id:e.id, title:e.title}).addClass(e.classes).data(e.data);a.after(d).prependTo(d).wrap('
');a.is(":disabled")&&d.addClass("disabled");var k,f,l,t=null,L=null;void 0!==a.attr("min")&&(k=a.attr("min"));void 0!==a.attr("max")&&(f=a.attr("max"));l=void 0!==a.attr("step")&&b.isNumeric(a.attr("step"))?Number(a.attr("step")):Number(1);var h=function(c){var h=a.val(),d;b.isNumeric(h)||(h=0,a.val("0"));c.is(".minus")?d=Number(h)-l:c.is(".plus")&&(d=Number(h)+l);c=(l.toString().split(".")[1]|| []).length;if(0=k&&d<=f&&a.val(d):b.isNumeric(k)&&!b.isNumeric(f)?d>=k&&a.val(d):!b.isNumeric(k)&&b.isNumeric(f)?d<=f&&a.val(d):a.val(d)};d.is(".disabled")||(d.on("mousedown","div.jq-number__spin",function(){var a=b(this);h(a);t=setTimeout(function(){L=setInterval(function(){h(a)},40)},350)}).on("mouseup mouseout","div.jq-number__spin",function(){clearTimeout(t);clearInterval(L)}).on("mouseup","div.jq-number__spin", function(){a.change().trigger("input")}),a.on("focus.styler",function(){d.addClass("focused")}).on("blur.styler",function(){d.removeClass("focused")}))};N();a.on("refresh",function(){a.off(".styler").closest(".jq-number").before(a).remove();N()})}else if(a.is("select")){var P=function(){function v(a){var b=a.prop("scrollHeight")-a.outerHeight(),d=null,c=null;a.off("mousewheel DOMMouseScroll").on("mousewheel DOMMouseScroll",function(e){d=0>e.originalEvent.detail||0=b&&0>d||0>=c&&0"+b.html()+"";b.parent().is("optgroup")&&(void 0!==b.parent().attr("class")&&(g=" "+b.parent().attr("class")),d=""+b.html()+"",b.is(":first-child")&&(d='
  • '+b.parent().attr("label")+"
  • "+d));E+=d}}function k(){var f=new c,h="",y=a.data("placeholder"), m=a.data("search"),k=a.data("search-limit"),F=a.data("search-not-found"),q=a.data("search-placeholder"),w=a.data("smart-positioning");void 0===y&&(y=e.selectPlaceholder);if(void 0===m||""===m)m=e.selectSearch;if(void 0===k||""===k)k=e.selectSearchLimit;if(void 0===F||""===F)F=e.selectSearchNotFound;void 0===q&&(q=e.selectSearchPlaceholder);if(void 0===w||""===w)w=e.selectSmartPositioning;var g=b('
    ').attr({id:f.id, title:f.title}).addClass(f.classes).data(f.data);a.after(g).prependTo(g);var B=g.css("z-index"),B=0
    '+F+"
    ");var n=b('
    '+h+"
      "+E+"
    ");g.append(n);var r=b("ul",n),p=b("li",n),x=b("input",n),I=b("div.jq-selectbox__not-found", n).hide();p.lengthC&&(C=a.innerWidth(),A=a.width())});p.css({display:""});u.is(".placeholder")&&u.width()>C?u.width(u.width()):(h=g.clone().appendTo("body").width("auto"),m=h.outerWidth(),h.remove(),m==g.outerWidth()&&u.width(A));C>g.width()&&n.width(C);""===l.first().text()&&""!== a.data("placeholder")&&p.first().hide();var J=g.outerHeight(!0),G=x.parent().outerHeight(!0)||0,z=r.css("max-height"),h=p.filter(".selected");1>h.length&&p.first().addClass("selected sel");void 0===p.data("li-height")&&(m=p.outerHeight(),!1!==y&&(m=p.eq(1).outerHeight()),p.data("li-height",m));var H=n.css("top");"auto"==n.css("left")&&n.css({left:0});"auto"==n.css("top")&&(n.css({top:J}),H=J);n.hide();h.length&&(l.first().text()!=f.text()&&g.addClass("changed"),g.data("jqfs-class",h.data("jqfs-class")), g.addClass(h.data("jqfs-class")));if(a.is(":disabled"))return g.addClass("disabled"),!1;O.click(function(){b("div.jq-selectbox").filter(".opened").length&&e.onSelectClosed.call(b("div.jq-selectbox").filter(".opened"));a.focus();if(!t){var d=b(window),c=p.data("li-height"),h=g.offset().top,f=d.height()-J-(h-d.scrollTop()),q=a.data("visible-options");if(void 0===q||""===q)q=e.selectVisibleOptions;var k=5*c,m=c*q;0q&&(k=m);0===q&&(m="auto");var q=function(){n.height("auto").css({bottom:"auto", top:H});var a=function(){r.css("max-height",Math.floor((f-20-G)/c)*c)};a();r.css("max-height",m);"none"!=z&&r.css("max-height",z);fk+G+20?(q(),g.removeClass("dropup").addClass("dropdown")):(u(),g.removeClass("dropdown").addClass("dropup")): !1===w||0===w?f>k+G+20&&(q(),g.removeClass("dropup").addClass("dropdown")):(n.height("auto").css({bottom:"auto",top:H}),r.css("max-height",m),"none"!=z&&r.css("max-height",z));g.offset().left+n.outerWidth()>d.width()&&n.css({left:"auto",right:0});b("div.jqselect").css({zIndex:B-1}).removeClass("opened");g.css({zIndex:B});n.is(":hidden")?(b("div.jq-selectbox__dropdown:visible").hide(),n.show(),g.addClass("opened focused"),e.onSelectOpened.call(g)):(n.hide(),g.removeClass("opened dropup dropdown"), b("div.jq-selectbox").filter(".opened").length&&e.onSelectClosed.call(g));x.length&&(x.val("").keyup(),I.hide(),x.keyup(function(){var c=b(this).val();p.each(function(){b(this).html().match(new RegExp(".*?"+c+".*?","i"))?b(this).show():b(this).hide()});""===l.first().text()&&""!==a.data("placeholder")&&p.first().hide();1>p.filter(":visible").length?I.show():I.hide()}));p.filter(".selected").length&&(""===a.val()?r.scrollTop(0):(0!==r.innerHeight()/c%2&&(c/=2),r.scrollTop(r.scrollTop()+p.filter(".selected").position().top- r.innerHeight()/2+c)));v(r)}});p.hover(function(){b(this).siblings().removeClass("selected")});p.filter(".selected").text();p.filter(":not(.disabled):not(.optgroup)").click(function(){a.focus();var c=b(this),d=c.text();if(!c.is(".selected")){var q=c.index(),q=q-c.prevAll(".optgroup").length;c.addClass("selected sel").siblings().removeClass("selected sel");l.prop("selected",!1).eq(q).prop("selected",!0);u.text(d);g.data("jqfs-class")&&g.removeClass(g.data("jqfs-class"));g.data("jqfs-class",c.data("jqfs-class")); g.addClass(c.data("jqfs-class"));a.change()}n.hide();g.removeClass("opened dropup dropdown");e.onSelectClosed.call(g)});n.mouseout(function(){b("li.sel",n).addClass("selected")});a.on("change.styler",function(){u.text(l.filter(":selected").text()).removeClass("placeholder");p.removeClass("selected sel").not(".optgroup").eq(a[0].selectedIndex).addClass("selected sel");l.first().text()!=p.filter(".selected").text()?g.addClass("changed"):g.removeClass("changed")}).on("focus.styler",function(){g.addClass("focused"); b("div.jqselect").not(".focused").removeClass("opened dropup dropdown").find("div.jq-selectbox__dropdown").hide()}).on("blur.styler",function(){g.removeClass("focused")}).on("keydown.styler keyup.styler",function(b){var c=p.data("li-height");""===a.val()?u.text(y).addClass("placeholder"):u.text(l.filter(":selected").text());p.removeClass("selected sel").not(".optgroup").eq(a[0].selectedIndex).addClass("selected sel");if(38==b.which||37==b.which||33==b.which||36==b.which)""===a.val()?r.scrollTop(0): r.scrollTop(r.scrollTop()+p.filter(".selected").position().top);40!=b.which&&39!=b.which&&34!=b.which&&35!=b.which||r.scrollTop(r.scrollTop()+p.filter(".selected").position().top-r.innerHeight()+c);13==b.which&&(b.preventDefault(),n.hide(),g.removeClass("opened dropup dropdown"),e.onSelectClosed.call(g))}).on("keydown.styler",function(a){32==a.which&&(a.preventDefault(),O.click())});D.registered||(b(document).on("click",D),D.registered=!0)}function f(){var e=new c,h=b('
    ').attr({id:e.id, title:e.title}).addClass(e.classes).data(e.data);a.after(h);d();h.append("
      "+E+"
    ");var f=b("ul",h),m=b("li",h),e=a.attr("size"),k=f.outerHeight(),t=m.outerHeight();void 0!==e&&0h.height()&&(f.css("overflowY","scroll"),v(f),m.filter(".selected").length&&f.scrollTop(f.scrollTop()+m.filter(".selected").position().top));a.prependTo(h);if(a.is(":disabled"))h.addClass("disabled"),l.each(function(){b(this).is(":selected")&&m.eq(b(this).index()).addClass("selected")}); else if(m.filter(":not(.disabled):not(.optgroup)").click(function(c){a.focus();var d=b(this);c.ctrlKey||c.metaKey||d.addClass("selected");c.shiftKey||d.addClass("first");c.ctrlKey||c.metaKey||c.shiftKey||d.siblings().removeClass("selected first");if(c.ctrlKey||c.metaKey)d.is(".selected")?d.removeClass("selected first"):d.addClass("selected first"),d.siblings().removeClass("first");if(c.shiftKey){var e=!1,f=!1;d.siblings().removeClass("selected").siblings(".first").addClass("selected");d.prevAll().each(function(){b(this).is(".first")&& (e=!0)});d.nextAll().each(function(){b(this).is(".first")&&(f=!0)});e&&d.prevAll().each(function(){if(b(this).is(".selected"))return!1;b(this).not(".disabled, .optgroup").addClass("selected")});f&&d.nextAll().each(function(){if(b(this).is(".selected"))return!1;b(this).not(".disabled, .optgroup").addClass("selected")});1==m.filter(".selected").length&&d.addClass("first")}l.prop("selected",!1);m.filter(".selected").each(function(){var a=b(this),c=a.index();a.is(".option")&&(c-=a.prevAll(".optgroup").length); l.eq(c).prop("selected",!0)});a.change()}),l.each(function(a){b(this).data("optionIndex",a)}),a.on("change.styler",function(){m.removeClass("selected");var a=[];l.filter(":selected").each(function(){a.push(b(this).data("optionIndex"))});m.not(".optgroup").filter(function(c){return-1h.height())a.on("keydown.styler",function(a){38!=a.which&&37!=a.which&& 33!=a.which||f.scrollTop(f.scrollTop()+m.filter(".selected").position().top-t);40!=a.which&&39!=a.which&&34!=a.which||f.scrollTop(f.scrollTop()+m.filter(".selected:last").position().top-f.innerHeight()+2*t)})}var l=b("option",a),E="";a.is("[multiple]")?x||t||f():k()};P();a.on("refresh",function(){a.off(".styler").parent().before(a).remove();P()})}else if(a.is(":reset"))a.on("click",function(){setTimeout(function(){a.closest("form").find("input, select").trigger("refresh")},1)})},destroy:function(){var c= b(this.element);c.is(":checkbox")||c.is(":radio")?(c.removeData("_styler").off(".styler refresh").removeAttr("style").parent().before(c).remove(),c.closest("label").add('label[for="'+c.attr("id")+'"]').off(".styler")):c.is('input[type="number"]')?c.removeData("_styler").off(".styler refresh").closest(".jq-number").before(c).remove():(c.is(":file")||c.is("select"))&&c.removeData("_styler").off(".styler refresh").removeAttr("style").parent().before(c).remove()}};b.fn.styler=function(c){var a=arguments; if(void 0===c||"object"===typeof c)return this.each(function(){b.data(this,"_styler")||b.data(this,"_styler",new x(this,c))}).promise().done(function(){var a=b(this[0]).data("_styler");a&&a.options.onFormStyled.call()}),this;if("string"===typeof c&&"_"!==c[0]&&"init"!==c){var e;this.each(function(){var t=b.data(this,"_styler");t instanceof x&&"function"===typeof t[c]&&(e=t[c].apply(t,Array.prototype.slice.call(a,1)))});return void 0!==e?e:this}};D.registered=!1});