-
Notifications
You must be signed in to change notification settings - Fork 4
/
cuteform.min.js
2 lines (2 loc) · 2.72 KB
/
cuteform.min.js
1
2
/* By db0 ([email protected], http://db0.fr/) Source/Licence https://github.com/db0company/CuteForm */
function cuteformhtml(t,e){var a=t.val(),o=t.text(),c=void 0!==e.images&&void 0!==e.images[a]?e.images[a]:void 0!==t.attr("data-cuteform-image")?t.attr("data-cuteform-image"):null;if(null!==c)return $('<img class="cuteform-elt" src="'+c+'" data-cuteform-val="'+a+'" data-cuteform-text="'+o+'">');var d=void 0!==e.html&&void 0!==e.html[a]?e.html[a]:void 0!==t.attr("data-cuteform-html")?t.attr("data-cuteform-html"):a;return $('<div class="cuteform-elt" data-cuteform-val="'+a+'" data-cuteform-text="'+o+'">'+d+"</div>")}function cuteform(t,e){var a,o;e=void 0===e?{}:e;t.addClass("cuteform-select");var c="true"==e.modal||"true"==t.attr("data-cuteform-modal"),d="true"==e["modal-text"]||"true"==t.attr("data-cuteform-modal-text"),r=e.title||t.attr("data-cuteform-title"),l=e.name||t.attr("data-cuteform-name")||t.selector.split(" ").reverse()[0].replace(/[^_a-zA-Z0-9-]/g,"");if(a=$('<div class="cuteform" data-cuteform-name="'+l+'">'+(m||c?"":"<br>")+"</div>"),t.after(a),c){o=$("#cuteform-modal");var f=$('<button type="button" class="cuteform-modal-button"></button>');t.after(f),t.hide(),a.hide()}else{var m=!(void 0!==e.hide&&"false"==e.hide.toString()||"false"==t.attr("data-cuteform-hide"));m&&t.hide()}t.find("option").each(function(){var r=$(this),l=cuteformhtml(r,e);a.append(l),r.val()==t.find("option:selected").first().val()&&l.addClass("cuteform-selected"),l.click(function(e){t.val(l.attr("data-cuteform-val")),t.trigger("change"),a.find(".cuteform-elt").removeClass("cuteform-selected"),l.addClass("cuteform-selected"),c&&(f.text(""),d?f.append('<span class="cuteform-modal-text">'+a.find(".cuteform-selected").attr("data-cuteform-text")+"</span>"):f.append(a.find(".cuteform-selected").clone(!0).off()),o.modal("hide"))})}),c&&(d?f.append('<span class="cuteform-modal-text">'+a.find(".cuteform-selected").attr("data-cuteform-text")+"</span>"):f.append(a.find(".cuteform-selected").clone(!0).off()),f.click(function(t){t.preventDefault(),o.css("display","block"),o.find(".modal-body").text("");var e=a.clone(!0);e.show(),o.find(".modal-body").append(e),r&&o.find(".modal-title").length>0&&o.find(".modal-title").text(r),o.modal(),o.on("hidden.bs.modal",function(t){o.css("display","none")})})),t.change(function(){a.find(".cuteform-elt").removeClass("cuteform-selected"),a.find("[data-cuteform-val="+t.find("option:selected").first().val()+"]").addClass("cuteform-selected")})}function cuteformclear(){$(".cuteform").remove(),$(".cuteform-selected").removeClass("cuteform-selected"),$(".cuteform-select").show(),$(".cuteform-select").removeClass("cuteform-select")}$(document).ready(function(){$("select[data-cuteform=true]").each(function(){cuteform($(this))})});