芝麻web文件管理V1.00
编辑当前文件:/home/prismawe/www/itrema/video/assets/js/CPTOC.js
// JavaScript Document // masking support - http://www.rekim.com/2011/02/11/html5-canvas-globalcompositeoperation-browser-handling/ window.toc = function(str) { return document.getElementById(str); }; toc.movieProperties = null; toc.rootObj = null; toc.mainMovie = null; toc.tocAssetArr = [ 'blankBookmark', 'fullBookmark', 'visited', 'searchBtnNormal', 'searchBtnSelect', 'expander', 'infoClose', 'go', 'clear', 'expandIcon', 'collapseIcon', 'moreinfo' ]; toc.tocIconsFolder = "./assets/toc/tocIcons/"; toc.PNGSuffix = ".png"; toc.loadedAssetArr = new Object(); toc.assetsLoaded = 0; toc.tocRightMargin = 10; toc.tocLeftMargin = 8; toc.entryTopMargin = 3; toc.entryBottomMargin = 3; toc.expanderWidth = 25; toc.TOCNAVIGATEBTN_X = 12; toc.TOCNAVIGATEBTN_Y = 4; toc.statusWidth = 26; toc.scrollBarWidth = 0; toc.entryHeight = 40; toc.indentationOffset = 20; toc.bookMarkWidth = 19; toc.expanderRight = 8; toc.defaultCanvas = null; toc.rolloverCanvas = null; toc.activeCanvas = null; toc.patternWidth = 8; toc.patternHeight = 8; toc.isSearchMode = false; toc.eventManager = null; toc.tocAnimator = null; toc.leftOffset = 0; function measureTextWidth(divElem,text,maxWidth,appendSuffix) { if(text == '') return; var test = document.getElementById("tocTest"); if(test==null) { test = document.createElement('div'); document.getElementById('toc').appendChild(test); test.id = 'tocTest'; test.setAttribute('class','tocTest'); } var innerHTMLText = text; if(appendSuffix) innerHTMLText += '...'; test.innerHTML = innerHTMLText; test.style.fontSize = window.getComputedStyle(divElem).fontSize; test.style.fontFamily = window.getComputedStyle(divElem).fontFamily; test.style.color = window.getComputedStyle(divElem).color; test.style.textDecoration = window.getComputedStyle(divElem).textDecoration; test.style.fontWeight = window.getComputedStyle(divElem).fontWeight; test.style.fontStyle = window.getComputedStyle(divElem).fontStyle; var height = (test.clientHeight); var width = (test.clientWidth) ; if(maxWidth && width > maxWidth) { measureTextWidth(divElem,text.substr(0,text.length-1),maxWidth,true); return; } divElem.height = height; divElem.style.height = height + "px"; divElem.innerHTML = '
' +innerHTMLText + '
'; divElem.textWidth = width; if(divElem.clientWidth < width) { divElem.style.width = width + "px"; divElem.width = width; } else { divElem.style.width = divElem.clientWidth + "px"; divElem.width = divElem.clientWidth; } } function scrollbarWidth() { var div = document.createElement('div'); div.style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"; var innerdiv = document.createElement('div'); innerdiv.style="height:100px;" // Append our div, do our calculation and then remove it document.getElementById('toc').appendChild(div); div.appendChild(innerdiv); var w1 = div.scrollWidth; div.style.overflowY='scroll'; var w2 = div.scrollWidth; document.getElementById('toc').removeChild(div); return (w1 - w2); } function getDisplayTime(inSec) { var min = ''; var intMin = 0; var sec = ''; var intSec = 0; var res = ''; inSec = Math.floor(inSec); intMin = Math.floor(inSec/60); min = intMin + ''; intSec = (inSec - (intMin * 60)); sec = intSec + ''; if(intMin<10) res = "0"+ intMin + ":"; else res = intMin + ":"; if(intSec < 10) res = res + "0" + sec ; else res = res + sec; return res; } function applyFontSettings(div,fontSettings){ div.style.fontFamily = fontSettings.font; div.style.fontSize = fontSettings.fontSize + 'px'; div.style.color = fontSettings.color; div.style.fontFamily = fontSettings.font; if(fontSettings.underline) div.style.textDecoration = 'underline'; if(fontSettings.bold) div.style.fontWeight = 'bold'; if(fontSettings.italic) div.style.fontStyle = 'italic'; } function isSubString(SourceStr, matchStr) { var sources = SourceStr.toLowerCase(); var match = matchStr.toLowerCase(); var matches = sources.split(match); if (matches.length > 1) return true; else return false; } toc.tocPersistanceManager = null; toc.PersistanceManager = function() { this.enteredArray = new Array(); this.visitedArray = new Array(); this.bookmarkArray = new Array(); this.lastVisitedEntry = -1; this.fileID = toc.movieProperties.tocProperties.htmlFileId; this.dontWrite = 1; } toc.PersistanceManager.prototype = { flushData : function() { if(!toc.movieProperties.tocProperties.hasSelfPaced) return; var str1 = ''; var str2 = ''; var str3 = ''; var obj = toc.tocPersistanceManager; for(var i=0;i
=0; --i) { if( this.level - this.contentDiv.tocEntries[i].level == 1 )//get immediate parent { this.contentDiv.tocEntries[i].setParentActive(bool); return; } } }, setActive : function(bool) { toc.tocPersistanceManager.setEntered(this); this.setParentActive(bool); }, setCanvas : function(bool) { var src = this.entryContainer.mousein ? toc.rolloverCanvas : toc.defaultCanvas; if(bool) src = toc.activeCanvas; this.entryContainer.style.backgroundImage = 'url("' + src +'")'; this.entryContainer.style.backgroundSize = '100% 100%'; }, checkChildrenAndVisited: function(index) { if(this.duration == 0) return; var sum = 0; for(var j = this.index+1; j < this.contentDiv.tocEntries.length; ++j) { if(this.contentDiv.tocEntries[j].level <= this.level) break; else if( this.contentDiv.tocEntries[j].level - this.level == 1 )// immediate children { if( this.contentDiv.tocEntries[j].entryContainer.visited ) sum+= this.contentDiv.tocEntries[j].duration; } } if(sum == this.duration) { this.setVisited();//propagate upwards this.entryContainer.visited = true; if(this.entryContainer.style.height != '0px') this.visitedDiv.style.visibility = ''; } }, setVisited : function() { if(!this.visitedDiv) return; if(this.entryContainer.visited) return; this.entryContainer.visited = true; toc.tocPersistanceManager.setVisited(this); if(this.entryContainer.style.height != '0px') this.visitedDiv.style.visibility = ''; if(this.level!=1) { for(var i= this.index - 1; i>=0; --i) { if( this.level - this.contentDiv.tocEntries[i].level == 1 )//get immediate parent { this.contentDiv.tocEntries[i].checkChildrenAndVisited(); break; } else continue; } } else this.checkChildrenAndVisited(); }, onRolloverEntry : function(event) { this.mousein = true; if(this.style.height == '0px') { this.style.cursor = 'default'; return; } if(this.parentObj.durationDiv) this.parentObj.durationDiv.style.color = toc.movieProperties.tocProperties.fontSettings['level'+this.parentObj.level+'Settings'].rolloverColor; if(this.parentObj.textDiv) this.parentObj.textDiv.style.color = toc.movieProperties.tocProperties.fontSettings['level'+this.parentObj.level+'Settings'].rolloverColor; if(this.active) return; if(!this.parentObj.hasChild&&toc.movieProperties.tocProperties.navigateVisited&&!toc.tocPersistanceManager.getEntered(this.parentObj)) return; var src = toc.rolloverCanvas; this.style.backgroundImage = 'url("' + src +'")'; this.style.backgroundSize = '100% 100%'; }, onRolloutEntry : function(event) { this.mousein = false; var src = toc.defaultCanvas; if(this.active) src = toc.activeCanvas; if(this.parentObj.durationDiv) this.parentObj.durationDiv.style.color = toc.movieProperties.tocProperties.fontSettings['level'+this.parentObj.level+'Settings'].color; if(this.parentObj.textDiv) this.parentObj.textDiv.style.color = toc.movieProperties.tocProperties.fontSettings['level'+this.parentObj.level+'Settings'].color; this.style.backgroundImage = 'url("' + src +'")'; this.style.backgroundSize = '100% 100%'; }, createDuration : function(entryDiv) { var durationDiv = document.createElement('div'); entryDiv.appendChild(durationDiv); durationDiv.setAttribute('class','tocDuration'); applyFontSettings(durationDiv,this.fontSettings); measureTextWidth(durationDiv,getDisplayTime(this.duration)); entryDiv.appendChild(durationDiv); durationDiv.style.top = (parseFloat(window.getComputedStyle(entryDiv).height.replace('px','')) - durationDiv.height)/2 + "px"; durationDiv.style.left = (parseFloat(window.getComputedStyle(entryDiv).width.replace('px','')) - toc.tocRightMargin - toc.scrollBarWidth - durationDiv.width - toc.statusWidth) + "px"; this.durationDiv = durationDiv; this.durationWidth = durationDiv.width; }, createText : function(entryDiv) { var textDiv = document.createElement('div'); entryDiv.appendChild(textDiv); textDiv.setAttribute('class','tocText'); applyFontSettings(textDiv,this.fontSettings); measureTextWidth(textDiv,this.text,(parseFloat(window.getComputedStyle(entryDiv).width.replace('px','')) - toc.tocLeftMargin - toc.tocRightMargin - toc.scrollBarWidth - this.durationWidth - toc.statusWidth - this.expanderWidth)); entryDiv.appendChild(textDiv); textDiv.style.top = (parseFloat(window.getComputedStyle(entryDiv).height.replace('px','')) - textDiv.height)/2 + "px"; textDiv.style.left = (toc.tocLeftMargin + this.expanderWidth) + "px"; this.textDiv = textDiv; }, calculateDuration : function() { if(this.link) return; for(var i=this.index + 1;i
= animator.totalSteps) { clearInterval(animator.intervalId); animator.currStep = 0; animator.isAnimating = false; objDiv.style[animator.param] = animator.endVal + "px"; objDiv.otherObj.style[animator.param] = animator.endVal + objDiv.otherparam + "px"; return; } if(((cp.CHROME == cp.browser) || (cp.device == cp.IDEVICE)) && (objDiv.style.webkitTransform != undefined)) { objDiv.style['webkitTransform'] = "translateX(0px)"; objDiv.otherObj.style['webkitTransform'] = "translateX(0px)"; } var val = animator.easeOut(animator.startVal,animator.endVal); objDiv.style[animator.param] = val + "px"; objDiv.otherObj.style[animator.param] = val + objDiv.otherparam + "px"; } else { animator.currStep++; if (animator.currStep >= animator.totalSteps) { clearInterval(animator.intervalId); animator.currStep = 0; animator.isAnimating = false; objDiv.style[animator.param] = animator.startVal + "px"; objDiv.otherObj.style[animator.param] = animator.startVal + objDiv.otherparam + "px"; return; } if(((cp.CHROME == cp.browser) || (cp.device == cp.IDEVICE)) && (objDiv.style.webkitTransform != undefined)) { objDiv.style['webkitTransform'] = "translateX(0px)"; objDiv.otherObj.style['webkitTransform'] = "translateX(0px)"; } var val = animator.easeOut(animator.endVal,animator.startVal); objDiv.style[animator.param] = val + "px"; objDiv.otherObj.style[animator.param] = val + objDiv.otherparam + "px"; } }, hideTOC : function() { if(this.isAnimating && this.direction == 0 ) return; else if(parseFloat(window.getComputedStyle(this.tocDiv)[this.param].replace('px','')) == this.startVal) return; this.collapseDiv.style.visibility = 'hidden'; this.direction = 0; if(toc.movieProperties.tocProperties.position == 0) this.tocDiv.otherparam = -this.expandDiv.width; else this.tocDiv.otherparam = this.tocDiv.width; this.expandDiv.style.left = this.endVal + this.tocDiv.otherparam + "px"; this.expandDiv.style.visibility = ''; this.tocDiv.otherObj = this.expandDiv; this.isAnimating = true; clearInterval(this.intervalId); this.intervalId = setInterval(this.beginAnim,20); }, showTOC : function(atEnd) { if(this.isAnimating && this.direction == 1 ) return; else if(parseFloat(window.getComputedStyle(this.tocDiv)[this.param].replace('px','')) == this.endVal) return; this.expandDiv.style.visibility = 'hidden'; this.direction = 1; if(toc.movieProperties.tocProperties.position == 0) this.tocDiv.otherparam = -this.collapseDiv.width; else this.tocDiv.otherparam = this.tocDiv.width; this.collapseDiv.style.left = this.startVal + this.tocDiv.otherparam + "px"; this.collapseDiv.style.visibility = ''; this.tocDiv.otherObj = this.collapseDiv; this.isAnimating = true; clearInterval(this.intervalId); this.intervalId = setInterval(this.beginAnim,20); } }; function loadtoc() { var tocDiv = document.getElementById('toc'); (toc.movieProperties.tocProperties.position == 1) ? tocDiv.setAttribute('class','tocLeftStyle') : tocDiv.setAttribute('class','tocRightStyle'); toc.rootObj.loadTOCAssets(); }; function RegisterTOCToEvents() { if(toc.eventManager&&toc.rootObj) { toc.eventManager.addEventListener( toc.rootObj.listenToSlideEnter,cp.SLIDEENTEREVENT); toc.eventManager.addEventListener( toc.rootObj.listenToSlideExit,cp.SLIDEEXITEVENT); } }; function tocInit(movieProperties,leftOffset,topOffset,rightOffset,bottomOffset) { toc.movieProperties = movieProperties; var tocDiv = document.getElementById('toc'); if(!toc.movieProperties.project.hasTOC) { tocDiv.style.display = 'none'; return; } toc.rootObj = new toc.tocConstruct(tocDiv); toc.tocPersistanceManager = new toc.PersistanceManager(); var hasData = toc.tocPersistanceManager.hasData(); if(hasData == 1) { var lRunTimeMsgBox = cp.ShowWarning(toc.movieProperties.tocProperties.cnfmsg,cp.model.data['rtDialog']['rtWarningTitle'],true,true); lRunTimeMsgBox.setDontAskMe(true); lRunTimeMsgBox.setDontAskMeText(toc.movieProperties.tocProperties.dntask); var lOkHandler = function() { toc.tocPersistanceManager.readData(); if(lRunTimeMsgBox.getDontAskMeInput()) { toc.tocPersistanceManager.setDontWrite(2); toc.tocPersistanceManager.flushData(); } else toc.tocPersistanceManager.setDontWrite(1); lRunTimeMsgBox.hide(); continueTOCInit(leftOffset,topOffset,rightOffset,bottomOffset); } var lCancelHandler = function() { if(lRunTimeMsgBox.getDontAskMeInput()) { toc.tocPersistanceManager.setDontWrite(0); toc.tocPersistanceManager.flushData(); } else toc.tocPersistanceManager.setDontWrite(1); lRunTimeMsgBox.hide(); continueTOCInit(leftOffset,topOffset,rightOffset,bottomOffset); } lRunTimeMsgBox.registerFirstButtonHandler(lOkHandler); lRunTimeMsgBox.registerSecondButtonHandler(lCancelHandler); lRunTimeMsgBox.show(); } else if(hasData == 2) { toc.tocPersistanceManager.readData(); continueTOCInit(leftOffset,topOffset,rightOffset,bottomOffset); } else continueTOCInit(leftOffset,topOffset,rightOffset,bottomOffset); }; function continueTOCInit(leftOffset,topOffset,rightOffset,bottomOffset) { var tocDiv = document.getElementById('toc'); window.onclose = toc.tocPersistanceManager.flushData; document.onunload = toc.tocPersistanceManager.flushData; RegisterTOCToEvents(); tocDiv.width = toc.movieProperties.tocProperties.width; tocDiv.height = toc.movieProperties.project.h; if(toc.movieProperties.tocProperties.stretch) { tocDiv.height += topOffset + bottomOffset; topOffset = 0; } tocDiv.style.width = tocDiv.width + "px"; tocDiv.style.height = tocDiv.height + "px"; var left = ((toc.movieProperties.tocProperties.position == 1) ? (toc.movieProperties.tocProperties.overlay ? -tocDiv.width : 0) + leftOffset : toc.movieProperties.project.w ) ; toc.leftOffset = leftOffset; tocDiv.style.left = left + "px"; tocDiv.style.top = topOffset + "px"; loadtoc(); } function setTOCCallback(movie,em) { toc.mainMovie = movie; toc.eventManager = em; RegisterTOCToEvents(); } function getStartFrameOfMovie() { if(toc.movieProperties.tocProperties.hasSelfPaced) { if(toc.tocPersistanceManager.lastVisitedEntry!=-1) { if(toc.movieProperties['Slide'+toc.rootObj.tocEntries[toc.tocPersistanceManager.lastVisitedEntry].link]) return toc.movieProperties['Slide'+toc.rootObj.tocEntries[toc.tocPersistanceManager.lastVisitedEntry].link].from; } } return 1; }