raspberry-pi-absensi/assets/plugin/popover/jquery.popSelect.min.js

9 lines
8.0 KiB
JavaScript
Raw Permalink Normal View History

/*
* popselect - v0.1.14
* Replaces traditional <select> with a options from popover
* http://jquer.in/popselect
*
* Made by Jay Kanakiya
* Under MIT License
*/
!function(a,b,c){"use strict";function d(b,c){this.element=b,this.settings=a.extend({},o,c),this._defaults=o,this._name=n,this.init()}function e(a,b){for(var c in b)a=a.replace(new RegExp("{"+c+"}","g"),b[c]);return a}function f(a){return"."+a}function g(a){return a?'<div class="{'+a+'}"></div>':'<div class="{wrapper}"></div>'}function h(a){for(var b="",c=0;c<a.length;c++)a[c].selected&&(b+=j(a[c].val,a[c].text));return b}function i(a,b){return e('<div class="{tagWrapper}"><textarea class="{selectTextarea}"></textarea><ul class="{selectTags}">{tags}</ul><div class="{placeholderText}">{text}</div></div>',{tags:h(b),text:a,placeholderText:p.placeholderText,tagWrapper:p.tagWrapper,selectTextarea:p.selectTextarea,selectTags:p.selectTags})}function j(a,b){return e('<li class="{tag}" data-value="{val}" data-text="{text}"><span class="{popoverClose}">&times;</span>{text}</li>',{text:b,val:a,tag:p.tag,popoverClose:p.popoverClose})}function k(a,b){return e('<li data-value="{val}" data-text="{text}">{text}</li>',{val:a,text:b})}function l(){return e('<li class="{placeholder}"><div><input type="text" readonly="true"></div></li>',{placeholder:p.placeholder})}function m(a,b){return e('<div class="{popoverSelect} {top}">'+(b.showTitle?'<h3 class="{selectTitle}">{title}</h3>':"")+'<div class="{popoverBody}"><ul class="{selectList}">{list}</ul></div><div class="{arrow}"></div></div>',{title:b.title,list:a,arrow:p.arrow,popoverSelect:p.popoverSelect,popoverBody:p.popoverBody,selectList:p.selectList,top:b.position,selectTitle:p.selectTitle})}var n="popSelect",o={position:"top",showTitle:!0,autoIncrease:!0,title:"Select Multiple Options",debug:!1,maxAllowed:0,placeholderText:"Click to Add Values",autofocus:!1},p={tag:"tag",arrow:"arrow",selectWrapper:"popover-select-wrapper",tagWrapper:"popover-tag-wrapper",popoverSelect:"popover-select",popoverBody:"popover-select-body",selectTextarea:"popover-select-textarea",selectTags:"popover-select-tags",popoverClose:"popSelect-close",selectList:"popover-select-list",popoverDisabled:"disabled",placeholder:"placeholder",placeholderInput:"placeholder input",placeholderText:"placeholder-text",selectTitle:"popover-select-title",top:"top"},q={popoverGenerated:"PopSelect Code Generated",closeClicked:"Close button clicked",noElem:"No element to be removed",unSupported:"Not Supported",posChanged:"Position changed"},r={option:"option",blur:"blur",click:"click",mousedown:"mousedown",li:"li",attrVal:"data-value",attrText:"data-text",body:"BODY"};a.extend(d.prototype,{init:function(){var b=this;this.$elem=a(this.element),this.$options=this.$elem.children(r.option).map(function(b,c){return{val:a(c).val(),text:a(c).text(),selected:a(c).attr("selected")}}),this.$elem.wrap(e(g(),{wrapper:p.selectWrapper}));var c=this.getPosition(this.$elem);this.elemPos=c,this.$elem.parent(f(p.selectWrapper)).css({width:this.settings.width||c.width,height:c.height});var d=this.generatePopover(this.$options);b.log(q.popoverGenerated,d),this.$elem.after(d),this.$popover=this.$elem.next(f(p.popoverSelect)),this.$popover.css({top:0,left:0}),this.$elem.after(i(this.settings.placeholderText,this.$options)),this.$tagWrapper=this.$elem.next(f(p.tagWrapper)),this.baseHeight=this.$tagWrapper.height(),this.$inputTagField=this.$tagWrapper.find(f(p.selectTextarea)),this.$inputTagField.on(r.blur,function(){b.$popover.hide()}),this.$tags=this.$tagWrapper.find(f(p.selectTags)),this.$tags.on(r.click,this.initializePopover.bind(this)),this.$tags.next(f(p.placeholderText)).on(r.click,this.initializePopover.bind(this)),this.$tags.on(r.click,f(p.popoverClose),function(){b.inputToPopover(a(this))}),this.$popover.find(f(p.selectList)).on(r.mousedown,function(a){a.preventDefault()}).on(r.click,r.li,function(){b.popoverToInput(a(this))}),this.$elem.hide(),this.checkNumberOfTags(),this.changeSize(),this.$elem.trigger("popselect:init"),this.settings.autofocus&&this.initializePopover()},inputToPopover:function(a){var b=a.parent();this.log(q.closeClicked,b);var c=b.attr(r.attrVal),d=b.attr(r.attrText);this.appendToPopup(c,d),b.remove(),this.setPlaceholder(),th