function getPHPRequestHandler(returnFn, fn, cls, location) { return new phpRequest(returnFn, fn, cls, location); } function expandComment(rootNode, commentID) { var virtualCall = (commentID != null); if (!virtualCall) { commentID = this.commentID; } var hndl = new commentCreator(); if (virtualCall) { hndl.displayLoc = rootNode.parentNode; }else { hndl.displayLoc = this.parentNode; } hndl.commentID = commentID; var fn = getPHPRequestHandler(new objfn('parseComments', hndl), 'getReplies', 'comment_responder', 'responder.php'); fn.run(commentID); var root = null; if (virtualCall) { root = rootNode.parentNode; }else { root = this.parentNode; } while(root.childNodes.length != 0) { root.removeChild(root.childNodes[0]); } var div = document.createElement('div'); div.className = 'comment_link'; div.appendChild(document.createTextNode('Loading...')); root.appendChild(div); } function hideComment() { var root = this.parentNode; while(root.childNodes.length != 0) { root.removeChild(root.childNodes[0]); } var div = document.createElement('div'); div.className = 'comment_link'; div.appendChild(document.createTextNode('+Replies('+this.commentCount+')')); div.onclick = expandComment; div.commentID = this.commentID; root.appendChild(div); } function commentCreator() { } commentCreator.prototype.parseComments = function(result) { comments = result['comments']; while(this.displayLoc.childNodes.length != 0) { this.displayLoc.removeChild(this.displayLoc.childNodes[0]); } var root = this.displayLoc; var div = document.createElement('div'); div.className = 'comment_link'; div.appendChild(document.createTextNode('-Replies('+comments.length.toString()+')')); div.onclick = hideComment; div.commentCount = comments.length.toString(); div.commentID = this.commentID; root.appendChild(div); var mainDiv = div; mainDiv.commentID = this.commentID; mainDiv.readSaveResponse = function(result) { if (result['status'] == 1) { expandComment(this, this.commentID); }else { alert(result['text']); } } troot = root; root = document.createElement('div'); root.className = 'comment'; troot.appendChild(root); var span; for(var i = 0; i < comments.length; i++) { span = document.createElement('div'); span.appendChild(document.createTextNode('//'+comments[i]['timeadded'])); span.className = 'comment_date'; root.appendChild(span); span = document.createElement('span'); span.appendChild(document.createTextNode(comments[i]['user'])); span.className = 'comment_user'; root.appendChild(span); span = document.createElement('span'); span.appendChild(document.createTextNode(' said:')); span.className = 'comment_text'; root.appendChild(span); div = document.createElement('div'); div.className = 'comment_text'; div.appendChild(document.createTextNode(comments[i]['comment'])); root.appendChild(div); // root.appendChild(document.createElement('br')); div = document.createElement('div'); div.className = 'comment_link'; div.appendChild(document.createTextNode('+Replies('+comments[i]['replies'].toString()+')')); div.onclick = expandComment; div.commentID = comments[i]['id']; var rootComment = document.createElement('div'); rootComment.appendChild(div); root.appendChild(rootComment); span = document.createElement('div'); span.className = 'comment_border'; root.appendChild(span); if (i != comments.length-1) { root.appendChild(document.createElement('br')); } } root.appendChild(document.createElement('br')); if (result['replyable'] == 1) { div = document.createElement('span'); div.className = 'comment_link'; div.appendChild(document.createTextNode(' Add Reply')); div.onclick = makeTextBox; div.style['left'] = '10px'; div.style['position'] = 'relative'; div.commentID = this.commentID; div.mainDiv = mainDiv; root.appendChild(div); } } function makeTextBox() { while(this.childNodes.length != 0) { this.removeChild(this.childNodes[0]); } this.onclick = null; var input = document.createElement('textarea'); input.className = 'comment_text_box'; this.appendChild(input); var textbox = input; input = document.createElement('div'); input.className = "comment_submit"; input.onclick = savecomment; input.source = textbox; input.commentID = this.commentID; input.mainDiv = this.mainDiv; this.appendChild(input); } function savecomment() { if (this.source.value == "") { return; } var fn = getPHPRequestHandler(new objfn('readSaveResponse', this.mainDiv), 'saveComment', 'comment_responder', 'responder.php'); fn.run(this.commentID, this.source.value); } function taskBarHandler() { } taskBarHandler.prototype.hideShowButtonClick = function(button) { if (this.layersVisible) { this.hideLayers(); }else { this.showLayers(); } } taskBarHandler.prototype.buttonClick = function(button) { for(var i = 0; i < this.buttons.length; i++) { this.buttons[i].setState(0); } button.setState(1); this.layers.selectContainer(this.layerIds[button.buttonID]); this.showLayers(); } taskBarHandler.prototype.hideLayers = function() { this.layers.style['visibility'] = 'hidden'; this.layers.style['display'] = 'none'; this.layersVisible = false; this.hideShowButton.childNodes[0].nodeValue = 'Show'; this.hideShowButton.setState(0); } taskBarHandler.prototype.showLayers = function() { this.layers.style['visibility'] = 'visible'; this.layers.style['display'] = 'block'; this.layersVisible = true; this.hideShowButton.childNodes[0].nodeValue = 'Hide'; this.hideShowButton.setState(1); } function initTaskbar(root) { while(root.childNodes.length != 0) { root.removeChild(root.childNodes[0]); } //Parameters var taskHeight = 15; var taskWidth = 591; var buttonWidth = 75; var layerHeight = 100; //Create the taskbar var taskBar = document.createElement('div'); taskBar.className = "taskbar_background"; divToVerticalSplitContainer(taskBar, taskWidth-buttonWidth, taskHeight, taskWidth-buttonWidth, taskHeight); var taskBarHolder = document.createElement('div'); divToVerticalSplitContainer(taskBarHolder, taskWidth, taskHeight, taskWidth, taskHeight); taskBarHolder.addContainer(taskBar); var hideShowButton = document.createElement('div'); hideShowButton.appendChild(document.createTextNode('Show')); divToButton(hideShowButton, 'taskbar_button_up', 'taskbar_button_down', 'taskbar_button_highlight', buttonWidth, taskHeight); taskBarHolder.addContainer(hideShowButton); root.appendChild(taskBarHolder); //Add the buttons var buttons = new Array(); buttons[0] = document.createElement('div'); buttons[0].appendChild(document.createTextNode('Auto Play')); for(var i = 0; i < buttons.length; i++) { divToButton(buttons[i], 'taskbar_button_up', 'taskbar_button_down', 'taskbar_button_highlight', buttonWidth, taskHeight); buttons[i].buttonID = i; taskBar.addContainer(buttons[i]); } buttons[0].setState(1); //Create the dropDown var dropDown = createLayeredContainer(layerHeight, taskWidth); dropDown.style['position'] = 'absolute'; // dropDown.style['background'] = '#AA0000'; root.style['position'] = 'relative'; root.appendChild(dropDown); //Create Objects var tskbr = new taskBarHandler(); tskbr.buttons = buttons; tskbr.layers = dropDown; tskbr.hideShowButton = hideShowButton; tskbr.hideLayers(); hideShowButton.broadcasterOnMouseup.addHook(new objfn('hideShowButtonClick', tskbr)); for(var i = 0; i < buttons.length; i++) { buttons[i].broadcasterOnMouseup.addHook(new objfn('buttonClick', tskbr)); } //Create Sections var layerIds = new Array(); layerIds[0] = dropDown.addContainer(createAutoPlayer(layerHeight, taskWidth)); tskbr.layerIds = layerIds; app.addComponent('taskbar', tskbr); } function createAutoPlayer(height, width) { var root = document.createElement('div'); divToVerticalSplitContainer(root, width, height, width, height); root.addContainer(createDBRadio(height, width)); root.className = 'autoplay_background'; return root; } function createDBRadio(height, width) { var root = document.createElement('div'); divToContainer(root, width, height, width, height); var title = document.createElement('div'); title.className = 'taskbar_title_text'; title.appendChild(document.createTextNode('DB Radio [')); var enableLink = document.createElement('span'); enableLink.className = 'taskbar_js_link'; enableLink.appendChild(document.createTextNode('Disabled')); enableLink.onclick = function() { app.getFunction('dbRadio', 'changeDisabled').run(); } title.appendChild(enableLink); title.appendChild(document.createTextNode(']')); root.appendChild(title); var workSpace = document.createElement('div'); workSpace.className = 'taskbar_text'; root.appendChild(workSpace); var radioObj = new dbRadio(); radioObj.enableLink = enableLink; radioObj.workSpace = workSpace; app.addComponent('dbRadio', radioObj); app.addFunction('dbRadio', 'changeDisabled', new objfn('changeDisabled', radioObj)); app.addFunction('dbRadio', 'openAlbum', new objfn('openAlbum', radioObj)); app.addFunction('dbRadio', 'repollServer', new objfn('repollServer', radioObj)); app.addFunction('dbRadio', 'setPlayerPosition', new objfn('setPlayerPosition', radioObj)); return root; } function dbRadio() { this.enabled = false; } dbRadio.prototype.changeDisabled = function() { while(this.workSpace.childNodes.length != 0) { this.workSpace.removeChild(this.workSpace.childNodes[0]); } if (this.repollTimeout != null) { clearTimeout(this.repollTimeout); this.repollTimeout = null; } if (this.setPlayerPosTimeout != null) { clearTimeout(this.setPlayerPosTimeout); this.setPlayerPosTimeout = null; } if (this.enabled) { this.enabled = false; this.enableLink.childNodes[0].nodeValue = 'Disabled'; }else { this.enabled = true; this.enableLink.childNodes[0].nodeValue = 'Enabled'; this.workSpace.appendChild(document.createTextNode('Loading...')); var fn = getPHPRequestHandler(new objfn('currentlyPlaying', this), 'currentlyPlaying', 'radio_responder', 'responder.php'); fn.run(); } } dbRadio.prototype.openAlbum = function() { OpenAlbum(this.currentAlbum); } dbRadio.prototype.repollServer = function(data) { var fn = getPHPRequestHandler(new objfn('currentlyPlaying', this), 'currentlyPlaying', 'radio_responder', 'responder.php'); fn.run(); } dbRadio.prototype.currentlyPlaying = function(data) { while(this.workSpace.childNodes.length != 0) { this.workSpace.removeChild(this.workSpace.childNodes[0]); } var text = document.createElement('div'); text.className = 'taskbar_text'; text.appendChild(document.createTextNode('Currently Playing:')); this.workSpace.appendChild(text); this.currentAlbum = data['albumID']; var img = document.createElement('img'); img.src = data['albumPic']; var imgLink = document.createElement('div'); imgLink.className = 'taskbar_js_link taskbar_float_left'; imgLink.appendChild(img); imgLink.onclick = function() { app.getFunction('dbRadio', 'openAlbum').run(); } this.workSpace.appendChild(imgLink); var span = null; span = document.createElement('div'); span.className = 'taskbar_float_left taskbar_text'; span.appendChild(document.createTextNode(data['albumName'])); this.workSpace.appendChild(span); this.workSpace.appendChild(document.createElement('br')); span = document.createElement('div'); span.className = 'taskbar_float_left taskbar_text'; span.appendChild(document.createTextNode(data['albumArtist'])); this.workSpace.appendChild(span); this.workSpace.appendChild(document.createElement('br')); span = document.createElement('div'); span.className = 'taskbar_float_left taskbar_text'; span.appendChild(document.createTextNode(data['songName'])); this.workSpace.appendChild(span); this.repollTimeout = setTimeout(repollRadioServer, data['nextPoll']*1000); playSingleSong(data['song']); this.songStartPosition = data['songPos']; if (this.songStartPosition > 5) { if (this.setPlayerPosTimeout != null) { clearTimeout(this.setPlayerPosTimeout); this.setPlayerPosTimeout = null; } this.setPlayerPosTimeout = setTimeout(setRadioPlayerPosition, 1000); } } dbRadio.prototype.setPlayerPosition = function() { this.setPlayerPosTimeout = null; try { var doc = playerWindowID.document.getElementById('MFrame'); if (doc.contentWindow.getPlayerState() == 3) { doc.contentWindow.setPlayerPosition(this.songStartPosition*1000); return; } }catch(e) { } this.setPlayerPosTimeout = setTimeout(setRadioPlayerPosition, 1000); } function playSingleSong(songid) { try { var doc = playerWindowID.document.getElementById('MFrame'); doc.contentWindow.userClose = true; doc.contentWindow.radioControl = true; try { doc.contentWindow.stopPlayer(); }catch(e) { } doc.src = 'player.php?noexitmsg=1&loc=0&list[]='+songid.toString(); }catch(e) { PlaySong(songid); } } function setRadioPlayerPosition() { app.getFunction('dbRadio', 'setPlayerPosition').run(); } function repollRadioServer() { app.getFunction('dbRadio', 'repollServer').run(); } //Components: events, functions function application() { this.components = new Array(); this.addComponent = function(name, obj) { var desc = new Array(); desc['obj'] = obj; desc['events'] = new Array(); desc['functions'] = new Array(); this.components[name] = desc; } this.getComponent = function(name) { return this.components[name]['obj']; } this.addFunction = function(component, fnName, fn) { if (this.components[component] == null) { alert('Unable to add function. Component '+component+' does not exist.'); return; } this.components[component]['functions'][fnName] = fn; } this.attachEvent = function(component, eventName, callbackfn) { if (this.components[component] == null) { alert('Unable to attach Event. Component '+component+' does not exist.'); return; } if (this.components[component]['events'][eventName] == null) { this.components[component]['events'][eventName] = new Array(); } this.components[component]['events'][eventName][this.components[component]['events'][eventName].length] = callbackfn; } this.sendEvent = function(component, event, args) { if (this.components[component]['events'][event] == null) { return; } for (var i = 0; i < this.components[component]['events'][event].length; i++) { this.components[component]['events'][event][i].runArr(args); } } this.getFunction = function(component, fnName) { return this.components[component]['functions'][fnName]; } } function sharedInputHandler(component, catchers) { this.component = component; this.events = new Array(); component.inputHandler = this; var handlerfn = function(evnt) { var eventType; if (isExplorer()) { evnt = event; } eventType = evnt.type; var events = this.inputHandler.events; for (var i = 0; i < events[eventType].length; i++) { if (events[eventType][i] != null) { events[eventType][i].run(evnt, i); } } } for(var i = 0; i < catchers.length; i++) { component['on'+catchers[i]] = handlerfn; this.events[catchers[i]] = new Array(); } this.removeEvent = function(eventType, id) { this.events[eventType][id] = null; } this.addEvent = function(eventType, fn) { if (this.events[eventType] == null) { alert('Shared Input Handler: "' + eventType + '", unbounded event name.'); return; } var i = 0; for (i = 0; i < this.events[eventType].length; i++) { if (this.events[eventType][i] == null) { break; } } this.events[eventType][i] = fn; return i; } } var globalTimers = new Array(); function timer() { setTimeout('exeTimers();', 100); } function exeTimers() { setTimeout('exeTimers();', 100); for(var i = 0; i < globalTimers.length; i++) { if (globalTimers[i] != null) { globalTimers[i].checkExecute(); } } } timer.prototype.addTimer = function(fn, interval) { for(var i = 0; i < globalTimers.length; i++) { if (globalTimers[i] == null) {break;} } globalTimers[i] = new timerObj(fn, interval); // return globalTimers[i]; return i; } timer.prototype.removeTimer = function(index) { globalTimers[index] = null; /* for(var i = 0; i < globalTimers.length; i++) { if (globalTimers[i] == obj) { globalTimers[i] = null; } } */ } function timerObj(fn, interval) { this.fn = fn; this.timer = timer; } timerObj.prototype.checkExecute = function () { this.fn.run(this); } //function phpCommunicator(objfn, fn, cls, location) function phpRequest(returnFn, fn, cls, location) { var parent = this; this.objfn = returnFn; this.fn = fn; this.cls = cls; this.location = location; this.rsp = new xmlHTTPRequestor(); this.tryCount = 1; this.headersSent = ""; this.run = function() { var toSendHeaders = "cls="+escape(this.cls)+"&fn="+escape(this.fn); var args = new Array(); for (var i = 0; i < arguments.length; i++) { args[i] = arguments[i]; } toSendHeaders = toSendHeaders + varToPostExport(args); this.headersSent = toSendHeaders; this.rsp.run(this.location, this.headersSent); } this.retryRequest = function() { // parent.tryCount = parent.tryCount + 1; parent.rsp.run(parent.location, parent.headersSent); } this.rspStateMon = function() { var xmlResponder = this.rsp.xmlResponder; if (xmlResponder.readyState != 4) { return; }; var responderStatus; try { responderStatus = xmlResponder.status; }catch(e) { responderStatus = -1; } if (responderStatus != 200) { if (this.tryCount == 3) { alert(location + '\n' + xmlResponder.status + ': Unable to retrieve XML response document.'); return; }else { setTimeout(this.retryRequest, 1000); return; } } var result = null; try { var root = xmlResponder.responseXML.getElementsByTagName('result'); root = root[0].childNodes[0]; result = XMLtoVar(root); }catch(e) { alert("Error: " + e.toString() + "\nUnable to parse:\n"+xmlResponder.responseText); } if (this.objfn != null) { this.objfn.run(result); } } this.rsp.stateMonFn = new objfn('rspStateMon', this); } function xmlHTTPRequestor() { var parent = this; this.xmlResponder = null; this.stateMonFn = null; try { this.xmlResponder = new XMLHttpRequest (); }catch (dumb_browser_exception) { try { this.xmlResponder = new ActiveXObject ("Msxml2.XMLHTTP"); }catch (yet_another_deal_with_ie_exception) { try { this.xmlResponder = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (give_up_now_exception) { alert('XML HTTP Request is not supported by your browser!'); return; } } } if (typeof this.xmlResponder.overrideMimeType != 'undefined') { this.xmlResponder.overrideMimeType("text/xml"); } this.run = function(location, postVars) { this.xmlResponder.abort(); this.xmlResponder.onreadystatechange = this.monitorResponderState; this.xmlResponder.open('POST', location, true); this.xmlResponder.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); this.xmlResponder.send(postVars); } this.monitorResponderState = function() { if (parent.stateMonFn != null) { parent.stateMonFn.run(); } } } function objfn(fn, obj) { this.fn = fn; this.obj = obj; } objfn.prototype.runArr = function(arr) { if (this.obj == null) { return this.fn.apply(this, arr); }else { return this.obj[this.fn].apply(this.obj, arr); } } objfn.prototype.run = function() { if (this.obj == null) { return this.fn.apply(this, arguments); }else { return this.obj[this.fn].apply(this.obj, arguments); } } function queryCach() { this.cach = new Array(); } queryCach.prototype.query = function(args, handler, fn, cls, location) { if (this.cach[location] != null) { if (this.cach[location][cls] != null) { if (this.cach[location][cls][fn] != null) { var fnQs = this.cach[location][cls][fn]; for (var i = 0; i < fnQs.length; i++) { if (isEqual(fnQs[i]['args'], args)) { handler.run(fnQs[i]['result']); return; } } } } } new queryCachRunner(args, handler, fn, cls, location, this); } queryCach.prototype.saveQuery = function(args, fn, cls, location, result) { if (this.cach[location] == null) { this.cach[location] = new Array(); } if (this.cach[location][cls] == null) { this.cach[location][cls] = new Array(); } if (this.cach[location][cls][fn] == null) { this.cach[location][cls][fn] = new Array(); } var save = new Array(); save['result'] = result; save['args'] = args; this.cach[location][cls][fn][this.cach[location][cls][fn].length] = save; } function queryCachRunner(args, handler, fn, cls, location, cacher) { this.handler = handler; this.cacher = cacher; this.fn = fn; this.cls = cls; this.location = location; this.args = args; var rnr = getPHPRequestHandler(new objfn('ret', this), fn, cls, location); rnr.run.apply(rnr, args); } queryCachRunner.prototype.ret = function(rsp) { this.cacher.saveQuery(this.args, this.fn, this.cls, this.location, rsp); this.handler.run(rsp); } function globalCach() { this.cach = new Array(); this.broadcasters = new Array(); } globalCach.prototype.get = function(varName) { return this.cach[varName]; } globalCach.prototype.incommingData = function(data) { for (var i in data) { this.setVariable(i, data[i]); } } globalCach.prototype.setVariable = function(varName, data) { if (data == this.cach[varName]) {return;} this.cach[varName] = data; if (this.broadcasters[varName] != null) { this.broadcasters[varName].broadcast(data); } } globalCach.prototype.bind = function(varName, handler) { if (this.broadcasters[varName] == null) { this.broadcasters[varName] = new eventBroadcaster(); } this.broadcasters[varName].addHook(handler); if (this.cach[varName] != null) { handler.run(this.cach[varName]); } } function userAuth() { this.inGroup = function(name) { var userObj = app.cach.get('userInfo'); var groups = userObj.groups; for(var i = 0; i < groups.length; i++) { if (groups[i] == name) { return true; } } return false; } } function createHorizontalSlider(max, pos, height, width, slider, sliderWidth, posMonFn) { slider.style['position'] = 'absolute'; var sliderInfo = document.createElement('div'); sliderInfo.style['height'] = '20px'; sliderInfo.style['width'] = '100px'; sliderInfo.style['top'] = '-24px'; sliderInfo.style['left'] = '5px'; sliderInfo.style['position'] = 'absolute'; sliderInfo.style['display'] = 'none'; sliderInfo.className = 'sliderInfo'; var styler = document.createElement('span'); styler.className = 'player_media_popup_text'; var labelText = document.createTextNode('test'); styler.appendChild(labelText); sliderInfo.appendChild(styler); slider.appendChild(sliderInfo); slider.onmousedown = function(evnt) { if (isExplorer()) { evnt = event; } this.parent.prevClientX = evnt.clientX; this.parent.draging = true; if (this.mouseupid != null) { app.docEvents.removeEvent('mouseup', this.mouseupid); this.mouseupid = null; } if (this.mousemoveid != null) { app.docEvents.removeEvent('mousemove', this.mousemoveid); this.mousemoveid = null; } this.mouseupid = app.docEvents.addEvent('mouseup', new objfn('mouseup', this)); this.mousemoveid = app.docEvents.addEvent('mousemove', new objfn('mousemove', this)); if (this.parent.posToTextFn != null) { this.parent.labelNode.style['display'] = 'block'; this.parent.labelText.nodeValue = this.parent.posToTextFn.run(this.parent.sliderPos); } } slider.mouseup = function(evnt) { if (!this.parent.draging) {return;} if (isExplorer()) { evnt = event; } this.parent.draging = false; if (this.mouseupid != null) { app.docEvents.removeEvent('mouseup', this.mouseupid); this.mouseupid = null; } if (this.mousemoveid != null) { app.docEvents.removeEvent('mousemove', this.mousemoveid); this.mousemoveid = null; } // app.docEvents.removeEvent('mouseup', this.mouseupid); // app.docEvents.removeEvent('mousemove', this.mousemoveid); if (this.parent.posMonFn != null) { this.parent.posMonFn.run(this.parent.sliderPos); } if (this.parent.posToTextFn != null) { this.parent.labelNode.style['display'] = 'none'; } } slider.mousemove = function(evnt) { if (!this.parent.draging) {return;} if (isExplorer()) { evnt = event; } var xChange = evnt.clientX - this.parent.prevClientX; this.parent.prevClientX = evnt.clientX; var change = this.parent.sliderMax * (xChange / (this.parent.physicalWidth - this.parent.sliderWidth)); var finalPos = this.parent.sliderPos + change; if (finalPos > this.parent.sliderMax) { finalPos = this.parent.sliderMax; } if (finalPos < this.parent.sliderMin) { finalPos = this.parent.sliderMin; } this.parent.setPos(finalPos); if (this.parent.posToTextFn != null) { this.parent.labelText.nodeValue = this.parent.posToTextFn.run(finalPos); } } var div = document.createElement('div'); div.labelNode = sliderInfo; div.labelText = labelText; slider.parent = div; // div.style['background'] = '#0000AA'; div.style['position'] = 'relative'; divToContainer(div, width, height, width, height); div.sliderMax = max; div.sliderMin = 0; div.slider = slider; div.sliderWidth = sliderWidth; div.posMonFn = posMonFn; div.physicalWidth = width; div.physicalHeight = height; div.sliderPos = pos; div.draging = false; div.prevClientX = 0; div.appendChild(slider); div.setPos = function(pos) { this.sliderPos = pos; var physicalPos; if (this.sliderMax == 0) { physicalPos = 0; }else { physicalPos = (this.physicalWidth-this.sliderWidth)*(this.sliderPos/this.sliderMax); } var newPos = Math.round(physicalPos).toString() + 'px'; if (this.slider.style['left'] != newPos) { this.slider.style['left'] = newPos; } } div.setWidth = function(width) { this.maxX = width; this.minX = width; this.physicalWidth = width; this.setSize(this.physicalWidth, this.physicalHeight); this.setPos(this.sliderPos); } div.setPos(pos); return div; } function objCach(phpfn, phpclass, responder) { this.cach = new Array(); this.phpfn = phpfn; this.phpclass = phpclass; this.phpresponder = responder; this.waitingHooks = new Array(); } objCach.prototype.get = function(objs, hook) { var allObjsPreloaded = true; var objResult = new Array(); var unknownObjs = new Array(); for(var i = 0; i < objs.length; i++) { if (this.cach['id'+objs[i]] == null) { allObjsPreloaded = false; unknownObjs[unknownObjs.length] = objs[i]; }else { objResult[objResult.length] = this.cach['id'+objs[i]]; } } if (allObjsPreloaded) { hook.run(objResult); return; } this.addHook(hook, objs); var req = getPHPRequestHandler(new objfn('saveObjs', this), this.phpfn, this.phpclass, this.phpresponder); req.run(unknownObjs); } objCach.prototype.saveObjs = function(objs) { for (var i = 0; i < objs.length; i++) { var obj = objs[i]; this.cach['id'+obj['id']] = obj; } this.triggerHooks(); } objCach.prototype.triggerHooks = function() { for (var i = 0; i < this.waitingHooks.length; i++) { var hook = this.waitingHooks[i]; var allFound = true; var result = new Array(); for (var j = 0; j < hook['ids'].length; j++) { if (this.cach['id'+hook['ids'][j]] == null) { allFound = false; break; }else { result[result.length] = this.cach['id'+hook['ids'][j]]; } } if (allFound) { hook['hook'].run(result); this.waitingHooks[i] = null; } } } objCach.prototype.addHook = function(hook, objs) { var i; for(i = 0; i < this.waitingHooks.length; i++) { if (this.waitingHooks[i] == null) { break; } } this.waitingHooks[i] = new Array(); this.waitingHooks[i]['hook'] = hook; this.waitingHooks[i]['ids'] = objs; } function divToContainer(div, minX, minY, maxX, maxY) { div.isContainer = true; if (minX == null) {minX = 0;} if (minY == null) {minY = 0;} if (maxX == null) {maxX = 0;} if (maxY == null) {maxY = 0;} div.minX = minX; div.minY = minY; div.maxX = maxX; div.maxY = maxY; div.setSize = function(x, y) { if (x < this.minX) {x = this.minX;} if (y < this.minY) {y = this.minY;} if (x > this.maxX && this.maxX != 0) {x = this.maxX;} if (y > this.maxY && this.maxY != 0) {y = this.maxY;} if (this.currX == x && this.currY == y) { return; } this.currX = x; this.currY = y; if (this.currX == 0 || this.currY == 0) { this.style['display'] = 'none'; this.style['visibility'] = 'hidden'; }else { this.style['display'] = 'block'; this.style['visibility'] = 'visible'; } this.style['width'] = this.currX+'px'; this.style['height'] = this.currY+'px'; if (this.resizeChildren != null) { if (this.delayResizeTimerID != -1) { app.timer.removeTimer(this.delayResizeTimerID); } this.delayResizeTimerID = app.timer.addTimer(new objfn('delayResize', this), 1); } } div.delayResize = function() { if (this.delayResizeTimerID != -1) { app.timer.removeTimer(this.delayResizeTimerID); } this.delayResizeTimerID = -1; this.resizeChildren(); } div.delayResizeTimerID = -1; div.setSize(0, 0); return div; } window.onresize = getWindowResize; var winWidth; var winHeight; var winContainer = null; var winDelayHandle = null; function initWindow() { getWindowResize(); } function setWindowContainer(div) { if (div.isContainer != true) { alert('Given div is not a container.'); return; } if (document.body.childNodes.length == 0) { document.body.appendChild(div); }else { document.body.insertBefore(div, document.body.childNodes[0]) } winContainer = div; } function getWindowResize() { if (window.innerWidth != null) { winWidth = window.innerWidth; winHeight = window.innerHeight; }else if (document.documentElement.clientHeight != null) { winWidth = document.documentElement.clientWidth; winHeight = document.documentElement.clientHeight; } if (winContainer != null) { if (winDelayHandle != null) { clearTimeout(winDelayHandle); winDelayHandle = null; } winDelayHandle = setTimeout(delayWinResizeExecute, 200); } } function delayWinResizeExecute() { winDelayHandle = null; try { winContainer.setSize(winWidth-20, winHeight-20); }catch(e) { document.title = e; } } function divToVerticalSplitContainer(div, minX, minY, maxX, maxY) { div = divToContainer(div, minX, minY, maxX, maxY); div.containers = new Array(); div.maxWidths = new Array(); div.widthFixedContainers = 0; div.addContainer = function (container, maxWidth) { if (maxWidth == null) { maxWidth = 0; } this.containers[this.containers.length] = container; this.maxWidths[this.maxWidths.length] = maxWidth; if (maxWidth != 0) { this.widthFixedContainers = this.widthFixedContainers + 1; } // var span = parseHTML(''); var span = document.createElement('span'); span.className = 'verticlesplitfloater'; span.appendChild(container); this.appendChild(span); this.resizeChildren; } div.resizeChildren = function() { if (this.containers.length == 0) {return;} var widthLeft = this.currX; var fixedWidthContainers = this.widthFixedContainers; var widthPerContainer = widthLeft/fixedWidthContainers; for (var i = 0; i < this.containers.length; i++) { if (this.maxWidths[i] != 0) { var contWidth = 0; if (widthPerContainer > this.maxWidths[i]) { contWidth = this.maxWidths[i]; }else { contWidth = widthPerContainer; } this.containers[i].setSize(contWidth, this.currY); widthLeft = widthLeft - this.containers[i].currX; fixedWidthContainers = fixedWidthContainers - 1; widthPerContainer = widthLeft/fixedWidthContainers; // if (widthLeft <= 0) {return;} } } widthPerContainer = widthLeft/(this.containers.length - this.widthFixedContainers); for (var i = 0; i < this.containers.length; i++) { if (this.maxWidths[i] == 0) { this.containers[i].setSize(widthPerContainer, this.currY); } } } return div; } function divToButton(div, upcls, downcls, hlcls, width, height) { div = divToContainer(div, width, height, width, height); div.upcls = upcls; div.downcls = downcls; div.hlcls = hlcls; div.state = -1;//1 = pressed, 0 = decompressed div.broadcasterOnMouseover = new eventBroadcaster(); div.broadcasterOnMouseout = new eventBroadcaster(); div.broadcasterOnMousedown = new eventBroadcaster(); div.broadcasterOnMouseup = new eventBroadcaster(); div.broadcasterOnChange = new eventBroadcaster(); div.setState = function(state) { if (this.state == state) { return; } this.state = state; this.broadcasterOnChange.broadcast(this); if (this.state == 1) { this.className = this.downcls; }else { this.className = this.upcls; } } div.onmouseover = function() { if (this.state == 0) { this.className = this.hlcls; } this.broadcasterOnMouseover.broadcast(this); } div.onmouseout = function() { if (this.state == 1) { this.className = this.downcls; }else { this.className = this.upcls; } this.broadcasterOnMouseout.broadcast(this); } div.onmousedown = function() { this.broadcasterOnMousedown.broadcast(this); this.className = this.downcls; } div.onmouseup = function() { this.broadcasterOnMouseup.broadcast(this); if (this.state == 1) { this.className = this.downcls; }else { this.className = this.upcls; } } div.setState(0); return div; } function createLayeredContainer(height, width) { var cont = document.createElement('div');//createDOMObj('div', new Array()); // cont.style['background'] = '#00AA00'; cont = divToContainer(cont, width, height, width, height); cont.containers = new Array(); cont.selected = 0; cont.addContainer = function (cont) { this.containers[this.containers.length] = cont; cont.style['visibility'] = 'hidden'; cont.style['display'] = 'none'; this.appendChild(cont); if (this.containers.length == 1) { this.selectContainer(0); } this.resizeChildren(); return this.containers.length-1; } cont.selectContainer = function(index) { if (index < 0 || index > (this.containers.length-1)) { alert('Container select index out of bound!'); } for(var i = 0; i < this.containers.length; i++) { this.containers[i].style['visibility'] = 'hidden'; this.containers[i].style['display'] = 'none'; } this.selected = index; this.containers[this.selected].style['visibility'] = 'visible'; this.containers[this.selected].style['display'] = 'block'; if (this.containers[this.selected].onvisible != null) { this.containers[this.selected].onvisible(); this.containers[this.selected].setSize(this.currX, this.currY); } } cont.resizeChildren = function() { for (var i = 0; i < this.containers.length; i++) { this.containers[i].setSize(this.currX, this.currY); } if (this.containers.length > 0) { this.selectContainer(this.selected); } } return cont; } function tabHandler(layeredcnt) { this.layeredcnt = layeredcnt; this.tabs = new Array(); this.currTab = 0; } tabHandler.prototype.buttonClick = function(button) { this.selectTab(button.layerIndex); } tabHandler.prototype.addTab = function(button, layerIndex) { var tab = new Array(); button.broadcasterOnMouseup.addHook(new objfn("buttonClick", this)); button.layerIndex = layerIndex; tab['button'] = button; tab['index'] = layerIndex; this.tabs[this.tabs.length] = tab; } tabHandler.prototype.selectTab = function(index) { for(var i = 0; i < this.tabs.length; i++) { this.tabs[i].button.setState(0); } this.currTab = index; this.tabs[index].button.setState(1); this.layeredcnt.selectContainer(this.tabs[index].index); } function divToHorizontalSplitContainer(div, minX, minY, maxX, maxY) { div = divToContainer(div, minX, minY, maxX, maxY); div.containers = new Array(); div.maxHeights = new Array(); div.heightFixedContainers = 0; div.addContainer = function (container, maxHeight) { if (maxHeight == null) { maxHeight = 0; } this.containers[this.containers.length] = container; this.maxHeights[this.maxHeights.length] = maxHeight; if (maxHeight != 0) { this.heightFixedContainers = this.heightFixedContainers + 1; } this.appendChild(container); this.resizeChildren; } div.resizeChildren = function() { if (this.containers.length == 0) {return;} var heightLeft = this.currY; var fixedHeightContainers = this.heightFixedContainers; var heightPerContainer = heightLeft/fixedHeightContainers; for (var i = 0; i < this.containers.length; i++) { if (this.maxHeights[i] != 0) { var contHeight = 0; if (heightPerContainer > this.maxHeights[i]) { contHeight = this.maxHeights[i]; }else { contHeight = heightPerContainer; } this.containers[i].setSize(this.currX, contHeight); heightLeft = heightLeft - this.containers[i].currY; fixedHeightContainers = fixedHeightContainers - 1; heightPerContainer = heightLeft/fixedHeightContainers; if (heightLeft <= 0) {return;} } } heightPerContainer = heightLeft/(this.containers.length - this.heightFixedContainers); for (var i = 0; i < this.containers.length; i++) { if (this.maxHeights[i] == 0) { this.containers[i].setSize(this.currX, heightPerContainer); } } } return div; } function createDOMObj(tag, tags) { tagString = ""; for (var x in tags) { tagString = tagString+' '+x+'="'+tags[x]+'"'; } // htmlNode = getChildByName(this.document, "HTML"); // bodyNode = getChildByName(htmlNode, "BODY"); // bodyNode.innerHTML = bodyNode.innerHTML + '<'+tag+tagString+'>'; var div = document.getElementById('DOMWorkSpace'); div.innerHTML = ""; div.innerHTML = '<'+tag+tagString+'>'; var node = div.removeChild(div.childNodes[0]); while (div.childNodes.length != 0) { div.removeChild(div.childNodes[0]); } return node; } function parseHTML(html) { var div = document.getElementById('DOMWorkSpace'); div.innerHTML = ""; div.innerHTML = html; var node = div.removeChild(div.childNodes[0]); while (div.childNodes.length != 0) { div.removeChild(div.childNodes[0]); } return node; } function clearChildNodes(parent) { while(parent.childNodes.length != 0) { parent.removeChild(parent.childNodes[0]); } } function isArray(a) { return a.constructor == Array; } function isEqual(st1, st2) { if (isArray(st1) != isArray(st2)) { return false; } if (isArray(st1) && isArray(st2)) { for(var i in st1) { if (isArray(st1[i]) != isArray(st2[i])) { return false; } if (isArray(st1[i]) && isArray(st2[i])) { if (!isEqual(st1[i], st2[i])) { return false; } }else { if (!(st1[i] == st2[i])) { return false; } } } return true; }else { return st1 == st2; } } function eventBroadcaster() { this.events = new Array(); this.addHook = function(handler) { var newid = this.events.length; this.events[newid] = handler; return newid; } this.broadcast = function() { for(var i = 0; i < this.events.length; i++) { if (this.events[i] != null) { this.events[i].runArr(arguments); } } } } function isExplorer() { if (document.all) { return true; }else { return false; } } function isMozilla() { if (document.all) { return false; }else { return true; } } /* function initLoader(retFn) { this.retObj = retFn; } initLoader.prototype.run = function() { var t = new phpRequest(new objfn("handler", this), "includes", "loader", 'app/layout.php'); t.run(); } initLoader.prototype.handler = function(doc) { this.retObj.run(); } */ function XMLtoVar(node) { if (node == null) { return; } var type = node.getAttribute('type'); if (type == "string") { if (node.childNodes.length == 1) { return node.childNodes[0].nodeValue; }else { var str = ""; for(var i = 0; i < node.childNodes.length; i++) { str = str + node.childNodes[i].nodeValue; } return str; } }else if (type == "array") { var result = new Array(); for(var i = 0; i < node.childNodes.length; i++) { result[node.childNodes[i].getAttribute('key')] = XMLtoVar(node.childNodes[i].childNodes[0]); } return result; } } function varToPostExport(variable, base) { if (variable == null) {return "";} if (base == null) { base = "input"; } if (!(typeof variable == 'object')) { return "&"+base+"="+escape(variable); }else { var toReturn = ''; for (i in variable) { toReturn = toReturn + varToPostExport(variable[i], base+"["+i+"]"); } return toReturn; } }