|
| 1 | +/** |
| 2 | + * Comment Core Library |
| 3 | + * |
| 4 | + * @author Jim Chen |
| 5 | + * @license MIT License |
| 6 | + * @description Comment management unit for CCL |
| 7 | + */ |
| 8 | +/// <reference path="Core.d.ts" /> |
| 9 | +class CommentManager implements ICommentManager { |
| 10 | + private _width:number = 0; |
| 11 | + private _height:number = 0; |
| 12 | + private _status:string = "stopped"; |
| 13 | + private _stage:HTMLDivElement; |
| 14 | + private _listeners:Object = {}; |
| 15 | + private _csa:Object = {}; |
| 16 | + |
| 17 | + public options:CCLOptions = { |
| 18 | + "global": { |
| 19 | + "scale": 1, |
| 20 | + "opacity": 1, |
| 21 | + "className": "cmt" |
| 22 | + }, |
| 23 | + "scroll": { |
| 24 | + "scale": 1, |
| 25 | + "opacity": 1 |
| 26 | + } |
| 27 | + }; |
| 28 | + public timeline:Array<Object> = []; |
| 29 | + public runline:Array<IComment> = []; |
| 30 | + public position:number = 0; |
| 31 | + |
| 32 | + get width():number { |
| 33 | + return this._width; |
| 34 | + } |
| 35 | + |
| 36 | + get height():number { |
| 37 | + return this._height; |
| 38 | + } |
| 39 | + |
| 40 | + get stage():HTMLDivElement { |
| 41 | + return this._stage; |
| 42 | + } |
| 43 | + |
| 44 | + get status():string { |
| 45 | + return this._status; |
| 46 | + } |
| 47 | + |
| 48 | + constructor(stage:HTMLDivElement) { |
| 49 | + this._stage = stage; |
| 50 | + } |
| 51 | + |
| 52 | + public static getCommentType(data:Object):string{ |
| 53 | + return ""; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Start the comment manager |
| 58 | + */ |
| 59 | + public start():void { |
| 60 | + this._status = "running"; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Stop the comment manager |
| 65 | + */ |
| 66 | + public stop():void { |
| 67 | + this._status = "stopped"; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Load a list of comments into the time line |
| 72 | + * @param data - list of abstract comment data |
| 73 | + */ |
| 74 | + public load(data:Array<Object>):void { |
| 75 | + this.timeline = data; |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Inserts an abstract comment data into the time line |
| 81 | + * @param data - abstract comment data |
| 82 | + */ |
| 83 | + public insert(data:Object):void { |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Clears all comments managed from the stage |
| 89 | + */ |
| 90 | + public clear():void { |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Sends a comment onto the stage |
| 96 | + * @param data - abstract comment data |
| 97 | + */ |
| 98 | + public send(data:Object):void { |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Set the bounds for the comment manager |
| 104 | + * @param width - width value px |
| 105 | + * @param height - height value px |
| 106 | + */ |
| 107 | + public setBounds(width:number = this.stage.offsetWidth, height:number = this.stage.offsetHeight):void { |
| 108 | + this._width = width; |
| 109 | + this._height = height; |
| 110 | + this.dispatchEvent("resize"); |
| 111 | + for(var allocator in this._csa){ |
| 112 | + if(this._csa.hasOwnProperty(allocator)){ |
| 113 | + var csa:CommentSpaceAllocator = this._csa[allocator]; |
| 114 | + csa.setBounds(this._width, this._height); |
| 115 | + } |
| 116 | + } |
| 117 | + this.stage.style.perspective = this.width * Math.tan(40 * Math.PI/180) / 2 + "px"; |
| 118 | + // TODO: Remove webkit prefix |
| 119 | + this.stage.style["webkitPerspective"] = this.width * Math.tan(40 * Math.PI/180) / 2 + "px"; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Dispatches an event |
| 124 | + * @param name - event name |
| 125 | + * @param data - corresponding data |
| 126 | + */ |
| 127 | + public dispatchEvent(name:String, data:Object = null):void { |
| 128 | + if (this._listeners.hasOwnProperty(name)) { |
| 129 | + var listenerList:Array<Function> = this._listeners[name]; |
| 130 | + for (var i = 0; i < listenerList.length; i++) { |
| 131 | + try { |
| 132 | + listenerList[i](data); |
| 133 | + } catch (e) { |
| 134 | + console.warn(e); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Add an event listener |
| 142 | + * @param name - event name |
| 143 | + * @param listener - listener function |
| 144 | + */ |
| 145 | + public addEventListener(name:String, listener:Function):void { |
| 146 | + if (this._listeners.hasOwnProperty(name)) { |
| 147 | + (Array<Function>)(this._listeners[name]).push(listener); |
| 148 | + } else { |
| 149 | + this._listeners[name] = [listener]; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + public finish(cmt:IComment):void { |
| 154 | + |
| 155 | + } |
| 156 | + |
| 157 | +} |
0 commit comments