| 69 | | JKL.Job = function ( func, onfinish, onerror ) { |
| 70 | | if ( ! func ) return window.undefined; |
| 71 | | JKL.Job.Instances ++; |
| 72 | | this.id = JKL.Job.Instances; |
| 73 | | this.func = func; |
| 74 | | this.onfinish = onfinish; |
| 75 | | this.onerror = onerror; |
| 76 | | this.done = false; |
| 77 | | this.tried = 0; |
| 78 | | }; |
| 79 | | JKL.Job.Instances = 0; |
| 80 | | JKL.Job.prototype = new JKL.Util(); |
| 81 | | JKL.Job.prototype.maxRetry = 10; |
| 82 | | JKL.Job.prototype.interval = 1; |
| 83 | | JKL.Job.prototype.run = function () { |
| 84 | | var ret = this.func(); |
| 85 | | this.tried ++; |
| 86 | | if ( ret ) { |
| 87 | | this.done = true; |
| 88 | | if ( this.onfinish ) { |
| 89 | | this.onfinish( ret ); |
| 90 | | } |
| 91 | | } else if ( this.tried < this.maxRetry ) { |
| 92 | | var that = this; |
| 93 | | var next = function () { |
| 94 | | that.run(); |
| 95 | | }; |
| 96 | | this.interval *= 2; |
| 97 | | window.setTimeout( next, this.interval ); |
| 98 | | } else { |
| 99 | | if ( this.onerror ) { |
| 100 | | this.onerror( "too many retries: "+this.tried ); |
| 101 | | } |
| 102 | | } |
| 103 | | } |
| | 69 | JKL.Job = function ( func, onfinish, onerror ) { |
| | 70 | if ( ! func ) return window.undefined; |
| | 71 | JKL.Job.Instances ++; |
| | 72 | this.id = JKL.Job.Instances; |
| | 73 | this.func = func; |
| | 74 | this.onfinish = onfinish; |
| | 75 | this.onerror = onerror; |
| | 76 | this.done = false; |
| | 77 | this.tried = 0; |
| | 78 | }; |
| | 79 | JKL.Job.Instances = 0; |
| | 80 | JKL.Job.prototype = new JKL.Util(); |
| | 81 | JKL.Job.prototype.maxRetry = 10; |
| | 82 | JKL.Job.prototype.interval = 1; |
| | 83 | JKL.Job.prototype.run = function () { |
| | 84 | var ret = this.func(); |
| | 85 | this.tried ++; |
| | 86 | if ( ret ) { |
| | 87 | this.done = true; |
| | 88 | if ( this.onfinish ) { |
| | 89 | this.onfinish( ret ); |
| | 90 | } |
| | 91 | } else if ( this.tried < this.maxRetry ) { |
| | 92 | var that = this; |
| | 93 | var next = function () { |
| | 94 | that.run(); |
| | 95 | }; |
| | 96 | this.interval *= 2; |
| | 97 | window.setTimeout( next, this.interval ); |
| | 98 | } else { |
| | 99 | if ( this.onerror ) { |
| | 100 | this.onerror( "too many retries: "+this.tried ); |
| | 101 | } |
| | 102 | } |
| | 103 | } |
| 109 | | JKL.JS2AS = function () { |
| 110 | | JKL.JS2AS.Instances ++; |
| 111 | | this.id = JKL.JS2AS.Instances; |
| 112 | | this._swfName = this.prefix + this.id; |
| 113 | | this.flashVars = {}; |
| 114 | | this.flashParams = new JKL.JS2AS.FlashParams(); |
| 115 | | this.flashAttributes = {}; |
| 116 | | return this; |
| 117 | | }; |
| 118 | | JKL.JS2AS.Instances = 0; |
| 119 | | JKL.JS2AS.prototype = new JKL.Util(); |
| 120 | | |
| 121 | | JKL.JS2AS.prototype.prefix = '_jkl_js2as_'; |
| 122 | | JKL.JS2AS.prototype.id; |
| 123 | | JKL.JS2AS.prototype._swfName; |
| 124 | | JKL.JS2AS.prototype.swfPath = null; |
| 125 | | JKL.JS2AS.prototype.installPath = null; |
| 126 | | JKL.JS2AS.prototype.noCache = false; |
| 127 | | JKL.JS2AS.prototype.displayX = 1; |
| 128 | | JKL.JS2AS.prototype.displayY = 1; |
| 129 | | JKL.JS2AS.prototype.flashVersion = '9.0.0'; |
| 130 | | JKL.JS2AS.prototype.flashVars; |
| 131 | | JKL.JS2AS.prototype.flashParams; |
| 132 | | JKL.JS2AS.prototype.flashAttributes; |
| 133 | | |
| 134 | | JKL.JS2AS.prototype.init = function (param) { |
| 135 | | if ( param ) { |
| 136 | | for( var key in param ) { |
| 137 | | this[key] = param[key]; |
| 138 | | } |
| 139 | | } |
| 140 | | var that = this; |
| 141 | | var func = function () { |
| 142 | | return that.doInit(); |
| 143 | | }; |
| 144 | | var job = new JKL.Job( func ); |
| 145 | | job.run(); |
| 146 | | |
| 147 | | } |
| 148 | | JKL.JS2AS.prototype.doInit = function () { |
| 149 | | if ( ! document.body ) return false; |
| 150 | | if ( ! window.swfobject ) return false; |
| 151 | | |
| 152 | | // .swf file URL |
| 153 | | var swfPath = this.swfPath; |
| 154 | | var instPath = this.installPath; |
| 155 | | if ( this.noCache ) { |
| 156 | | swfPath += '?'+Math.floor(Math.random()*900000+100000); |
| 157 | | instPath += '?'+Math.floor(Math.random()*900000+100000); |
| 158 | | } |
| 159 | | |
| 160 | | // create object element for flash |
| 161 | | var dummyElem = document.createElement( 'span' ); // dummy |
| 162 | | dummyElem.id = this._swfName; |
| 163 | | document.body.appendChild( dummyElem ); |
| 164 | | |
| 165 | | // load flash |
| 166 | | swfobject.embedSWF(swfPath, this._swfName, this.displayX, this.displayY, |
| 167 | | this.flashVersion, instPath, this.flashVars, |
| 168 | | this.flashParams, this.flashAttributes); |
| 169 | | |
| 170 | | // wait until flash is loaded |
| 171 | | var that = this; |
| 172 | | var func = function () { |
| 173 | | return that.waitReady(); |
| 174 | | }; |
| 175 | | var job = new JKL.Job( func ); |
| 176 | | job.run(); |
| 177 | | |
| 178 | | return true; |
| 179 | | } |
| 180 | | |
| 181 | | JKL.JS2AS.prototype.waitReady = function () { |
| 182 | | var swf = this.getSwfObject(); |
| 183 | | if ( ! swf ) return false; |
| 184 | | if ( ! swf.create ) return false; |
| 185 | | |
| 186 | | // onready callback |
| 187 | | if ( this.onready ) { |
| 188 | | this.onready( this ); |
| 189 | | } |
| 190 | | |
| 191 | | return true; |
| 192 | | } |
| 193 | | |
| 194 | | JKL.JS2AS.prototype._swfObject; |
| 195 | | JKL.JS2AS.prototype.getSwfObject = function () { |
| 196 | | if ( this._swfObject ) return this._swfObject; |
| 197 | | if (navigator.appName.indexOf("Microsoft") != -1) { |
| 198 | | this._swfObject = window[this._swfName] |
| 199 | | } else { |
| 200 | | this._swfObject = document[this._swfName] |
| 201 | | } |
| 202 | | return this._swfObject; |
| 203 | | } |
| 204 | | } |
| 205 | | |
| 206 | | // flash parameters |
| | 109 | JKL.JS2AS = function () { |
| | 110 | JKL.JS2AS.Instances ++; |
| | 111 | this.id = JKL.JS2AS.Instances; |
| | 112 | this._swfName = this.prefix + this.id; |
| | 113 | this.flashVars = {}; |
| | 114 | this.flashParams = new JKL.JS2AS.FlashParams(); |
| | 115 | this.flashAttributes = {}; |
| | 116 | return this; |
| | 117 | }; |
| | 118 | JKL.JS2AS.Instances = 0; |
| | 119 | JKL.JS2AS.prototype = new JKL.Util(); |
| | 120 | |
| | 121 | JKL.JS2AS.prototype.prefix = '_jkl_js2as_'; |
| | 122 | JKL.JS2AS.prototype.id; |
| | 123 | JKL.JS2AS.prototype._swfName; |
| | 124 | JKL.JS2AS.prototype.swfPath = null; |
| | 125 | JKL.JS2AS.prototype.installPath = null; |
| | 126 | JKL.JS2AS.prototype.noCache = false; |
| | 127 | JKL.JS2AS.prototype.displayX = 1; |
| | 128 | JKL.JS2AS.prototype.displayY = 1; |
| | 129 | JKL.JS2AS.prototype.flashVersion = '9.0.0'; |
| | 130 | JKL.JS2AS.prototype.flashVars; |
| | 131 | JKL.JS2AS.prototype.flashParams; |
| | 132 | JKL.JS2AS.prototype.flashAttributes; |
| | 133 | |
| | 134 | JKL.JS2AS.prototype.init = function (param) { |
| | 135 | if ( param ) { |
| | 136 | for( var key in param ) { |
| | 137 | this[key] = param[key]; |
| | 138 | } |
| | 139 | } |
| | 140 | var that = this; |
| | 141 | var func = function () { |
| | 142 | return that.doInit(); |
| | 143 | }; |
| | 144 | var job = new JKL.Job( func ); |
| | 145 | job.run(); |
| | 146 | |
| | 147 | } |
| | 148 | JKL.JS2AS.prototype.doInit = function () { |
| | 149 | if ( ! document.body ) return false; |
| | 150 | if ( ! window.swfobject ) return false; |
| | 151 | |
| | 152 | // .swf file URL |
| | 153 | var swfPath = this.swfPath; |
| | 154 | var instPath = this.installPath; |
| | 155 | if ( this.noCache ) { |
| | 156 | swfPath += '?'+Math.floor(Math.random()*900000+100000); |
| | 157 | instPath += '?'+Math.floor(Math.random()*900000+100000); |
| | 158 | } |
| | 159 | |
| | 160 | // create object element for flash |
| | 161 | var dummyElem = document.createElement( 'span' ); // dummy |
| | 162 | dummyElem.id = this._swfName; |
| | 163 | document.body.appendChild( dummyElem ); |
| | 164 | |
| | 165 | // load flash |
| | 166 | swfobject.embedSWF(swfPath, this._swfName, this.displayX, this.displayY, |
| | 167 | this.flashVersion, instPath, this.flashVars, |
| | 168 | this.flashParams, this.flashAttributes); |
| | 169 | |
| | 170 | // wait until flash is loaded |
| | 171 | var that = this; |
| | 172 | var func = function () { |
| | 173 | return that.waitReady(); |
| | 174 | }; |
| | 175 | var job = new JKL.Job( func ); |
| | 176 | job.run(); |
| | 177 | |
| | 178 | return true; |
| | 179 | } |
| | 180 | |
| | 181 | JKL.JS2AS.prototype.waitReady = function () { |
| | 182 | var swf = this.getSwfObject(); |
| | 183 | if ( ! swf ) return false; |
| | 184 | if ( ! swf.create ) return false; |
| | 185 | |
| | 186 | // onready callback |
| | 187 | if ( this.onready ) { |
| | 188 | this.onready( this ); |
| | 189 | } |
| | 190 | |
| | 191 | return true; |
| | 192 | } |
| | 193 | |
| | 194 | JKL.JS2AS.prototype._swfObject; |
| | 195 | JKL.JS2AS.prototype.getSwfObject = function () { |
| | 196 | if ( this._swfObject ) return this._swfObject; |
| | 197 | if (navigator.appName.indexOf("Microsoft") != -1) { |
| | 198 | this._swfObject = window[this._swfName] |
| | 199 | } else { |
| | 200 | this._swfObject = document[this._swfName] |
| | 201 | } |
| | 202 | return this._swfObject; |
| | 203 | } |
| | 204 | } |
| | 205 | |
| | 206 | // flash parameters |
| 221 | | JKL.JS2AS.Item = function () {} |
| 222 | | JKL.JS2AS.Item.prototype = new JKL.Util(); |
| 223 | | JKL.JS2AS.Item.prototype.className = null; |
| 224 | | JKL.JS2AS.Item.prototype.create = function () { |
| 225 | | var args = []; |
| 226 | | args.push.apply( args, arguments ); |
| 227 | | |
| 228 | | var cls = this.proxy.className; |
| 229 | | args.unshift( cls ); // 1st argument |
| 230 | | |
| 231 | | var swf = this.proxy.getSwfObject(); |
| 232 | | |
| 233 | | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| 234 | | if ( ! swf.create ) return JKL.Console.error( 'create interface not found: '+this.swfPath ); |
| 235 | | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| 236 | | |
| 237 | | this.id = swf.create.apply( swf, args ); |
| 238 | | } |
| 239 | | |
| 240 | | JKL.JS2AS.Item.prototype.call = function () { |
| 241 | | var args = []; |
| 242 | | args.push.apply( args, arguments ); |
| 243 | | args.unshift( this.id ); // 1st argument |
| 244 | | |
| 245 | | var swf = this.proxy.getSwfObject(); |
| 246 | | var cls = this.proxy.className; |
| 247 | | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| 248 | | if ( ! swf.call ) return JKL.Console.error( 'call interface not found: '+this.swfPath ); |
| 249 | | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| 250 | | |
| 251 | | return swf.call.apply( swf, args ); |
| 252 | | } |
| 253 | | |
| 254 | | JKL.JS2AS.Item.prototype.set = function ( key, val ) { |
| 255 | | var swf = this.proxy.getSwfObject(); |
| 256 | | var cls = this.proxy.className; |
| 257 | | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| 258 | | if ( ! swf.setter ) return JKL.Console.error( 'setter interface not found: '+this.swfPath ); |
| 259 | | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| 260 | | |
| 261 | | if ( typeof(val) == 'function' ) { |
| 262 | | val = this.getCallback( val ); |
| 263 | | } |
| 264 | | |
| 265 | | return swf.setter( this.id, key, val ); |
| 266 | | } |
| 267 | | |
| 268 | | JKL.JS2AS.Item.prototype.get = function ( key ) { |
| 269 | | var swf = this.proxy.getSwfObject(); |
| 270 | | var cls = this.proxy.className; |
| 271 | | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| 272 | | if ( ! swf.getter ) return JKL.Console.error( 'getter interface not found: '+this.swfPath ); |
| 273 | | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| 274 | | |
| 275 | | return swf.getter( this.id, key ); |
| 276 | | } |
| 277 | | |
| 278 | | JKL.JS2AS.Item.prototype.drop = function () { |
| 279 | | var swf = this.proxy.getSwfObject(); |
| 280 | | var cls = this.proxy.className; |
| 281 | | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| 282 | | if ( ! swf.drop ) return JKL.Console.error( 'drop interface not found: '+this.swfPath ); |
| 283 | | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| 284 | | |
| 285 | | return swf.drop( this.id ); |
| 286 | | } |
| 287 | | } |
| | 221 | JKL.JS2AS.Item = function () {} |
| | 222 | JKL.JS2AS.Item.prototype = new JKL.Util(); |
| | 223 | JKL.JS2AS.Item.prototype.className = null; |
| | 224 | JKL.JS2AS.Item.prototype.create = function () { |
| | 225 | var args = []; |
| | 226 | args.push.apply( args, arguments ); |
| | 227 | |
| | 228 | var cls = this.proxy.className; |
| | 229 | args.unshift( cls ); // 1st argument |
| | 230 | |
| | 231 | var swf = this.proxy.getSwfObject(); |
| | 232 | |
| | 233 | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| | 234 | if ( ! swf.create ) return JKL.Console.error( 'create interface not found: '+this.swfPath ); |
| | 235 | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| | 236 | |
| | 237 | this.id = swf.create.apply( swf, args ); |
| | 238 | } |
| | 239 | |
| | 240 | JKL.JS2AS.Item.prototype.call = function () { |
| | 241 | var args = []; |
| | 242 | args.push.apply( args, arguments ); |
| | 243 | args.unshift( this.id ); // 1st argument |
| | 244 | |
| | 245 | var swf = this.proxy.getSwfObject(); |
| | 246 | var cls = this.proxy.className; |
| | 247 | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| | 248 | if ( ! swf.call ) return JKL.Console.error( 'call interface not found: '+this.swfPath ); |
| | 249 | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| | 250 | |
| | 251 | return swf.call.apply( swf, args ); |
| | 252 | } |
| | 253 | |
| | 254 | JKL.JS2AS.Item.prototype.set = function ( key, val ) { |
| | 255 | var swf = this.proxy.getSwfObject(); |
| | 256 | var cls = this.proxy.className; |
| | 257 | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| | 258 | if ( ! swf.setter ) return JKL.Console.error( 'setter interface not found: '+this.swfPath ); |
| | 259 | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| | 260 | |
| | 261 | if ( typeof(val) == 'function' ) { |
| | 262 | val = this.getCallback( val ); |
| | 263 | } |
| | 264 | |
| | 265 | return swf.setter( this.id, key, val ); |
| | 266 | } |
| | 267 | |
| | 268 | JKL.JS2AS.Item.prototype.get = function ( key ) { |
| | 269 | var swf = this.proxy.getSwfObject(); |
| | 270 | var cls = this.proxy.className; |
| | 271 | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| | 272 | if ( ! swf.getter ) return JKL.Console.error( 'getter interface not found: '+this.swfPath ); |
| | 273 | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| | 274 | |
| | 275 | return swf.getter( this.id, key ); |
| | 276 | } |
| | 277 | |
| | 278 | JKL.JS2AS.Item.prototype.drop = function () { |
| | 279 | var swf = this.proxy.getSwfObject(); |
| | 280 | var cls = this.proxy.className; |
| | 281 | if ( ! swf ) return JKL.Console.error( 'swf not ready: '+this.swfPath ); |
| | 282 | if ( ! swf.drop ) return JKL.Console.error( 'drop interface not found: '+this.swfPath ); |
| | 283 | if ( ! cls ) return JKL.Console.error( 'invalid calss name: '+cls ); |
| | 284 | |
| | 285 | return swf.drop( this.id ); |
| | 286 | } |
| | 287 | } |