viktor / vkalarm

// ==UserScript==
// @name         vkalarm
// @namespace    https://openuserjs.org/scripts/viktor/vkalarm
// @version      0.0.2
// @description  alarm for audio player on vk.com
// @author       Viktor Dakalov <atlantidu@gmail.com>
// @match        https://vk.com/*
// @match        http://vk.com/*
// @grant        none
// ==/UserScript==

(function(){var Knee={is:function(value,name){return window.toString.call(value)==="[object "+name+"]"},isBoolean:function(value){return this.is(value,"Boolean")},isElement:function(value){return value instanceof HTMLElement&&value.nodeType===1},isArray:function(value){return this.is(value,"Array")},isObject:function(value){return this.is(value,"Object")},isArguments:function(value){return this.is(value,"Arguments")},isFunction:function(value){return this.is(value,"Function")},isString:function(value){return this.is(value,"String")},isNumber:function(value){return this.is(value,"Number")},isFinite:function(value){return window.isFinite(value)},isRegExp:function(value){return this.is(value,"Regexp")},isNaN:function(value){return this.isNumber(value)&&value!==+value},isNull:function(value){return value===null},isUndefined:function(value){return value===undefined},get:function(value,typeTest,def){return typeTest.call(this,value)?value:def||undefined},each:function(obj,context,handler){var index=0,item,name;arguments.length===1&&(handler=obj,context=this,obj=this);arguments.length===2&&(handler=context,context=this);if(typeof obj==='object'&&obj!==null&&typeof handler==='function'){for(name in obj){if(obj.hasOwnProperty(name)&&(name!=='length'||!(obj instanceof Array||obj instanceof HTMLCollection||obj instanceof NodeList))){handler.call(context,obj[name],name,index++)}}}return obj},grep:function(obj,context,handler){var isArr,list;arguments.length===1&&(handler=obj,context=this,obj=this);arguments.length===2&&(handler=context,context=this);list=(isArr=obj instanceof Array)?[]:{};this.each(obj,context,function(value,key,index){if(handler.call(context,value,key,index)!==false){isArr?list.push(value):list[key]=value}});return list},collect:function(obj,context,handler){var isArr,list;arguments.length===1&&(handler=obj,context=this,obj=this);arguments.length===2&&(handler=context,context=this);list=(isArr=obj instanceof Array)?[]:{};this.each(obj,context,function(value,key,index){if((list[key]=handler.call(context,value,key,index))===false){isArr?(list.splice(key,1)):(delete list[key])}});return list},collectEntries:function(obj,context,handler){var list={},result;arguments.length===1&&(handler=obj,context=this,obj=this);arguments.length===2&&(handler=context,context=this);this.each(obj,context,function(value,key,index){result=handler.call(context,value,key,index);if(result!==false){list[result[0]]=result[1]}});return list},translate:function(source,destination,context,handler){arguments.length===3&&(handler=context,context=this);this.each(source,context,function(value,key,index){handler.call(context,destination,value,key,index)});return destination},repeat:function(number,context,handler){var list=[];arguments.length===1&&(handler=function(){},context=this);arguments.length===2&&(handler=context,context=this);this.each(new Array(number+1).join().split(/./),context,function(value,key,index){list.push(handler.call(context,index,key,index));if(list[list.length-1]===false){list.pop()}});return list},elem:function($el,attrs,content,parent){$el=$el instanceof HTMLElement?$el:document.createElement($el);Knee.each(attrs||{},function(value,key){$el.setAttribute(key,value)});if(content!=null){$el.innerHTML=content}if(parent instanceof HTMLElement){parent.appendChild($el)}return $el},elem_cls:function(el,classes){function mk(name){el.className+=(el.className&&el.className.length?" ":"")+name}function rm(name){el.className=el.className.replace(new RegExp("\\s?"+name+"\\s?")," ").trim()}if(classes===false){el.className=""}this.each(classes||{},function(flag,className){(rm(className)||true)&&flag&&mk(className)});return this.collectEntries(el.className?el.className.split(/\s+/):[],function(value){return value?[value,true]:false})},elem_get:function(selector,context){return this.get(context,this.isElement,document).querySelector(selector)},elem_gets:function(selector,context){return this.get(context,this.isElement,document).querySelectorAll(selector)},elem_before:function(newElement,beforeElement){if(this.isElement(beforeElement.parentNode)){beforeElement.parentNode.insertBefore(newElement,beforeElement)}},keys:function(object){return this.translate(object,[],this,function(dest,value,key){dest.push(key)})},values:function(object){return this.translate(object,[],function(dest,value){dest.push(value)})},random:(function(){var random=function(len,collection){len=arguments.length>0?len:8;collection=arguments.length>1?collection:random.ALPHABET+random.DIGIRAL;return this.repeat(len,function(){return collection[Math.floor(Math.random()*collection.length)]}).join("")};random.ALPHABET="abcdefghijklmnopqrstuvwxyz";random.DIGIRAL="0123456789";random.COMPLEX="!@#$%^&*()_+{},./\\;'\"`";random.FULL=random.ALPHABET+random.DIGIRAL+random.COMPLEX;return random}()),result:function(fnc,context,args){return this.isFunction(fnc)?fnc.apply(context||this,args||[]):fnc},clone:function(obj){return this.collect(obj,this,function(value){if(this.isArray(value)||(this.isObject(value)&&value.constructor.name==="Object")){return this.clone(value)}return value})},push:function(obj,key,value){if(this.isArray(obj)){obj[Knee.result(key)]=value}if(this.isObject(obj)){obj[Knee.result(key)]=value}return obj},on:function(el,event,context,handler){arguments.length===3&&(handler=context,context,this);if(this.isString(el)){el=this.eo.get(el)}if(this.isElement(el)||el instanceof Window||el instanceof Document){el.addEventListener(event,handler.bind(context))}},off:function(el,event,handler){if(this.isString(el)){el=this.eo.get(el)}if(this.isElement(el)){el.removeEventListener(event,handler)}},wait:function(rate,maxTimeOut,testFunction,handler){var isTrue=false,timer,self=this;function wrapHandler(){if(isTrue){handler.call(self)}}function wrapTest(){if(testFunction.call(self)){isTrue=true;timer.cancel()}}timer=new this.Timer({rate:rate,stop:maxTimeOut,onStop:wrapHandler},this,wrapTest)},idle:function(){},Timer:function(params,context,handler){arguments.length===2&&(handler=context,context=this);if(Knee.isNumber(params)){params={start:params}}var timers=new Array(3),self=this;function isStart(){return Knee.isNumber(params.start)&&params.start>=0}function isStop(){return Knee.isNumber(params.stop)&&params.stop>0}function isRate(){return Knee.isNumber(params.rate)&&params.rate>=0}if(isStart()||isRate()){timers[0]=setTimeout(run,(params.start||0)*1000)}function run(){if(Knee.isNumber(timers[0])){timers[0]=undefined}if(isRate()){if(!isStop()&&!(self instanceof Knee.Timer)){console.warn("The timer operates in periodically mode only if timer started through constructor");return cancel()}callback();timers[2]=setInterval(callback,params.rate*1000);if(Knee.isFunction(params.onStart)){params.onStart(self)}}else{callback()}if(isStop()){timers[1]=setTimeout(cancel,params.stop*1000)}}function cancel(){timers[0]&&(timers[0]=clearTimeout(timers[0]),undefined);timers[1]&&(timers[1]=clearTimeout(timers[1]),undefined);if(timers[2]){timers[2]=clearInterval(timers[2]),undefined;if(Knee.isFunction(params.onStop)){params.onStop(self)}}}function callback(){handler.call(context)}this.isActive=function(){return Knee.isNumber(timers[0])||Knee.isNumber(timers[2])};this.start=function(){run()};this.cancel=function(){cancel()}}};function KneeCore(core){Knee.each(core,this,function(value,key){this[key]=value})}KneeCore.prototype=Knee;Knee.each(Knee,function(value,key){KneeCore[key]=value});KneeCore.create=function(extend){function KneeApp(params){Knee.each(params,this,function(value,key){this[key]=value});Knee.result(this.initialize,this)}KneeApp.prototype=new KneeCore(extend);return KneeApp};window.Knee=KneeCore}());(function(){function Scope(data,localStorageKey){var storage=data||{},listeners=[],self=this,fires=[];function save(){if(Knee.isString(localStorageKey)){localStorage.setItem(localStorageKey,JSON.stringify(storage))}}function load(){if(Knee.isString(localStorageKey)&&localStorageKey in localStorage){return JSON.parse(localStorage.getItem(localStorageKey))}return{}}if(localStorageKey){Knee.each(load(),function(value,key){storage[key]=value});save()}function get(name,def){var names=name.split("."),lastName=names.pop(),context=storage;Knee.each(names,function(_name){(Knee.isObject(context)||Knee.isArray(context))&&(Knee.isObject(context[_name])||Knee.isArray(context[_name]))?(context=context[_name]):(context=undefined)});return(Knee.isObject(context)||Knee.isArray(context))&&lastName in context?context[lastName]:def}function set(name,value){var names=name.split("."),lastName=names.pop(),context=storage,old;Knee.each(names,function(_name){if(Knee.isObject(context[_name])||Knee.isArray(context[_name])){context=context[_name]}else if(!(_name in context)){context=context[_name]={}}});old=context[lastName];Knee.isFunction(context[lastName])?(context[lastName].apply(context,value)):(context[lastName]=value);fires.push({name:name,value:value,old:old})}function trigger(path,val,old){var listener;function triggerHandlers(listener){Knee.each(listener.handlers,function(handler){handler.handler.call(handler.context,val,old,self)})}listener=findListener(path);if(listener){triggerHandlers(listener)}}function findListener(path){return Knee.grep(listeners,function(_listener){return _listener.path===path})[0]}function on(path,context,handler){var listener=findListener(path);if(!listener){listener={path:path,handlers:[]}}listener.handlers.push({context:context||self,handler:handler});listeners.push(listener)}function off(path,handler){var listener=findListener(path);if(listener){if(Knee.isFunction(handler)){listener.handlers=Knee.grep(listener.handlers,function(_handler){return _handler.handler!==handler})}else{listener.handlers=[]}}}this.get=function(path,def){if(Knee.isString(path)){return get(path,def)}if(Knee.isArray(path)){return Knee.collect(path,function(name){return get(name,def)})}if(Knee.isObject(path)){return Knee.collectEntries(path,function(some,key){return[key,get(key,def)]})}return Knee.clone(storage)};this.set=function(path,value){if(Knee.isString(path)){path=Knee.push({},path,value)}if(Knee.isObject(path)){fires=[{name:"",old:Knee.clone(storage)}];Knee.each(path,function(value,path){set(path,value)});fires[0].value=Knee.clone(storage);save();setTimeout(function(){Knee.each(fires,function(obj){trigger(obj.name,obj.value,obj.old)})},0)}};this.has=function(path){var unique=Knee.random(16,Knee.random.FULL);return get(path,unique)===unique};this.on=function(path,context,handler){arguments.length===2&&(handler=context,context=this);if(Knee.isString(path)){path=[path]}Knee.each(path,function(path){on(path,context,handler)})};this.off=function(path,handler){if(arguments.length===0){listeners=[];return}if(Knee.isString(path)){path=[path]}Knee.each(path,function(path){off(path,handler)})}}function Styles(data,context,callContext){var $el=Knee.elem("style",{type:"text/css"},null,document.head),self=this,contextSelector=Knee.get(context,Knee.isString,""),scope=new Scope(data);scope.on("",update);function render(){var buffer=[],selector="selector",ref="@",space=" ",nl="\n",bo="{",bc="}",ind="\t",sep=": ",sc=";",cf="&";Knee.each(scope.get(),function(rules){var sel;if(selector in rules){sel=Knee.result(rules[selector],callContext||self);if(Knee.isString(contextSelector)&&Knee.isString(sel)){sel=Knee.collect(sel.split(","),function(s){return contextSelector+(s[0]===cf?s.substr(1):" "+s)}).join(", ")}buffer.push(sel);buffer.push(space);delete rules[selector]}buffer.push(bo);Knee.each(Knee.result(rules,callContext||self),function(value,rule){rule=rule.replace(/([A-Z])/g,"-$1").toLowerCase();value=Knee.result(value,callContext||self);value=Knee.isArray(value)?value.join(""):value;buffer.push(nl);buffer.push(ind);buffer.push(rule);buffer.push(sep);buffer.push(value);buffer.push(sc)});buffer.push(nl);buffer.push(bc);buffer.push(nl)});return buffer.join("")}function update(){$el.innerHTML=render()}this.get=scope.get.bind(scope);this.set=scope.set.bind(scope);this.destroy=function(){$el.parentNode.removeChild($el)};this.update=update;this.toString=render;update()}function Markup(data,model,context){var scope=new Scope(data),self=this;this.render=function(){var markup=scope.get();if(Knee.isObject(markup)){markup=[markup]}if(Knee.isArray(markup)){context.$el.innerHTML="";Knee.each(markup,this,function(element){this.nodeCreators.other.call(this,element,context.$el)})}};this.fromValue=function(value,args){value=Knee.result(value,context,args);if(Knee.isString(value)){value=value.replace(/\{\{(.+?)\}\}/g,function(m,g,r){return r=Knee.result(model.get(g,g),context),r==null?"":r}.bind(this))}return value};this.setters={other:[function($el,key,value){if(key in $el){$el[key]=value}}],tagName:function(){},children:function($el,key,value){Knee.each(value,this,function(child){var creator=child.tagName in self.nodeCreators?self.nodeCreators[child.tagName]:"other";self.nodeCreators[creator].call(this,child,$el)})},style:function($el,key,value){Knee.each(value,this,function(v,k,r){r=Knee.result(v,context,[$el]);$el.style[k]=Knee.isArray(r)?r.join(""):r})},checked:function($el,key,value){value===true&&$el.setAttribute(key,value)},disabled:function($el,key,value){if(value===true){$el.setAttribute("disabled","true")}},value:function($el,key,value){$el.setAttribute(key,value)},parentNode:function($el,key,value){var $parent=value;if(Knee.isString($parent)){$parent=Knee.elem_get($parent)}if(Knee.isElement($parent)){Knee.elem($el,null,null,$parent)}}};this.nodeCreators={other:function(obj,$parent){var $el=Knee.isString(obj.tagName)&&obj.tagName.length?Knee.elem(obj.tagName,null,null,$parent):null;if(Knee.isElement($el)){Knee.each(obj,this,function(value,key){value=key.substr(0,2)==="on"?(Knee.isFunction(value)?value.bind(context,$el):value):self.fromValue(value,[$el]);if(Knee.isFunction(self.setters[key])){self.setters[key].call(context,$el,key,value)}else{Knee.each(self.setters.other,this,function(handler){handler.call(context,$el,key,value)})}})}return $el}};this.scope=scope;this.render()}function isScope(value){return value instanceof Scope}function isStyles(value){return value instanceof Styles}function isMarkup(value){return value instanceof Markup}var app=Knee.create({isScope:isScope,isStyle:isStyles,isMarkup:isMarkup,mountType:0,initialize:function(){this.id=this.id||this.random(8,this.random.ALPHABET);this.$el=this.isElement(this.$el)?this.$el:this.elem(this.$el||"div",{id:this.id});this.remount();this.scope=new Scope(this.scope,this.scopeSyncKey);this.styles=new Styles(this.styles,"#"+this.id,this);this.globalStyles=new Styles(this.globalStyles,null,this);this.markup=new Markup(this.markup,this.scope,this);this.result(this.init,this)},remount:function(){var $point=this.result(this.mount);if(this.isString($point)){$point=this.elem_get(this.mount)}if(this.isElement($point)){switch(this.mountType){case 1:$point.children.length?this.elem_before(this.$el,$point.children.item(0)):this.elem(this.$el,null,null,$point);break;case 2:this.elem_before(this.$el,$point);break;case 3:var $sibling;this.each($point.parentNode.children,function(child){$sibling===$point?this.elem_before(this.$el,$sibling):($sibling=child)});if(this.isElement($sibling)){this.elem_before(this.$el,$sibling)}break;case 4:$point.innerHTML="";this.elem(this.$el,null,null,$point);break;default:this.elem(this.$el,null,null,$point);break}this.onMountAfter()}},onMountAfter:function(){},destroy:function(){this.styles.destroy();this.globalStyles.destroy();if(this.$el.parentNode){this.$el.parentNode.removeChild(this.$el)}}});app.MOUNT_INSIDE_LAST=0;app.MOUNT_INSIDE_FIRST=1;app.MOUNT_PREVIOUS=2;app.MOUNT_AFTER=3;app.MOUNT_OVERWRITE=4;app.Scope=Scope;app.Markup=Markup;app.Styles=Styles;window.KneeApp=app}());(function(){var audioDriver={isPlaying:function(){return window.audioPlayer&&window.audioPlayer.player&&!window.audioPlayer.player.paused()},getCurrentSongInfo:function(){var id=Knee.result(window.currentAudioId),songInfo=undefined;if(id){if(window.audioPlaylist&&id in window.audioPlaylist){songInfo=window.audioPlaylist[id]}else{songInfo=window.audioPlayer.getSongInfoFromDOM(id)}}return songInfo},play:function(songInfo){var id;if(!window.audioPlayer){stManager.add("audioplayer.js",audioDriver.play.bind(this,songInfo));return}if(!songInfo){try{id=window.currentAudioId()||window.geByClass1('audio',ge('pad_playlist')).id.substr(5).replace('_pad','');songInfo=window.audioPlaylist&&id in window.audioPlaylist?window.audioPlaylist[id]:window.audioPlayer.getSongInfoFromDOM(id)}catch(e){}}if(songInfo){window.playAudioNew(songInfo.full_id||songInfo.aid)}},stop:function(){window.audioPlayer.pauseTrack()}};new KneeApp({mount:"body",scopeSyncKey:"vkAlarm",appButton:new KneeApp({mount:"#side_bar ol",markup:{tagName:"li",children:[{tagName:"a",href:"javascript:",className:"left_row",onmousedown:function(){this.appParent.onButtonClick()},children:[{tagName:"span",className:"left_count_wrap fl_r",innerHTML:"2"},{tagName:"span",className:"left_label inl_bl",innerHTML:"Alarm"}]}]},update:function(){var len=this.appParent.scope.get("tasks.length",0);if(!len){this.markup.scope.set("children.0.children.0.style.display",len)}this.markup.scope.set({"children.0.children.0.innerHTML":len,"children.0.children.0.style.display":len?"block":"none"});this.markup.render()}}),appCreatePage:new KneeApp({styles:{label:{selector:"label",display:"block",padding:"4px 2px"},caption:{selector:"label span:first-child",width:"40px",display:"inline-block"},select:{selector:"label select",border:"1px solid #C3CBD4",background:"white",fontSize:"12px",height:"20px"}},markup:[{tagName:"div",className:"tools",children:[{tagName:"a",onclick:function(){this.onSaveTask()},innerHTML:"save task"},{tagName:"a",onclick:function(){this.onCancel()},innerHTML:"cancel"}]},{tagName:"label",children:[{tagName:"span",innerHTML:"Action "},{tagName:"select",onchange:function($el){this.scope.set("action",+$el.value)},children:[{tagName:"option",value:0,innerHTML:"Stop",selected:function(){return+this.scope.get("action")===0}},{tagName:"option",value:1,innerHTML:"Play",selected:function(){return+this.scope.get("action")===1}}]}]},{tagName:"label",children:[{tagName:"span",innerHTML:"Time "},{tagName:"input",type:"number",className:"text",min:0,max:23,onmouseenter:function($el){$el.focus();$el.select()},value:function(){return this.scope.get("stamp").getHours()},onchange:function($el){this.scope.get("stamp").setHours(parseInt($el.value))}},{tagName:"span",innerHTML:" : "},{tagName:"input",type:"number",className:"text",min:0,max:59,onmouseenter:function($el){$el.focus();$el.select()},value:function(){return this.scope.get("stamp").getMinutes()},onchange:function($el){this.scope.get("stamp").setMinutes(parseInt($el.value))}},{tagName:"span",innerHTML:" : "},{tagName:"input",type:"number",className:"text",min:0,max:59,onmouseenter:function($el){$el.focus();$el.select()},value:function(){return this.scope.get("stamp").getSeconds()},onchange:function($el){this.scope.get("stamp").setSeconds(parseInt($el.value))}}]},{tagName:"label",children:[{tagName:"span"},{tagName:"a",href:"javascript:",innerHTML:function(){return this.scope.get("everyday",false)?"everyday":"once"},onclick:function(){this.scope.set("everyday",!this.scope.get("everyday",false));this.markup.render()}}]},{tagName:"label",children:[{tagName:"a",href:"javascript:",onmousedown:function(){this.scope.set("songInfo",audioDriver.getCurrentSongInfo())},title:"Required that your the song of was on the page when starting the timer. Otherwise will be play the first song is found on current page",innerHTML:"Remember current sound"},{tagName:"div",innerHTML:function(){var si=this.scope.get("songInfo");return si?[si[5],si[6]].join(" &ndash; "):"Undefined song"}}]},{tagName:"label",style:{display:function(){return this.isNumber(this.scope.get("id"))?"block":"none"}},children:[{tagName:"a",href:"javascript:",innerHTML:"remove",onmousedown:function(){confirm("Remove this task?")&&this.remove()}}]}],scope:{stamp:new Date()},init:function(){this.scope.on("songInfo",this.markup,this.markup.render)},onSaveTask:function(){var data=this.scope.get(),len=this.appParent.scope.get("tasks.length",0);if(new Date()>data.stamp){data.stamp=new Date(data.stamp.getTime()+86.4e6)}data.stamp=data.stamp.getTime();if(this.isNumber(data.id)){this.appParent.scope.set("tasks."+data.id,data)}else{data.id=len;this.appParent.scope.set("tasks.push",[data])}this.reset();this.appParent.showPage(this.appParent.appTaskList)},reset:function(){this.scope.set({id:undefined,stamp:new Date(),action:undefined,everyday:undefined,songInfo:undefined})},onCancel:function(){this.appParent.showPage(this.appParent.appTaskList)},update:function(){if(this.isNumber(this.scope.get("id"))){this.scope.set({stamp:new Date(this.scope.get("stamp"))})}else{this.scope.set({stamp:new Date(),action:1})}this.markup.render()},remove:function(){this.appParent.scope.set("tasks.splice",[this.scope.get("id"),1]);this.reset();this.appParent.showPage(this.appParent.appTaskList)}}),appTaskList:new KneeApp({markup:[{tagName:"div",className:"tools",children:[{tagName:"a",onmousedown:function(){this.appParent.onNewTask()},innerHTML:"new task"},{tagName:"a",onmousedown:function(){confirm("Remove all tasks?")&&this.appParent.scope.set("tasks",[])},innerHTML:"remove all"}]},{tagName:"div",className:"list",children:[]},{tagName:"p",style:{display:"none"},children:[{tagName:"span",innerHTML:"Currently you have no tasks. In order to set the alarm, you need to add a "},{tagName:"a",href:"javascript:",innerHTML:"new task",onmousedown:function(){this.appParent.onNewTask()}}]}],timer:undefined,actions:["Stop player","Start player"],init:function(){this.timer=new this.Timer({rate:1},this,this.update)},fire:function(task){switch(task.action){case 0:if(audioDriver.isPlaying()){audioDriver.stop()}break;case 1:if(!audioDriver.isPlaying()){audioDriver.play(task.songInfo)}break}},update:function(){var cur=new Date().getTime(),removes=[];this.markup.scope.set("1.children",[]);this.each(this.appParent.scope.get("tasks",[]),this,function(task,key,index){if(0>(task.stamp-cur)){this.fire(task);if(task.everyday){this.appParent.scope.set("tasks."+key+".stamp",task.stamp+86.4e6)}else{removes.push(index);return}}this.markup.scope.set("1.children.push",[{tagName:"div",className:"row",children:[{tagName:"a",href:"javascript:",onmousedown:function(){this.onEdit(task)},innerHTML:function(){return this.output(task)}}]}])});this.each(removes,this,function(index){this.appParent.scope.set("tasks.splice",[index,1])});if(!this.appParent.scope.get("tasks.length",0)){this.markup.scope.set({"0.style.display":"none","2.style.display":"block"})}else{this.markup.scope.set({"0.style.display":"block","2.style.display":"none"})}this.markup.render();this.appParent.appButton.update()},onEdit:function(task){this.appParent.appCreatePage.scope.set(task);this.appParent.showPage(this.appParent.appCreatePage)},output:function(task){function d(n){return n>9?n:"0"+n}var diff=(task.stamp-new Date().getTime())/1000,days=~~(diff/86400),hours=~~((diff%86400)/3600),minutes=~~((diff%3600)/60),seconds=~~(diff%60),result=[d(hours),d(minutes),d(seconds)];return(days?[d(days)].concat(result):result).join(":")+" - "+this.actions[task.action]}}),globalStyles:{body:{selector:"*"}},styles:{el:{selector:"",width:"280px",minHeight:"200px",position:"fixed",bottom:function(val){return val||(this.scope.get("position")?"initial":0)},top:function(val){return val||(this.scope.get("position")?[this.scope.get("position.top"),"px"]:"initial")},left:function(val){return val||([this.scope.get("position.left",50),"px"])},background:"white",display:"none",zIndex:999,borderRadius:"2px",border:"1px solid #D9E0E7"},elVisible:{selector:"&.visible",display:"block"},header:{selector:".header",background:"#E9EDF1",padding:"5px",cursor:"default"},h1:{selector:"h1",color:"#607387",fontSize:"12px",margin:0,WebkitUserSelect:"none !important"},content:{selector:".content",padding:"5px"},tools:{selector:".tools",textAlign:"right"},toolsItem:{selector:".tools a + a",marginLeft:"5px"}},markup:[{tagName:"div",className:"header",onmousedown:function($el,event){this.inMouseDown=true;this.lastPoint=[event.pageX,event.pageY];this.lastOffset=[this.$el.offsetLeft,this.$el.offsetTop,this.$el.offsetWidth,this.$el.offsetHeight];this.onMoveStart()},ondblclick:function(){this.onButtonClick()},children:[{tagName:"h1",innerHTML:"Alarm"}]},{tagName:"div",className:"content"}],visible:false,inMouseDown:false,lastPoint:[0,0],lastOffset:[],init:function(){this.appButton.appParent=this;this.appTaskList.appParent=this;this.appCreatePage.appParent=this;this.showPage(this.appTaskList);if(!this.isArray(this.scope.get("tasks"))){this.scope.set("tasks",[])}this.on(window,"mousemove",this,this.onMove);this.on(window,"mouseup",this,this.onMouseUp)},onMoveStart:function(){this.globalStyles.set({"body.WebkitUserSelect":"none","body.pointerEvents":"none","body.cursor":"move"})},onMoveEnd:function(){this.globalStyles.set({"body.WebkitUserSelect":"initial","body.pointerEvents":"auto","body.cursor":"auto"});this.styles.set({"el.top":[this.$el.style.top],"el.left.0":[this.$el.style.left],"el.bottom":["initial"]});this.scope.set("position",{top:parseInt(this.$el.style.top),left:parseInt(this.$el.style.left)})},onMove:function(event){if(!this.inMouseDown){return}var deltaPoint=[event.pageX-this.lastPoint[0],event.pageY-this.lastPoint[1]],top=this.lastOffset[1]+deltaPoint[1],left=this.lastOffset[0]+deltaPoint[0];top=top+this.lastOffset[3]>=window.innerHeight?window.innerHeight-this.lastOffset[3]:top;top=0>=top?0:top;left=left+this.lastOffset[2]>=window.innerWidth?window.innerWidth-this.lastOffset[2]:left;left=0>=left?0:left;this.$el.style.top=top+"px";this.$el.style.left=left+"px";this.$el.style.bottom="initial"},onMouseUp:function(){if(this.inMouseDown){this.inMouseDown=false;this.onMoveEnd()}},onButtonClick:function(){this.elem_cls(this.$el,{visible:this.visible=!this.visible})},showPage:function(appPage){appPage.mount="#"+this.id+" .content";appPage.mountType=KneeApp.MOUNT_OVERWRITE;appPage.remount();this.result(appPage.update,appPage)},onNewTask:function(){this.showPage(this.appCreatePage)}})}());