//wg v.1.561 www.colorotate.org var CRHttpRequest = { get : function(url, params, callback) { var process = true, sid = 'sid' + parseInt(Math.random()*1000000), cb = 'cb=CRHttpRequest.callback.' + sid, script = document.createElement('script'); script.type = 'text/javascript'; if(params) { var sep = ''; url += "?"; for(var name in params) { url += sep + name + '=' + params[name]; sep = '&'; } } if(url.indexOf('?') == -1) script.src = url + '?' + cb; else if(url.match(/\?[\w\d]+/)) script.src = url + '&' + cb; else script.src = url + cb; CRHttpRequest.callback[sid] = function(response) { process = false; callback(response); }; script.onerror = script.onload = script.onreadystatechange = function() { if(!this.loaded && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { this.loaded = 1; this.onerror = this.onload = this.onreadystatechange = null; if(process) { callback(false); } else { /* ready */ } this.parentNode.removeChild(this); delete script; delete CRHttpRequest.callback[sid]; } } if(document.getElementsByTagName('head').length) { document.getElementsByTagName('head')[0].appendChild(script); } else { document.appendChild(script); } }, callback : {}, getPaletteByID: function(val, elemID){ var host = window.location.hostname; if(host.length==0){ host = window.location.protocol } this.get('http://www.colorotate.org/api/palette/', { id : val, elemID : elemID, dn:host }, function(response) { if(response.error.type>=0){ CRWidget.fire({ type: "onJSLoadSchemaError", text:response.error.text, errorType:response.error.type, id:response.debug.elemID }); }else{ var arr = response.result.palette.colors.substr(3,response.result.palette.colors.length-5).split("', u'"); CRWidget.fire({ type: "onJSLoadSchemaComplete", arr:arr, paletteID:response.debug.id, id:response.debug.elemID }); } }) }, _getData : function(frame) { if(frame.abort) return; var callback = CRHttpRequest.callback[frame.id]; if(callback) { try { callback(eval("(" + frame.contentWindow.name + ")")); } catch (ex) {} delete CRHttpRequest.callback[frame.id]; } setTimeout(function() { frame.parentNode.removeChild(frame); }, 0); }, _onLoad : function(frame) { var blank = 'about:blank', wnd = frame.contentWindow; try { if (!frame.state && (wnd.location == blank || wnd.location == 'javascript:true')) return; } catch (ex) {} if(frame.state) { return this._getData(frame); } else wnd.location = blank; frame.state = 1; } } //Copyright (c) 2010 Nicholas C. Zakas. All rights reserved. //MIT License function EventTarget(){ this._listeners = {} } EventTarget.prototype = { constructor: EventTarget, addListener: function(type, listener){ if (typeof this._listeners[type] == "undefined"){ this._listeners[type] = []; } this._listeners[type].push(listener); }, fire: function(event){ if (typeof event == "string"){ event = { type: event }; } if (!event.target){ event.target = this; } if (!event.type){ //falsy throw new Error("Event object missing 'type' property."); } if (this._listeners[event.type] instanceof Array){ var listeners = this._listeners[event.type]; for (var i=0, len=listeners.length; i < len; i++){ listeners[i].call(this, event); } } }, removeListener: function(type, listener){ if (this._listeners[type] instanceof Array){ var listeners = this._listeners[type]; for (var i=0, len=listeners.length; i < len; i++){ if (listeners[i] === listener){ listeners.splice(i, 1); break; } } } }, setFocusedColorDot: function(ind, swfRef){ if (swfRef && typeof swfRef.setSelectedColor != "undefined") { swfRef.setSelectedColor(ind) }}, setColorsFromArray: function(arr, swfRef){ if (swfRef && typeof swfRef.setPaletteArray != "undefined") {swfRef.setPaletteArray(arr) } }, getColorsFromArray: function(swfRef){ if (swfRef && typeof swfRef.getPaletteArray != "undefined") {return swfRef.getPaletteArray().split(",") }; return [] }, setSelected: function(ind, id){ this.fire({ type: "onFocusColorDot", ind:ind, id:id }) }, changeSchemaColor: function(arr, id){this.fire({ type: "onEditColorDot", ind:arr[0], clr:arr[1], id:id }) }, changeSchemaColorProcess: function(arr, id){ this.fire({ type: "onProcessEditColorDot", ind:arr[0], clr:arr[1], id:id }) }, changeSchemaColors: function(arr, id){ this.fire({ type: "onEditColors", arr:arr, id:id }) }, changeSchemaColorsProcess: function(arr, id){ this.fire({ type: "onProcessEditColors", arr:arr, id:id }) }, loadSchemaComplete: function(arr, paletteID, id){ this.fire({ type: "onSWFLoadSchemaComplete", arr:arr, paletteID:paletteID, id:id }) }, loadSchemaError: function(str, type, id){ this.fire({ type: "onSWFLoadSchemaError", text:str, errorType:type, id:id }) }, embedWidget: function(bgcolor, schema, w, h, id, divID, cr_callback_fn, schema_visible, address_line_visible, diamond_editable){ if(swfobject){ var flashvars = {swf:"http://www.colorotate.org/static/swf/widget.swf", fonts:"http://www.colorotate.org/static/swf/fonts.swf", version:"1.561"}; var params = {menu:"false", bgcolor:"#343434", AllowScriptAccess:"always", swliveconnect:"true"}; var cr_ref; var cr_preloader = "http://www.colorotate.org/swfs/preloader_widget.swf"; var cr_express_install = "http://www.colorotate.org/static/js/swfobject/expressInstall.swf"; params.bgcolor = bgcolor; flashvars.bgcolor = bgcolor; flashvars.schema = schema; flashvars.swf_w = w; flashvars.swf_h = h; flashvars.id = id; flashvars.schema_visible = schema_visible; flashvars.address_line_visible = address_line_visible; flashvars.diamond_editable = diamond_editable; var attributes = {id:flashvars.id, name:flashvars.id}; swfobject.embedSWF(cr_preloader, divID, w, h, "10.0.0", cr_express_install, flashvars, params, attributes, cr_callback_fn); } } } var CRWidget = new EventTarget();