-
Notifications
You must be signed in to change notification settings - Fork 4
/
dialpad.min.js
1 lines (1 loc) · 6.7 KB
/
dialpad.min.js
1
(function(){function WildEmitter(){this.callbacks={}}WildEmitter.prototype.on=function(e,t,n){var r=arguments.length===3,i=r?arguments[1]:undefined,s=r?arguments[2]:arguments[1];return s._groupName=i,(this.callbacks[e]=this.callbacks[e]||[]).push(s),this},WildEmitter.prototype.once=function(e,t){function r(){n.off(e,r),t.apply(this,arguments)}var n=this;return this.on(e,r),this},WildEmitter.prototype.releaseGroup=function(e){var t,n,r,i;for(t in this.callbacks){i=this.callbacks[t];for(n=0,r=i.length;n<r;n++)i[n]._groupName===e&&(i.splice(n,1),n--,r--)}return this},WildEmitter.prototype.off=function(e,t){var n=this.callbacks[e],r;return n?arguments.length===1?(delete this.callbacks[e],this):(r=n.indexOf(t),n.splice(r,1),this):this},WildEmitter.prototype.emit=function(e){var t=[].slice.call(arguments,1),n=this.callbacks[e],r=this.getWildcardCallbacks(e),i,s,o;if(n)for(i=0,s=n.length;i<s;++i)n[i].apply(this,t);if(r)for(i=0,s=r.length;i<s;++i)r[i].apply(this,[e].concat(t));return this},WildEmitter.prototype.getWildcardCallbacks=function(e){var t,n,r=[];for(t in this.callbacks){n=t.split("*");if(t==="*"||n.length===2&&e.slice(0,n[1].length)===n[1])r=r.concat(this.callbacks[t])}return r};var jade=function(e){function t(e){return e!=null}return Array.isArray||(Array.isArray=function(e){return"[object Array]"==Object.prototype.toString.call(e)}),Object.keys||(Object.keys=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t}),e.merge=function(n,r){var i=n["class"],s=r["class"];if(i||s)i=i||[],s=s||[],Array.isArray(i)||(i=[i]),Array.isArray(s)||(s=[s]),i=i.filter(t),s=s.filter(t),n["class"]=i.concat(s).join(" ");for(var o in r)o!="class"&&(n[o]=r[o]);return n},e.attrs=function(n,r){var i=[],s=n.terse;delete n.terse;var o=Object.keys(n),u=o.length;if(u){i.push("");for(var a=0;a<u;++a){var f=o[a],l=n[f];"boolean"==typeof l||null==l?l&&(s?i.push(f):i.push(f+'="'+f+'"')):0==f.indexOf("data")&&"string"!=typeof l?i.push(f+"='"+JSON.stringify(l)+"'"):"class"==f&&Array.isArray(l)?i.push(f+'="'+e.escape(l.join(" "))+'"'):r&&r[f]?i.push(f+'="'+e.escape(l)+'"'):i.push(f+'="'+l+'"')}}return i.join(" ")},e.escape=function(t){return String(t).replace(/&(?!(\w+|\#\d+);)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},e.rethrow=function(t,n,r){if(!n)throw t;var i=3,s=require("fs").readFileSync(n,"utf8"),o=s.split("\n"),u=Math.max(r-i,0),a=Math.min(o.length,r+i),i=o.slice(u,a).map(function(e,t){var n=t+u+1;return(n==r?" > ":" ")+n+"| "+e}).join("\n");throw t.path=n,t.message=(n||"Jade")+":"+r+"\n"+i+"\n\n"+t.message,t},e}({}),template=function anonymous(locals,attrs,escape,rethrow,merge){attrs=attrs||jade.attrs,escape=escape||jade.escape,rethrow=rethrow||jade.rethrow,merge=merge||jade.merge;var buf=[];with(locals||{}){var interp,__indent=[];buf.push('\n<div id="screen">\n <div class="dialerwrapper">\n <div class="numberEntry"></div>\n <ul id="dialpad">\n <li>\n <button data-value="1">\n <p>1</p>\n <div> </div>\n </button>\n <button data-value="2">\n <p>2</p>\n <div>abc</div>\n </button>\n <button data-value="3">\n <p>3</p>\n <div>def</div>\n </button>\n </li>\n <li>\n <button data-value="4">\n <p>4</p>\n <div>ghi</div>\n </button>\n <button data-value="5">\n <p>5</p>\n <div>jki</div>\n </button>\n <button data-value="6">\n <p>6</p>\n <div>mno</div>\n </button>\n </li>\n <li>\n <button data-value="7">\n <p>7</p>\n <div>pqrs</div>\n </button>\n <button data-value="8">\n <p>8</p>\n <div>tuv</div>\n </button>\n <button data-value="9">\n <p>9</p>\n <div>wxyz</div>\n </button>\n </li>\n <li>\n <button data-value="#">\n <p>#</p>\n <div> </div>\n </button>\n <button data-value="0">\n <p>0</p>\n <div>abc</div>\n </button>\n <button data-value="del">\n <p>⌫</p>\n <div></div>\n </button>\n </li>\n </ul>\n </div>'),locals.footer&&buf.push('\n <footer>\n <nav id="actions"><a class="call">Call</a></nav>\n </footer>'),buf.push("\n</div>")}return buf.join("")},phoney=window.ATT&&window.ATT.phoneNumber||window.phoney,Dialpad=function(e){var t=e||{},n={onHide:"hide",onPress:"press",onCallableNumber:"callableNumber",onCall:"call"};WildEmitter.call(this),this.number="",this.footer=!0;for(var r in n)t[r]&&this.on(n[r],t[r])};Dialpad.prototype=new WildEmitter,Dialpad.prototype.render=function(e){return this.dom=this.domify(template(this)),this.addClickHandlers(),this.numberField=this.dom.querySelector(".numberEntry"),this.clear(),this.addDocListener(),this.dom},Dialpad.prototype.hide=function(){this.removeDocListener(),this.dom.parentElement.removeChild(this.dom),this.emit("hide")},Dialpad.prototype.addDocListener=function(){var e=this;this.boundKeyHandler=function(){e.handleKeyDown.apply(e,arguments)},document.addEventListener("keydown",this.boundKeyHandler,!0)},Dialpad.prototype.removeDocListener=function(){document.removeEventListener("keydown",this.boundKeyHandler,!0)},Dialpad.prototype.addClickHandlers=function(){var e=this,t=this.dom.querySelectorAll("button"),n=this.dom.querySelector(".call");Array.prototype.forEach.call(t,function(t){t.addEventListener("click",function(t){var n=this.attributes["data-value"],r=n&&n.nodeValue;return r=="del"?e.removeLastNumber():e.addNumber(r),!1},!0)}),n&&n.addEventListener("click",function(){e.handleCallClick.apply(e,arguments)},!1)},Dialpad.prototype.handleKeyDown=function(e){var t,n=e.which;n>=48&&n<=57&&(t=n-48,this.addNumber(t+"")),n===8&&(this.removeLastNumber(),e.preventDefault()),n===13&&this.handleCallClick(e)},Dialpad.prototype.getNumber=function(){return this.number},Dialpad.prototype.setNumber=function(e){var t=phoney.parse(e),n=this.number,r=phoney.getCallable(t);this.number=t,this.numberField.innerHTML=phoney.stringify(this.number),r&&this.emit("callableNumber",r)},Dialpad.prototype.addNumber=function(e){var t=this.getNumber()+""+e;this.emit("press",e),this.setNumber(t)},Dialpad.prototype.removeLastNumber=function(){this.setNumber(this.getNumber().slice(0,-1)),this.emit("press","del")},Dialpad.prototype.clear=function(){this.setNumber("")},Dialpad.prototype.domify=function(e){var t=document.createElement("div");return t.innerHTML=e,t.firstElementChild},Dialpad.prototype.handleCallClick=function(e){return e.preventDefault(),this.emit("call",this.number,!!phoney.getCallable(this.number)),!1},typeof module!="undefined"?module.exports=Dialpad:typeof define=="function"&&define.amd?define(Dialpad):window.Dialpad=Dialpad})(window)