twreporter-react
Version:
React-Redux site for The Reporter Foundation in Taiwan
1,830 lines (1,812 loc) • 155 kB
JavaScript
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
;(function(){
// modjewel.js
(function(){
var PROGRAM = "modjewel"
var VERSION = "2.0.0"
var global = this
if (global.modjewel) {
log("modjewel global variable already defined")
return
}
global.modjewel = null
var ModuleStore
var ModulePreloadStore
var MainModule
var WarnOnRecursiveRequire = false
function get_require(currentModule) {
var result = function require(moduleId) {
if (moduleId.match(/^\.{1,2}\//)) {
moduleId = normalize(currentModule, moduleId)
}
if (hop(ModuleStore, moduleId)) {
var module = ModuleStore[moduleId]
if (module.__isLoading) {
if (WarnOnRecursiveRequire) {
var fromModule = currentModule ? currentModule.id : "<root>"
console.log("module '" + moduleId + "' recursively require()d from '" + fromModule + "', problem?")
}
}
currentModule.moduleIdsRequired.push(moduleId)
return module.exports
}
if (!hop(ModulePreloadStore, moduleId)) {
var fromModule = currentModule ? currentModule.id : "<root>"
error("module '" + moduleId + "' not found from '" + fromModule + "', must be define()'d first")
}
var factory = ModulePreloadStore[moduleId][0]
var prereqs = ModulePreloadStore[moduleId][1]
var module = create_module(moduleId)
var newRequire = get_require(module)
ModuleStore[moduleId] = module
module.__isLoading = true
try {
currentModule.moduleIdsRequired.push(moduleId)
var prereqModules = []
for (var i=0; i<prereqs.length; i++) {
var prereqId = prereqs[i]
var prereqModule
if (prereqId == "require") prereqModule = newRequire
else if (prereqId == "exports") prereqModule = module.exports
else if (prereqId == "module") prereqModule = module
else prereqModule = newRequire(prereqId)
prereqModules.push(prereqModule)
}
if (typeof factory == "function") {
var result = factory.apply(null, prereqModules)
if (result) {
module.exports = result
}
}
else {
module.exports = factory
}
}
finally {
module.__isLoading = false
}
return module.exports
}
result.define = require_define
result.implementation = PROGRAM
result.version = VERSION
return result
}
function hop(object, name) {
return Object.prototype.hasOwnProperty.call(object, name)
}
function create_module(id) {
return {
id: id,
uri: id,
exports: {},
prereqIds: [],
moduleIdsRequired: []
}
}
function require_reset() {
ModuleStore = {}
ModulePreloadStore = {}
MainModule = create_module(null)
var require = get_require(MainModule)
var define = require_define
define("modjewel", modjewel_module)
global.modjewel = require("modjewel")
global.modjewel.require = require
global.modjewel.define = define
global.modjewel.define.amd = {implementation: PROGRAM, version: VERSION}
}
function require_define(moduleId, prereqs, factory) {
var rem = ["require", "exports", "module"]
if (typeof moduleId != "string") {
console.log("modjewel.define(): first parameter must be a string; was: " + moduleId)
return
}
if (arguments.length == 2) {
factory = prereqs
prereqs = null
}
if (!prereqs || prereqs.length == 0) {
prereqs = rem
}
if (typeof factory != "function") {
if (factory) {
ModulePreloadStore[moduleId] = [factory, prereqs]
return
}
console.log("modjewel.define(): factory was falsy: " + factory)
return
}
if (moduleId.match(/^\./)) {
console.log("modjewel.define(): moduleId must not start with '.': '" + moduleName + "'")
return
}
if (hop(ModulePreloadStore, moduleId)) {
console.log("modjewel.define(): module '" + moduleId + "' has already been defined")
return
}
ModulePreloadStore[moduleId] = [factory, prereqs]
}
function getModulePath(module) {
if (!module || !module.id) return ""
var parts = module.id.split("/")
return parts.slice(0, parts.length-1).join("/")
}
function normalize(module, file) {
var modulePath = getModulePath(module)
var dirParts = ("" == modulePath) ? [] : modulePath.split("/")
var fileParts = file.split("/")
for (var i=0; i<fileParts.length; i++) {
var filePart = fileParts[i]
if (filePart == ".") {
}
else if (filePart == "..") {
if (dirParts.length > 0) {
dirParts.pop()
}
else {
}
}
else {
dirParts.push(filePart)
}
}
return dirParts.join("/")
}
function error(message) {
throw new Error(PROGRAM + ": " + message)
}
function modjewel_getLoadedModuleIds() {
var result = []
for (moduleId in ModuleStore) {
result.push(moduleId)
}
return result
}
function modjewel_getPreloadedModuleIds() {
var result = []
for (moduleId in ModulePreloadStore) {
result.push(moduleId)
}
return result
}
function modjewel_getModule(moduleId) {
if (null == moduleId) return MainModule
return ModuleStore[moduleId]
}
function modjewel_getModuleIdsRequired(moduleId) {
var module = modjewel_getModule(moduleId)
if (null == module) return null
return module.moduleIdsRequired.slice()
}
function modjewel_warnOnRecursiveRequire(value) {
if (arguments.length == 0) return WarnOnRecursiveRequire
WarnOnRecursiveRequire = !!value
}
function modjewel_module(require, exports, module) {
exports.VERSION = VERSION
exports.require = null
exports.define = null
exports.getLoadedModuleIds = modjewel_getLoadedModuleIds
exports.getPreloadedModuleIds = modjewel_getPreloadedModuleIds
exports.getModule = modjewel_getModule
exports.getModuleIdsRequired = modjewel_getModuleIdsRequired
exports.warnOnRecursiveRequire = modjewel_warnOnRecursiveRequire
}
function log(message) {
console.log("modjewel: " + message)
}
require_reset()
})();
;
modjewel.require('modjewel').warnOnRecursiveRequire(true);
// weinre/common/Binding.amd.js
;modjewel.define("weinre/common/Binding", function(require, exports, module) {
var Binding, Ex;
Ex = require('./Ex');
module.exports = Binding = (function() {
function Binding(receiver, method) {
if (!receiver) {
throw new Ex(arguments, "receiver argument for Binding constructor was null");
}
if (typeof method === "string") {
method = receiver[method];
}
if (typeof method === !"function") {
throw new Ex(arguments, "method argument didn't specify a function");
}
return function() {
return method.apply(receiver, [].slice.call(arguments));
};
}
return Binding;
})();
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/Callback.amd.js
;modjewel.define("weinre/common/Callback", function(require, exports, module) {
var Callback, CallbackIndex, CallbackTable, ConnectorChannel, Ex;
Ex = require('./Ex');
CallbackTable = {};
CallbackIndex = 1;
ConnectorChannel = "???";
module.exports = Callback = (function() {
function Callback() {
throw new Ex(arguments, "this class is not intended to be instantiated");
}
Callback.setConnectorChannel = function(connectorChannel) {
return ConnectorChannel = "" + connectorChannel;
};
Callback.register = function(callback) {
var data, func, index, receiver;
if (typeof callback === "function") {
callback = [null, callback];
}
if (typeof callback.slice !== "function") {
throw new Ex(arguments, "callback must be an array or function");
}
receiver = callback[0];
func = callback[1];
data = callback.slice(2);
if (typeof func === "string") {
func = receiver[func];
}
if (typeof func !== "function") {
throw new Ex(arguments, "callback function was null or not found");
}
index = ConnectorChannel + "::" + CallbackIndex;
CallbackIndex++;
if (CallbackIndex >= 65536 * 65536) {
CallbackIndex = 1;
}
CallbackTable[index] = [receiver, func, data];
return index;
};
Callback.deregister = function(index) {
return delete CallbackTable[index];
};
Callback.invoke = function(index, args) {
var callback, e, func, funcName, receiver;
callback = CallbackTable[index];
if (!callback) {
throw new Ex(arguments, "callback " + index + " not registered or already invoked");
}
receiver = callback[0];
func = callback[1];
args = callback[2].concat(args);
try {
return func.apply(receiver, args);
} catch (_error) {
e = _error;
funcName = func.name || func.signature;
if (!funcName) {
funcName = "<unnamed>";
}
return require("./Weinre").logError(arguments.callee.signature + (" exception invoking callback: " + funcName + "(" + (args.join(',')) + "): ") + e);
} finally {
Callback.deregister(index);
}
};
return Callback;
})();
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/Debug.amd.js
;modjewel.define("weinre/common/Debug", function(require, exports, module) {
var Debug;
module.exports = new (Debug = (function() {
function Debug() {
this._printCalledArgs = {};
}
Debug.prototype.log = function(message) {
var console;
console = window.console.__original || window.console;
return console.log("" + (this.timeStamp()) + ": " + message);
};
Debug.prototype.logCall = function(context, intf, method, args, message) {
var printArgs, signature;
if (message) {
message = ": " + message;
} else {
message = "";
}
signature = this.signature(intf, method);
printArgs = this._printCalledArgs[signature];
if (printArgs) {
args = JSON.stringify(args, null, 4);
} else {
args = "";
}
return this.log("" + context + " " + signature + "(" + args + ")" + message);
};
Debug.prototype.logCallArgs = function(intf, method) {
return this._printCalledArgs[this.signature(intf, method)] = true;
};
Debug.prototype.signature = function(intf, method) {
return "" + intf + "." + method;
};
Debug.prototype.timeStamp = function() {
var date, mins, secs;
date = new Date();
mins = "" + (date.getMinutes());
secs = "" + (date.getSeconds());
if (mins.length === 1) {
mins = "0" + mins;
}
if (secs.length === 1) {
secs = "0" + secs;
}
return "" + mins + ":" + secs;
};
return Debug;
})());
});
;
// weinre/common/EventListeners.amd.js
;modjewel.define("weinre/common/EventListeners", function(require, exports, module) {
var EventListeners, Ex, Weinre;
Ex = require('./Ex');
Weinre = require('./Weinre');
module.exports = EventListeners = (function() {
function EventListeners() {
this.listeners = [];
}
EventListeners.prototype.add = function(listener, useCapture) {
return this.listeners.push([listener, useCapture]);
};
EventListeners.prototype.remove = function(listener, useCapture) {
var listeners, _i, _len, _listener;
listeners = this.listeners.slice();
for (_i = 0, _len = listeners.length; _i < _len; _i++) {
_listener = listeners[_i];
if (_listener[0] !== listener) {
continue;
}
if (_listener[1] !== useCapture) {
continue;
}
this._listeners.splice(i, 1);
return;
}
};
EventListeners.prototype.fire = function(event) {
var e, listener, listeners, _i, _len, _results;
listeners = this.listeners.slice();
_results = [];
for (_i = 0, _len = listeners.length; _i < _len; _i++) {
listener = listeners[_i];
listener = listener[0];
if (typeof listener === "function") {
try {
listener.call(null, event);
} catch (_error) {
e = _error;
Weinre.logError("" + arguments.callee.name + " invocation exception: " + e);
}
continue;
}
if (typeof (listener != null ? listener.handleEvent : void 0) !== "function") {
throw new Ex(arguments, "listener does not implement the handleEvent() method");
}
try {
_results.push(listener.handleEvent.call(listener, event));
} catch (_error) {
e = _error;
_results.push(Weinre.logError("" + arguments.callee.name + " invocation exception: " + e));
}
}
return _results;
};
return EventListeners;
})();
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/Ex.amd.js
;modjewel.define("weinre/common/Ex", function(require, exports, module) {
var Ex, StackTrace, prefix;
StackTrace = require('./StackTrace');
module.exports = Ex = (function() {
Ex.catching = function(func) {
var e;
try {
return func.call(this);
} catch (_error) {
e = _error;
console.log("runtime error: " + e);
return StackTrace.dump(arguments);
}
};
function Ex(args, message) {
if (!args || !args.callee) {
throw Ex(arguments, "first parameter must be an Arguments object");
}
StackTrace.dump(args);
if (message instanceof Error) {
message = "threw error: " + message;
}
message = prefix(args, message);
message;
}
return Ex;
})();
prefix = function(args, string) {
if (args.callee.signature) {
return args.callee.signature + ": " + string;
}
if (args.callee.displayName) {
return args.callee.displayName + ": " + string;
}
if (args.callee.name) {
return args.callee.name + ": " + string;
}
return "<anonymous>" + ": " + string;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/HookLib.amd.js
;modjewel.define("weinre/common/HookLib", function(require, exports, module) {
var HookLib, HookSite, HookSites, IgnoreHooks, callAfterHooks, callBeforeHooks, callExceptHooks, getHookSite, getHookedFunction;
HookLib = exports;
HookSites = [];
IgnoreHooks = 0;
module.exports = HookLib = (function() {
function HookLib() {}
HookLib.addHookSite = function(object, property) {
return getHookSite(object, property, true);
};
HookLib.getHookSite = function(object, property) {
return getHookSite(object, property, false);
};
HookLib.ignoreHooks = function(func) {
var result;
try {
IgnoreHooks++;
result = func.call();
} finally {
IgnoreHooks--;
}
return result;
};
return HookLib;
})();
getHookSite = function(object, property, addIfNotFound) {
var hookSite, i, _i, _len;
i = 0;
for (_i = 0, _len = HookSites.length; _i < _len; _i++) {
hookSite = HookSites[_i];
if (hookSite.object !== object) {
continue;
}
if (hookSite.property !== property) {
continue;
}
return hookSite;
}
if (!addIfNotFound) {
return null;
}
hookSite = new HookSite(object, property);
HookSites.push(hookSite);
return hookSite;
};
HookSite = (function() {
function HookSite(object, property) {
var hookedFunction;
this.object = object;
this.property = property;
this.target = object[property];
this.hookss = [];
if (typeof this.target === 'undefined') {
return;
} else {
hookedFunction = getHookedFunction(this.target, this);
if (!(navigator.userAgent.match(/MSIE/i) && (object === localStorage || object === sessionStorage))) {
object[property] = hookedFunction;
}
}
}
HookSite.prototype.addHooks = function(hooks) {
return this.hookss.push(hooks);
};
HookSite.prototype.removeHooks = function(hooks) {
var i, _i, _ref;
for (i = _i = 0, _ref = this.hookss.length; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
if (this.hookss[i] === hooks) {
this.hookss.splice(i, 1);
return;
}
}
};
return HookSite;
})();
getHookedFunction = function(func, hookSite) {
var hookedFunction;
hookedFunction = function() {
var e, result;
callBeforeHooks(hookSite, this, arguments);
try {
result = func.apply(this, arguments);
} catch (_error) {
e = _error;
callExceptHooks(hookSite, this, arguments, e);
throw e;
} finally {
callAfterHooks(hookSite, this, arguments, result);
}
return result;
};
hookedFunction.displayName = func.displayName || func.name;
return hookedFunction;
};
callBeforeHooks = function(hookSite, receiver, args) {
var hooks, _i, _len, _ref, _results;
if (IgnoreHooks > 0) {
return;
}
_ref = hookSite.hookss;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
hooks = _ref[_i];
if (hooks.before) {
_results.push(hooks.before.call(hooks, receiver, args));
} else {
_results.push(void 0);
}
}
return _results;
};
callAfterHooks = function(hookSite, receiver, args, result) {
var hooks, _i, _len, _ref, _results;
if (IgnoreHooks > 0) {
return;
}
_ref = hookSite.hookss;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
hooks = _ref[_i];
if (hooks.after) {
_results.push(hooks.after.call(hooks, receiver, args, result));
} else {
_results.push(void 0);
}
}
return _results;
};
callExceptHooks = function(hookSite, receiver, args, e) {
var hooks, _i, _len, _ref, _results;
if (IgnoreHooks > 0) {
return;
}
_ref = hookSite.hookss;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
hooks = _ref[_i];
if (hooks.except) {
_results.push(hooks.except.call(hooks, receiver, args, e));
} else {
_results.push(void 0);
}
}
return _results;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/IDGenerator.amd.js
;modjewel.define("weinre/common/IDGenerator", function(require, exports, module) {
var IDGenerator, idName, nextId, nextIdValue;
nextIdValue = 1;
idName = "__weinre__id";
module.exports = IDGenerator = (function() {
function IDGenerator() {}
IDGenerator.checkId = function(object) {
return object[idName];
};
IDGenerator.getId = function(object, map) {
var id;
id = IDGenerator.checkId(object);
if (!id) {
id = nextId();
object[idName] = id;
}
if (map) {
map[id] = object;
}
return id;
};
IDGenerator.next = function() {
return nextId();
};
return IDGenerator;
})();
nextId = function() {
var result;
result = nextIdValue;
nextIdValue += 1;
return result;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/IDLTools.amd.js
;modjewel.define("weinre/common/IDLTools", function(require, exports, module) {
var Callback, Ex, IDLTools, IDLs, getProxyMethod;
Ex = require('./Ex');
Callback = require('./Callback');
IDLs = {};
module.exports = IDLTools = (function() {
function IDLTools() {
throw new Ex(arguments, "this class is not intended to be instantiated");
}
IDLTools.addIDLs = function(idls) {
var idl, intf, _i, _len, _results;
_results = [];
for (_i = 0, _len = idls.length; _i < _len; _i++) {
idl = idls[_i];
_results.push((function() {
var _j, _len1, _ref, _results1;
_ref = idl.interfaces;
_results1 = [];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
intf = _ref[_j];
IDLs[intf.name] = intf;
_results1.push(intf.module = idl.name);
}
return _results1;
})());
}
return _results;
};
IDLTools.getIDL = function(name) {
return IDLs[name];
};
IDLTools.getIDLsMatching = function(regex) {
var intf, intfName, results;
results = [];
for (intfName in IDLs) {
intf = IDLs[intfName];
if (intfName.match(regex)) {
results.push(intf);
}
}
return results;
};
IDLTools.validateAgainstIDL = function(klass, interfaceName) {
var classMethod, error, errors, intf, intfMethod, messagePrefix, printName, propertyName, _i, _j, _len, _len1, _ref, _results;
intf = IDLTools.getIDL(interfaceName);
messagePrefix = "IDL validation for " + interfaceName + ": ";
if (null === intf) {
throw new Ex(arguments, messagePrefix + ("idl not found: '" + interfaceName + "'"));
}
errors = [];
_ref = intf.methods;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
intfMethod = _ref[_i];
classMethod = klass.prototype[intfMethod.name];
printName = klass.name + "::" + intfMethod.name;
if (null === classMethod) {
errors.push(messagePrefix + ("method not implemented: '" + printName + "'"));
continue;
}
if (classMethod.length !== intfMethod.parameters.length) {
if (classMethod.length !== intfMethod.parameters.length + 1) {
errors.push(messagePrefix + ("wrong number of parameters: '" + printName + "'"));
continue;
}
}
}
for (propertyName in klass.prototype) {
if (klass.prototype.hasOwnProperty(propertyName)) {
continue;
}
if (propertyName.match(/^_.*/)) {
continue;
}
printName = klass.name + "::" + propertyName;
if (!intf.methods[propertyName]) {
errors.push(messagePrefix + ("method should not be implemented: '" + printName + "'"));
continue;
}
}
if (!errors.length) {
return;
}
_results = [];
for (_j = 0, _len1 = errors.length; _j < _len1; _j++) {
error = errors[_j];
_results.push(require("./Weinre").logError(error));
}
return _results;
};
IDLTools.buildProxyForIDL = function(proxyObject, interfaceName) {
var intf, intfMethod, messagePrefix, _i, _len, _ref, _results;
intf = IDLTools.getIDL(interfaceName);
messagePrefix = "building proxy for IDL " + interfaceName + ": ";
if (null === intf) {
throw new Ex(arguments, messagePrefix + ("idl not found: '" + interfaceName + "'"));
}
_ref = intf.methods;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
intfMethod = _ref[_i];
_results.push(proxyObject[intfMethod.name] = getProxyMethod(intf, intfMethod));
}
return _results;
};
return IDLTools;
})();
getProxyMethod = function(intf, method) {
var proxyMethod, result;
result = proxyMethod = function() {
var args, callbackId;
callbackId = null;
args = [].slice.call(arguments);
if (args.length > 0) {
if (typeof args[args.length - 1] === "function") {
callbackId = Callback.register(args[args.length - 1]);
args = args.slice(0, args.length - 1);
}
}
while (args.length < method.parameters.length) {
args.push(null);
}
args.push(callbackId);
return this.__invoke(intf.name, method.name, args);
};
result.displayName = intf.name + "__" + method.name;
return result;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/MessageDispatcher.amd.js
;modjewel.define("weinre/common/MessageDispatcher", function(require, exports, module) {
var Binding, Callback, Ex, IDLTools, InspectorBackend, MessageDispatcher, Verbose, WebSocketXhr, Weinre,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Weinre = require('./Weinre');
WebSocketXhr = require('./WebSocketXhr');
IDLTools = require('./IDLTools');
Binding = require('./Binding');
Ex = require('./Ex');
Callback = require('./Callback');
Verbose = false;
InspectorBackend = null;
module.exports = MessageDispatcher = (function() {
function MessageDispatcher(url, id) {
if (!id) {
id = "anonymous";
}
this._url = url;
this._id = id;
this.error = null;
this._opening = false;
this._opened = false;
this._closed = false;
this._interfaces = {};
this._open();
}
MessageDispatcher.setInspectorBackend = function(inspectorBackend) {
return InspectorBackend = inspectorBackend;
};
MessageDispatcher.verbose = function(value) {
if (arguments.length >= 1) {
Verbose = !!value;
}
return Verbose;
};
MessageDispatcher.prototype._open = function() {
if (this._opened || this._opening) {
return;
}
if (this._closed) {
throw new Ex(arguments, "socket has already been closed");
}
this._opening = true;
this._socket = new WebSocketXhr(this._url, this._id);
this._socket.addEventListener("open", Binding(this, "_handleOpen"));
this._socket.addEventListener("error", Binding(this, "_handleError"));
this._socket.addEventListener("message", Binding(this, "_handleMessage"));
return this._socket.addEventListener("close", Binding(this, "_handleClose"));
};
MessageDispatcher.prototype.close = function() {
if (this._closed) {
return;
}
this._opened = false;
this._closed = true;
return this._socket.close();
};
MessageDispatcher.prototype.send = function(data) {
return this._socket.send(data);
};
MessageDispatcher.prototype.getWebSocket = function() {
return this._socket;
};
MessageDispatcher.prototype.registerInterface = function(intfName, intf, validate) {
if (validate) {
IDLTools.validateAgainstIDL(intf.constructor, intfName);
}
if (this._interfaces[intfName]) {
throw new Ex(arguments, "interface " + intfName + " has already been registered");
}
return this._interfaces[intfName] = intf;
};
MessageDispatcher.prototype.createProxy = function(intfName) {
var proxy, self, __invoke;
proxy = {};
IDLTools.buildProxyForIDL(proxy, intfName);
self = this;
proxy.__invoke = __invoke = function(intfName, methodName, args) {
return self._sendMethodInvocation(intfName, methodName, args);
};
return proxy;
};
MessageDispatcher.prototype._sendMethodInvocation = function(intfName, methodName, args) {
var data;
if (typeof intfName !== "string") {
throw new Ex(arguments, "expecting intf parameter to be a string");
}
if (typeof methodName !== "string") {
throw new Ex(arguments, "expecting method parameter to be a string");
}
data = {
"interface": intfName,
method: methodName,
args: args
};
data = JSON.stringify(data);
this._socket.send(data);
if (Verbose) {
return Weinre.logDebug(this.constructor.name + ("[" + this._url + "]: send " + intfName + "." + methodName + "(" + (JSON.stringify(args)) + ")"));
}
};
MessageDispatcher.prototype.getState = function() {
if (this._opening) {
return "opening";
}
if (this._opened) {
return "opened";
}
if (this._closed) {
return "closed";
}
return "unknown";
};
MessageDispatcher.prototype.isOpen = function() {
return this._opened === true;
};
MessageDispatcher.prototype._handleOpen = function(event) {
this._opening = false;
this._opened = true;
this.channel = event.channel;
Callback.setConnectorChannel(this.channel);
if (Verbose) {
return Weinre.logDebug(this.constructor.name + ("[" + this._url + "]: opened"));
}
};
MessageDispatcher.prototype._handleError = function(message) {
this.error = message;
this.close();
if (Verbose) {
return Weinre.logDebug(this.constructor.name + ("[" + this._url + "]: error: ") + message);
}
};
MessageDispatcher.prototype._handleMessage = function(message) {
var args, data, e, intf, intfName, method, methodName, methodSignature, skipErrorForMethods;
skipErrorForMethods = ['domContentEventFired', 'loadEventFired', 'childNodeRemoved'];
try {
data = JSON.parse(message.data);
} catch (_error) {
e = _error;
throw new Ex(arguments, "invalid JSON data received: " + e + ": '" + message.data + "'");
}
intfName = data["interface"];
methodName = data.method;
args = data.args;
methodSignature = "" + intfName + "." + methodName + "()";
intf = this._interfaces.hasOwnProperty(intfName) && this._interfaces[intfName];
if (!intf && InspectorBackend && intfName.match(/.*Notify/)) {
intf = InspectorBackend.getRegisteredDomainDispatcher(intfName.substr(0, intfName.length - 6));
}
if (!intf) {
Weinre.notImplemented("weinre: request for non-registered interface: " + methodSignature);
return;
}
methodSignature = intf.constructor.name + ("." + methodName + "()");
method = intf[methodName];
if (typeof method !== "function") {
Weinre.notImplemented(methodSignature);
return;
}
try {
method.apply(intf, args);
} catch (_error) {
e = _error;
if (__indexOf.call(skipErrorForMethods, methodName) < 0) {
Weinre.logError(("weinre: invocation exception on " + methodSignature + ": ") + e);
}
}
if (Verbose) {
return Weinre.logDebug(this.constructor.name + ("[" + this._url + "]: recv " + intfName + "." + methodName + "(" + (JSON.stringify(args)) + ")"));
}
};
MessageDispatcher.prototype._handleClose = function() {
this._reallyClosed = true;
if (Verbose) {
return Weinre.logDebug(this.constructor.name + ("[" + this._url + "]: closed"));
}
};
return MessageDispatcher;
})();
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/MethodNamer.amd.js
;modjewel.define("weinre/common/MethodNamer", function(require, exports, module) {
var MethodNamer,
__hasProp = {}.hasOwnProperty;
module.exports = MethodNamer = (function() {
function MethodNamer() {}
MethodNamer.setNamesForClass = function(aClass) {
var key, val, _ref, _results;
for (key in aClass) {
if (!__hasProp.call(aClass, key)) continue;
val = aClass[key];
if (typeof val === "function") {
val.signature = "" + aClass.name + "::" + key;
val.displayName = key;
val.name = key;
}
}
_ref = aClass.prototype;
_results = [];
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
val = _ref[key];
if (typeof val === "function") {
val.signature = "" + aClass.name + "." + key;
val.displayName = key;
_results.push(val.name = key);
} else {
_results.push(void 0);
}
}
return _results;
};
return MethodNamer;
})();
MethodNamer.setNamesForClass(module.exports);
});
;
// weinre/common/StackTrace.amd.js
;modjewel.define("weinre/common/StackTrace", function(require, exports, module) {
var StackTrace, getTrace;
module.exports = StackTrace = (function() {
function StackTrace(args) {
if (!args || !args.callee) {
throw Error("first parameter to " + arguments.callee.signature + " must be an Arguments object");
}
this.trace = getTrace(args);
}
StackTrace.dump = function(args) {
var stackTrace;
args = args || arguments;
stackTrace = new StackTrace(args);
return stackTrace.dump();
};
StackTrace.prototype.dump = function() {
var frame, _i, _len, _ref, _results;
console.log("StackTrace:");
_ref = this.trace;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
frame = _ref[_i];
_results.push(console.log(" " + frame));
}
return _results;
};
return StackTrace;
})();
getTrace = function(args) {
var err, func, result, visitedFuncs;
result = [];
visitedFuncs = [];
func = args.callee;
while (func) {
if (func.signature) {
result.push(func.signature);
} else if (func.displayName) {
result.push(func.displayName);
} else if (func.name) {
result.push(func.name);
} else {
result.push("<anonymous>");
}
if (-1 !== visitedFuncs.indexOf(func)) {
result.push("... recursion");
return result;
}
visitedFuncs.push(func);
try {
func = func.caller;
} catch (_error) {
err = _error;
func = null;
}
}
return result;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/WebSocketXhr.amd.js
;modjewel.define("weinre/common/WebSocketXhr", function(require, exports, module) {
var EventListeners, Ex, HookLib, WebSocketXhr, Weinre, _xhrEventHandler;
Ex = require('./Ex');
Weinre = require('./Weinre');
HookLib = require('./HookLib');
EventListeners = require('./EventListeners');
module.exports = WebSocketXhr = (function() {
WebSocketXhr.CONNECTING = 0;
WebSocketXhr.OPEN = 1;
WebSocketXhr.CLOSING = 2;
WebSocketXhr.CLOSED = 3;
function WebSocketXhr(url, id) {
this.initialize(url, id);
}
WebSocketXhr.prototype.initialize = function(url, id) {
if (!id) {
id = "anonymous";
}
this.readyState = WebSocketXhr.CONNECTING;
this._url = url;
this._id = id;
this._urlChannel = null;
this._queuedSends = [];
this._sendInProgress = true;
this._listeners = {
open: new EventListeners(),
message: new EventListeners(),
error: new EventListeners(),
close: new EventListeners()
};
return this._getChannel();
};
WebSocketXhr.prototype._getChannel = function() {
var body;
body = JSON.stringify({
id: this._id
});
return this._xhr(this._url, "POST", body, this._handleXhrResponseGetChannel);
};
WebSocketXhr.prototype._handleXhrResponseGetChannel = function(xhr) {
var e, object;
if (xhr.status !== 200) {
return this._handleXhrResponseError(xhr);
}
try {
object = JSON.parse(xhr.responseText);
} catch (_error) {
e = _error;
this._fireEventListeners("error", {
message: "non-JSON response from channel open request"
});
this.close();
return;
}
if (!object.channel) {
this._fireEventListeners("error", {
message: "channel open request did not include a channel"
});
this.close();
return;
}
this._urlChannel = this._url + "/" + object.channel;
this.readyState = WebSocketXhr.OPEN;
this._fireEventListeners("open", {
message: "open",
channel: object.channel
});
this._sendInProgress = false;
this._sendQueued();
return this._readLoop();
};
WebSocketXhr.prototype._readLoop = function() {
if (this.readyState === WebSocketXhr.CLOSED) {
return;
}
if (this.readyState === WebSocketXhr.CLOSING) {
return;
}
return this._xhr(this._urlChannel, "GET", "", this._handleXhrResponseGet);
};
WebSocketXhr.prototype._handleXhrResponseGet = function(xhr) {
var data, datum, e, self, _i, _len, _results;
self = this;
if (xhr.status !== 200) {
return this._handleXhrResponseError(xhr);
}
try {
datum = JSON.parse(xhr.responseText);
} catch (_error) {
e = _error;
this.readyState = WebSocketXhr.CLOSED;
this._fireEventListeners("error", {
message: "non-JSON response from read request"
});
return;
}
HookLib.ignoreHooks(function() {
return setTimeout((function() {
return self._readLoop();
}), 0);
});
_results = [];
for (_i = 0, _len = datum.length; _i < _len; _i++) {
data = datum[_i];
_results.push(self._fireEventListeners("message", {
data: data
}));
}
return _results;
};
WebSocketXhr.prototype.send = function(data) {
if (typeof data !== "string") {
throw new Ex(arguments, this.constructor.name + ".send");
}
this._queuedSends.push(data);
if (this._sendInProgress) {
return;
}
return this._sendQueued();
};
WebSocketXhr.prototype._sendQueued = function() {
var datum;
if (this._queuedSends.length === 0) {
return;
}
if (this.readyState === WebSocketXhr.CLOSED) {
return;
}
if (this.readyState === WebSocketXhr.CLOSING) {
return;
}
datum = JSON.stringify(this._queuedSends);
this._queuedSends = [];
this._sendInProgress = true;
return this._xhr(this._urlChannel, "POST", datum, this._handleXhrResponseSend);
};
WebSocketXhr.prototype._handleXhrResponseSend = function(xhr) {
var httpSocket;
httpSocket = this;
if (xhr.status !== 200) {
return this._handleXhrResponseError(xhr);
}
this._sendInProgress = false;
return HookLib.ignoreHooks(function() {
return setTimeout((function() {
return httpSocket._sendQueued();
}), 0);
});
};
WebSocketXhr.prototype.close = function() {
this._sendInProgress = true;
this.readyState = WebSocketXhr.CLOSING;
this._fireEventListeners("close", {
message: "closing",
wasClean: true
});
return this.readyState = WebSocketXhr.CLOSED;
};
WebSocketXhr.prototype.addEventListener = function(type, listener, useCapture) {
return this._getListeners(type).add(listener, useCapture);
};
WebSocketXhr.prototype.removeEventListener = function(type, listener, useCapture) {
return this._getListeners(type).remove(listener, useCapture);
};
WebSocketXhr.prototype._fireEventListeners = function(type, event) {
if (this.readyState === WebSocketXhr.CLOSED) {
return;
}
event.target = this;
return this._getListeners(type).fire(event);
};
WebSocketXhr.prototype._getListeners = function(type) {
var listeners;
listeners = this._listeners[type];
if (null === listeners) {
throw new Ex(arguments, "invalid event listener type: '" + type + "'");
}
return listeners;
};
WebSocketXhr.prototype._handleXhrResponseError = function(xhr) {
if (xhr.status === 404) {
this.close();
return;
}
this._fireEventListeners("error", {
target: this,
status: xhr.status,
message: "error from XHR invocation: " + xhr.statusText
});
return Weinre.logError(("error from XHR invocation: " + xhr.status + ": ") + xhr.statusText);
};
WebSocketXhr.prototype._xhr = function(url, method, data, handler) {
var xhr;
if (null === handler) {
throw new Ex(arguments, "handler must not be null");
}
xhr = (XMLHttpRequest.noConflict ? new XMLHttpRequest.noConflict() : new XMLHttpRequest());
xhr.httpSocket = this;
xhr.httpSocketHandler = handler;
xhr.onreadystatechange = function() {
return _xhrEventHandler(xhr);
};
HookLib.ignoreHooks(function() {
return xhr.open(method, url, true);
});
xhr.setRequestHeader("Content-Type", "text/plain");
return HookLib.ignoreHooks(function() {
return xhr.send(data);
});
};
return WebSocketXhr;
})();
_xhrEventHandler = function(xhr) {
if (xhr.readyState !== 4) {
return;
}
return xhr.httpSocketHandler.call(xhr.httpSocket, xhr);
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/common/Weinre.amd.js
;modjewel.define("weinre/common/Weinre", function(require, exports, module) {
var ConsoleLogger, Ex, IDLTools, StackTrace, Weinre, consoleLogger, getLogger, logger, _notImplemented, _showNotImplemented;
Ex = require('./Ex');
IDLTools = require('./IDLTools');
StackTrace = require('./StackTrace');
_notImplemented = {};
_showNotImplemented = false;
logger = null;
module.exports = Weinre = (function() {
function Weinre() {
throw new Ex(arguments, "this class is not intended to be instantiated");
}
Weinre.addIDLs = function(idls) {
return IDLTools.addIDLs(idls);
};
Weinre.deprecated = function() {
return StackTrace.dump(arguments);
};
Weinre.notImplemented = function(thing) {
if (_notImplemented[thing]) {
return;
}
_notImplemented[thing] = true;
if (!_showNotImplemented) {
return;
}
return Weinre.logWarning(thing + " not implemented");
};
Weinre.showNotImplemented = function() {
var key, _results;
_showNotImplemented = true;
_results = [];
for (key in _notImplemented) {
_results.push(Weinre.logWarning(key + " not implemented"));
}
return _results;
};
Weinre.logError = function(message) {
return getLogger().logError(message);
};
Weinre.logWarning = function(message) {
return getLogger().logWarning(message);
};
Weinre.logInfo = function(message) {
return getLogger().logInfo(message);
};
Weinre.logDebug = function(message) {
return getLogger().logDebug(message);
};
return Weinre;
})();
ConsoleLogger = (function() {
function ConsoleLogger() {}
ConsoleLogger.prototype.logError = function(message) {
return console.log("error: " + message);
};
ConsoleLogger.prototype.logWarning = function(message) {
return console.log("warning: " + message);
};
ConsoleLogger.prototype.logInfo = function(message) {
return console.log("info: " + message);
};
ConsoleLogger.prototype.logDebug = function(message) {
return console.log("debug: " + message);
};
return ConsoleLogger;
})();
consoleLogger = new ConsoleLogger();
getLogger = function() {
if (logger) {
return logger;
}
if (Weinre.client) {
logger = Weinre.WeinreClientCommands;
return logger;
}
if (Weinre.target) {
logger = Weinre.WeinreTargetCommands;
return logger;
}
return consoleLogger;
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/target/BrowserHacks.amd.js
;modjewel.define("weinre/target/BrowserHacks", function(require, exports, module) {
var BrowserHacks;
BrowserHacks = function() {
if (typeof document.addEventListener === "undefined") {
alert("Oops. It seems the page runs in compatibility mode. Please fix it and try again.");
return;
}
if (typeof window.Element === "undefined") {
window.Element = function() {};
}
if (typeof window.Node === "undefined") {
window.Node = function() {};
}
if (!Object.getPrototypeOf) {
Object.getPrototypeOf = function(object) {
if (!object.__proto__) {
throw new Error("This vm does not support __proto__ and getPrototypeOf. Script requires any of them to operate correctly.");
}
return object.__proto__;
};
}
};
BrowserHacks();
});
;
// weinre/target/CheckForProblems.amd.js
;modjewel.define("weinre/target/CheckForProblems", function(require, exports, module) {
var CheckForProblems, checkForOldPrototypeVersion;
module.exports = CheckForProblems = (function() {
function CheckForProblems() {}
CheckForProblems.check = function() {
return checkForOldPrototypeVersion();
};
return CheckForProblems;
})();
checkForOldPrototypeVersion = function() {
var badVersion;
badVersion = false;
if (typeof Prototype === "undefined") {
return;
}
if (!Prototype.Version) {
return;
}
if (Prototype.Version.match(/^1\.5.*/)) {
badVersion = true;
}
if (Prototype.Version.match(/^1\.6.*/)) {
badVersion = true;
}
if (badVersion) {
return alert("Sorry, weinre is not support in versions of Prototype earlier than 1.7");
}
};
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/target/Console.amd.js
;modjewel.define("weinre/target/Console", function(require, exports, module) {
var Console, MessageLevel, MessageSource, MessageType, OriginalConsole, RemoteConsole, Timeline, UsingRemote, Weinre;
Weinre = require('../common/Weinre');
Timeline = require('../target/Timeline');
UsingRemote = false;
RemoteConsole = null;
OriginalConsole = null;
MessageSource = {
HTML: 0,
WML: 1,
XML: 2,
JS: 3,
CSS: 4,
Other: 5
};
MessageType = {
Log: 0,
Object: 1,
Trace: 2,
StartGroup: 3,
StartGroupCollapsed: 4,
EndGroup: 5,
Assert: 6,
UncaughtException: 7,
Result: 8
};
MessageLevel = {
Tip: 0,
Log: 1,
Warning: 2,
Error: 3,
Debug: 4
};
module.exports = Console = (function() {
function Console() {}
Object.defineProperty(Console, 'original', {
get: function() {
return OriginalConsole;
}
});
Console.useRemote = function(value) {
var oldValue;
if (arguments.length === 0) {
return UsingRemote;
}
oldValue = UsingRemote;
UsingRemote = !!value;
if (UsingRemote) {
window.console = RemoteConsole;
} else {
window.console = OriginalConsole;
}
return oldValue;
};
Console.prototype._generic = function(level, messageParts) {
var message, messagePart, parameters, payload, _i, _len;
message = messageParts[0].toString();
parameters = [];
for (_i = 0, _len = messageParts.length; _i < _len; _i++) {
messagePart = messageParts[_i];
parameters.push(Weinre.injectedScript.wrapObjectForConsole(messagePart, true));
}
payload = {
source: MessageSource.JS,
type: MessageType.Log,
level: level,
message: message,
parameters: parameters
};
return Weinre.wi.ConsoleNotify.addConsoleMessage(payload);
};
Console.prototype.log = function() {
return this._generic(MessageLevel.Log, [].slice.call(arguments));
};
Console.prototype.debug = function() {
return this._generic(MessageLevel.Debug, [].slice.call(arguments));
};
Console.prototype.error = function() {
return this._generic(MessageLevel.Error, [].slice.call(arguments));
};
Console.prototype.info = function() {
return this._generic(MessageLevel.Log, [].slice.call(arguments));
};
Console.prototype.warn = function() {
return this._generic(MessageLevel.Warning, [].slice.call(arguments));
};
Console.prototype.dir = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.dirxml = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.trace = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.assert = function(condition) {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.count = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.markTimeline = function(message) {
return Timeline.addRecord_Mark(message);
};
Console.prototype.lastWMLErrorMessage = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.profile = function(title) {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.profileEnd = function(title) {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.time = function(title) {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.timeEnd = function(title) {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.group = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.groupCollapsed = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
Console.prototype.groupEnd = function() {
return Weinre.notImplemented(arguments.callee.signature);
};
return Console;
})();
RemoteConsole = new Console();
OriginalConsole = window.console || {};
RemoteConsole.__original = OriginalConsole;
OriginalConsole.__original = OriginalConsole;
require("../common/MethodNamer").setNamesForClass(module.exports);
});
;
// weinre/target/CSSStore.amd.js
;modjewel.define("weinre/target/CSSStore", function(require, exports, module) {
var CSSStore, IDGenerator, Weinre, _elementMatchesSelector, _fallbackMatchesSelector, _getMappableId, _getMappableObject, _mozMatchesSelector, _msMatchesSelector, _webkitMatchesSelector;
IDGenerator = require('../common/IDGenerator');
Weinre = require('../common/Weinre');
_elementMatchesSelector = null;
module.exports = CSSStore = (function() {
function CSSStore() {
this.styleSheetMap = {};
this.styleRuleMap = {};
this.styleDeclMap = {};
this.testElement = document.createElement("div");
}
CSSStore.prototype.getInlineStyle = function(node) {
var cssProperty, styleObject, _i, _len, _ref;
styleObject = this._buildMirrorForStyle(node.style, true);
_ref = styleObject.cssProperties;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
cssProperty = _ref[_i];
cssProperty.status = "style";
}
return styleObject;
};
CSSStore.prototype.getComputedStyle = function(node) {
var styleObject;
if (!node) {
return {};
}
if (node.nodeType !== Node.ELEMENT_NODE) {
return {};
}
styleObject = this._buildMirrorForStyle(window.getComputedStyle(node), false);
return styleObject;
};
CSSStore.prototype.getMatchedCSSRules = function(node) {
var cssRule, err, object, result, styleSheet, _i, _j, _len, _len1, _ref, _ref1;
result = [];
try {
_ref = document.styleSheets;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
styleSheet = _ref[_i];
if (!styleSheet.cssRules) {
continue;
}
_ref1 = styleSheet.cssRules;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
cssRule = _ref1[_j];
if (!_elementMatchesSelector(node, cssRule.selectorText)) {
continue;
}
object = {};
object.ruleId = this._getStyleRuleId(cssRule);
object.selectorText = cssRule.selectorText;
object.style = this._buildMirrorForStyle(cssRule.style, true);
result.push(object);
}
}
} catch (_error) {
err = _error;
return result;
}
return result;
};
CSSStore.prototype.getStyleAttributes = function(node) {
var result;
result = {};
return result;
};
CSSStore.prototype.getPseudoElements = function(node) {
var result;
result = [];
return result;
};
CSSStore.prototype.setPropertyText = function(styleId, propertyIndex, text, overwrite) {
var compare, i, key, mirror, properties, propertyIndices, propertyMirror, styleDecl;
styleDecl = Weinre.cssStore._getStyleDecl(styleId);
if (!styleDecl) {
Weinre.logWarning("requested style not available: " + styleId);
return null;
}
mirror = styleDecl.__weinre__mirror;
if (!mirror) {
Weinre.logWarning("requested mirror not available: " + styleId);
return null;
}
properties = mirror.cssProperties;
propertyMirror = this._parseProperty(text);
if (null === propertyMirror) {
this._removePropertyFromMirror(mirror, propertyIndex);
properties = mirror.cssProperties;
} else {
this._removePropertyFromMirror(mirror, propertyIndex);
properties = mirror.cssProperties;
propertyIndices = {};
i = 0;
while (i < properties.length) {
propertyIndices[properties[i].name] = i;
i++;
}
i = 0;
while (i < propertyMirror.cssProperties.length) {
if (propertyIndices[propertyMirror.cssProperties[i].name] != null) {
properties[propertyIndices[propertyMirror.cssProperties[i].name]] = propertyMirror.cssProperties[i];
} else {
properties.push(propertyMirror.cssProperties[i]);
}
i++;
}
for (key in propertyMirror.shorthandValues) {
mirror.shorthandValues[key] = propertyMirror.shorthandValues[key];
}
}
properties.sort(compare = function(p1, p2) {
if (p1.name < p2.name) {
return -1;
} else if (p1.name > p2.name) {
return 1;
} else {
return 0;
}
});
this._setStyleFromMirror(styleDecl);
return mirror;
};
CSSStore.prototype._removePropertyFromMirror = function(mirror, index) {
var i, newProperties, properties, property;
properties = mirror.cssProperties;
if (index >= properties.length) {
return;
}
property = properties[index];
properties[index] = null;
if (mirror.shorthandValues[property.name]) {
delete mirror.shorthandValues[property.name];
i = 0;
while (i < properties.length) {
if (properties[i]) {
if (properties[i].shorthandName === property.name) {
properties[i] = null;
}
}
i++;
}
}
newProperties = [];
i = 0;
while (i < properties.length) {
if (properties[i]) {
newProperties.push(properties[i]);
}
i++;
}
return mirror.cssProperties = newProperties;
};
CSSStore.prototype.toggleProperty = function(styleId, propertyIndex, disable) {
var cssProperty, mirror, styleDecl;
styleDecl = Weinre.cssStore._getStyleDecl(styleId);
if (!styleDecl) {
Weinre.logWarning("requested style not available: " + styleId);
return null;
}
mirror = styleDecl.__weinre__mirror;
if (!mirror) {
Weinre.logWarning("requested mirror not available: " + styleId);
return null;
}
cssProperty = mirror.cssProperties[propertyIndex];
if (!cssProperty) {
Weinre.logWarning(("requested property not available: " + styleId + ": ") + propertyIndex);
return null;
}
if (disable) {
cssProperty.status = "disabled";
} else {
cssProperty.status = "active";
}
this._setStyleFromMirror(styleDecl);
return mirror;
};
CSSStore.prototype._setStyleFromMirror = function(styleDecl) {
var cssProperties, cssText, property, _i, _len;
cssText = [];
cssProperties = styleDecl.__weinre__mirror.cssProperties;
cssText = "";
for (_i = 0, _len = cssProperties.length; _i < _len; _i++) {
property = cssProperties[_i];
if (!property.parsedOk) {
continue;
}
if (property.status === "disabled") {
continue;
}
if (property.shorthandName) {
continue;
}
cssText += property.name + ": " + property.value;
if (property.priority === "important") {
cssText += " !important; ";
} else {
cssText += "; ";
}
}
return styleDecl.cssText = cssText;
};
CSSStore.prototype._buildMirrorForStyle = function(styleDecl, bind) {
var i, name, properties, property, result, shorthandName;
result = {
properties: {},
cssProperties: []
};
if (!styleDecl) {
return result;
}
if (bind) {
result.styleId = this._getStyleDeclId(styleDecl);
styleDecl.__weinre__mirror = result;
}
result.properties.width = styleDecl.getPropertyValue("width") || "";
result.properties.height = styleDecl.getPropertyValue("height") || "";
result.cssText = styleDecl.cssText;
result.shorthandValues = {};
properties = [];
if (styleDecl) {
i = 0;
while (i < styleDecl.length) {
property = {};
name = styleDecl.item(i);
property.name = name;
property.priority = styleDecl.getPropertyPriority(name);
property.implicit = typeof styleDecl.isPropertyImplicit !== "undefined" ? styleDecl.isPropertyImplicit(name) : true;
property.shorthandName = typeof styleDecl.getPropertyShorthand !== "undefined" ? styleDecl.getPropertyShorthand(name) || "" : "";
property.status = (property.shorthandName ? "style" : "active");
property.parsedOk = true;
property.value = styleDecl.getPropertyValue(name);
properties.push(property);
if (property.shorthandName) {
shorthandName = property.shorthandName;
if (!result.shorthandValues[shorthandName]) {
result.shorthandValues[shorthandName] = styleDecl.getPropertyValue(shorthandName);
property = {};
property.name = shorthandName;
property.priority = styleDecl.getPropertyPriority(shorthandName);
property.implicit = styleDecl.isPropertyImplicit(shorthandName);
property.shorthandName = "";
property.status = "active";
property