__emit: function (type, name, args) { if (name === 'ready' || name === 'beforedataready') { var listeners = this.__lookupListener(type, name); $$.forEach(listeners, function (current) { current.handler.apply(current.listener, args); }); return; } if (name === 'dataready') { this.__dataReady = true; } if (!this.__dataReady) { return; } var listeners = this.__lookupListener(type, name); $$.forEach(listeners, function (current) { current.handler.apply(current.listener, args); }); },
__restrictRemoveCellBorder: function (location, row) { var styleData = this.getActiveSheet().style; var rowsData = styleData.rows; var currentRow = rowsData[row]; if ($$.isNdef(currentRow) || $$.isNdef(currentRow.cells)) { return; } $$.forEach(currentRow.cells, function (currentCell, col) { var details = this.getCellClassifyStyleDetails('borders', row, col); /* --- 空检查 startIndex --- */ if (!this.__hasBorder(location, details)) { return; } /* --- 空检查 endIndex --- */ details = $$.clone(details.border); details[location] = NONE; //currentCell.si = this.rs('generate.border', details, currentCell.si); currentCell.si = this.getModule('StylePool').generateBorder(details, currentCell.si); }, this); },
__drawHeaderColumn: function () { var visualData = this.visualData; var screen = this.gridlineScreen; var colWidths = visualData.colWidths; var colPoints = visualData.colPoints; var headWidth = visualData.headWidth; var headHeight = visualData.headHeight; $$.forEach(visualData.cols, function (colIndex, index) { var title = $$.indexToTitle(colIndex); var x = headWidth + colPoints[index] + colWidths[index] / 2 + OFFSET; var y = headHeight / 2; screen.save(); screen.beginPath(); screen.rect(headWidth + colPoints[index] + OFFSET, 0, colWidths[index], headHeight); screen.clip(); screen.fillText(title, x, y + 1); screen.restore(); }); },
$$.forEach(rowsData, function (currentRow, row) { if (row < startRow) { return; } if (row > endRow) { return false; } if (!currentRow.cells) { return; } $$.forEach(currentRow.cells, function (currentCell, col) { if (col < startCol) { return; } if (col > endCol) { return false; } if ($$.isDefined(currentCell.hyperlink)) { result = true; return false; } }); if (result) { return false; } });
ExtensionOptionsImpl.prototype.setupElementProperties = function() { utils.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { // Get the size constraints from the <extensionoptions> tag, or use the // defaults if not specified if (this.element.hasAttribute(attributeName)) { this[attributeName] = this.element.getAttribute(attributeName); } else { this[attributeName] = AUTO_SIZE_ATTRIBUTES[attributeName]; } Object.defineProperty(this.element, attributeName, { get: function() { return this[attributeName]; }.bind(this), set: function(value) { this.element.setAttribute(attributeName, value); }.bind(this), enumerable: true }); }, this); this.resetSizeConstraintsIfInvalid(); Object.defineProperty(this.element, 'extension', { get: function() { return this.element.getAttribute('extension'); }.bind(this), set: function(value) { this.element.setAttribute('extension', value); }.bind(this), enumerable: true }); };
clear: function() { this.freeze(); if(this.model) this.model.freeze(); utils.forEach(this.components, function(c) { c.clear(); }); }
__restrictAddCellBorder: function (location, borderValue, col) { var styleData = this.getActiveSheet().style; var rowsData = styleData.rows; $$.forEach(rowsData, function (currentRow, row) { if ($$.isNdef(currentRow.cells) || $$.isNdef(currentRow.cells[col])) { return; } var currentCell = currentRow.cells[col]; var details = this.getCellClassifyStyleDetails('borders', row, col); if ($$.isNdef(details)) { details = $$.clone(DEFAULT_BORDER_STYLE); } else { details = $$.clone(details.border); } details[location] = borderValue; currentCell.si = this.getModule('StylePool').generateBorder(details, currentCell.si); //currentCell.si = this.rs('generate.border', details, currentCell.si); }, this); },
loadComponents: function() { var _this = this; var config; var comp; //use the same name for collection this.components = []; //external dependencies let this model know what it //has to wait for if(this.model) { this.model.resetDeps(); } // Loops through components, loading them. utils.forEach(this._components_config, function(c) { if(!c.component) { utils.error('Error loading component: name not provided'); return; } comp = (utils.isString(c.component)) ? Component.get(c.component) : c.component; if(!comp) return; config = utils.extend(c, { name: c.component, ui: _this._uiMapping(c.placeholder, c.ui) }); //instantiate new subcomponent var subcomp = new comp(config, _this); var c_model = c.model || []; subcomp.model = _this._modelMapping(subcomp.name, c_model, subcomp.model_expects, subcomp.model_binds); _this.components.push(subcomp); }); },
setSid: function (sid, startIndex, endIndex) { if ($$.isNdef(sid)) { return this.clearStyle(startIndex, endIndex); } var styleData = this.getActiveSheet().style; var rowsData = styleData.rows; var currentRow; // 清除行上所有的独立单元格 for (var i = startIndex; i <= endIndex; i++) { currentRow = rowsData[i]; if ($$.isNdef(currentRow) || $$.isNdef(currentRow.cells)) { continue; } $$.forEach(currentRow.cells, function (currentCell, col) { delete currentRow.cells[col]; }, this); } // 重置行样式 for (var i = startIndex; i <= endIndex; i++) { if ($$.isNdef(rowsData[i])) { rowsData[i] = {}; } rowsData[i] = { si: sid, customFormat: 1 }; } },
clearStyle: function (startIndex, endIndex) { var styleData = this.getActiveSheet().style; var rowsData = styleData.rows; var currentRow; // 清除行上独立单元格 for (var i = startIndex; i <= endIndex; i++) { currentRow = rowsData[i]; if ($$.isNdef(currentRow) || $$.isNdef(currentRow.cells)) { continue; } $$.forEach(currentRow.cells, function (currentCell, col) { delete currentRow.cells[col]; }); } // 清除行样式 for (var i = startIndex; i <= endIndex; i++) { if ($$.isNdef(rowsData[i])) { rowsData[i] = {}; } currentRow = rowsData[i]; delete currentRow.si; currentRow.customFormat = 1; this.cleanRowStyle(i); } }
/** * Outputs the difference between two objects * @param {Object} obj prevailing object * @param {Object} compare comparison object * @returns {Object} resulting diff object */ function changedObj(obj, compare) { var acc = {}; utils.forEach(obj, function(val, name) { if(!(name in compare)) { acc[name] = val; return true; } //if the same, no need to check deeper if(JSON.stringify(val) === JSON.stringify(compare[name])) return true; else if(utils.isArray(val)) { acc[name] = val; } else if(utils.isObject(val)) { acc[name] = changedObj(val, compare[name]); } else if(utils.isDate(compare[name])) { var comp1 = val.toString(); //TODO: workaround for years only var comp2 = compare[name].getUTCFullYear().toString(); if(comp1 !== comp2) { acc[name] = val; } } else { acc[name] = val; } }); return acc; }
'send', function(message, callback) { // Validate message.data. var payloadSize = 0; forEach(message.data, function(property, value) { if (property.length == 0) throw new Error("One of data keys is empty."); var lowerCasedProperty = property.toLowerCase(); // Issue an error for forbidden prefixes of property names. if (lowerCasedProperty.startsWith("goog.") || lowerCasedProperty.startsWith("google") || property.startsWith("collapse_key")) { throw new Error("Invalid data key: " + property); } payloadSize += property.length + value.length; }); if (payloadSize > gcm.MAX_MESSAGE_SIZE) throw new Error("Payload exceeded allowed size limit. Payload size is: " + payloadSize); if (payloadSize == 0) throw new Error("No data to send."); return arguments; });
__drawHeaderRow: function () { var visualData = this.visualData; var screen = this.gridlineScreen; var rowHeights = visualData.rowHeights; var rowPoints = visualData.rowPoints; var headWidth = visualData.headWidth; var headHeight = visualData.headHeight; $$.forEach(visualData.rows, function (rowIndex, index) { var x = headWidth / 2; var y = headHeight + rowPoints[index] + rowHeights[index] / 2 + OFFSET; screen.save(); screen.beginPath(); screen.rect(0, headHeight + rowPoints[index] + OFFSET, headWidth, rowHeights[index]); screen.clip(); screen.fillText(rowIndex + 1, x, y + 1); screen.restore(); }); },
__drawContent: function () { var visualData = this.visualData; var layoutData = this.layoutData; var screen = this.contentScreen; screen.save(); screen.translate(visualData.headWidth, visualData.headHeight); $$.forEach(layoutData, function (currentRow) { $$.forEach(currentRow, function (currentCell) { if (!currentCell.contentInfo) { return; } // 是合并单元格,但是不是活动单元格,退出 if (currentCell.mergecell && !currentCell.active) { return; } this.__drawCellContent(currentCell); }, this); }, this); screen.restore(); },
this.objectNode_.addEventListener('-internal-' + eventname, function(e) { var evt = new Event(eventname, { bubbles: true }); var detail = e.detail ? JSON.parse(e.detail) : {}; forEach(attribs, function(i, attribName) { evt[attribName] = detail[attribName]; }); node.dispatchEvent(evt); });
function(targetId, message, options, responseCallback) { var connectOptions = {name: messaging.kMessageChannel}; forEach(options, function(k, v) { connectOptions[k] = v; }); var port = runtime.connect(targetId || runtime.id, connectOptions); messaging.sendMessageImpl(port, message, responseCallback); });
// Validate conditions and actions against specific schemas of this // event object type. // |rules| is an array of JSON objects that follow the Rule type of the // declarative extension APIs. |conditions| is an array of JSON type // identifiers that are allowed to occur in the conditions attribute of each // rule. Likewise, |actions| is an array of JSON type identifiers that are // allowed to occur in the actions attribute of each rule. function validateRules(rules, conditions, actions) { var conditionsSchema = buildArrayOfChoicesSchema(conditions); var actionsSchema = buildArrayOfChoicesSchema(actions); forEach(rules, function(i, rule) { validate([rule.conditions], [conditionsSchema]); validate([rule.actions], [actionsSchema]); }) };
var documentObserver = new WebKitMutationObserver(function(mutations) { forEach(mutations, function(i, mutation) { for (var i = 0, addedNode; addedNode = mutation.addedNodes[i]; i++) { if (addedNode.tagName == tagName) { cb(addedNode); } } }); });
messages.on('position-info-updated', function (message, pi) { utils.forEach(_watches, function (watch) { try { _getCurrentPosition(watch.win, watch.fail); } catch (e) { console.log(e); } }); });
forEach(mutations, function(i, mutation) { forEach(mutation.addedNodes, function(i, addedNode) { if (addedNode.nodeType == Node.ELEMENT_NODE) { if (addedNode.tagName == tagName) cb(addedNode); findChildTags(addedNode); } }); });
$$.forEach(layoutData, function (rowLayout) { $$.forEach(rowLayout, function (currentLayout) { if (!currentLayout.mergecell || !currentLayout.active) { return; } var rect = this.rs('get.visible.rect', currentLayout.mergecell.start, currentLayout.mergecell.end); screen.clearRect(rect.x, rect.y, rect.width, rect.height); }, this); }, this);
__overflowAddColumn: function (location, borderValue, row) { var styleData = this.getActiveSheet().style; var rowsData = styleData.rows; var colsData = styleData.cols; var globalStyle = styleData.globalStyle; $$.forEach(colsData, function (currentCol, col) { var sid = this.getColumnSid(col); // 和全局样式一致,则删除该列样式,并退出 if ($$.isNdef(currentCol.customFormat) || sid === globalStyle) { delete colsData[col]; return; } var currentRow = rowsData[row]; // 行存在且具有自定义样式,则跳过该行上的覆盖 if ($$.isDefined(currentRow) && $$.isDefined(currentRow.customFormat)) { return; } var details = this.getColumnClassifyStyleDetails('borders', col); if ($$.isNdef(details)) { details = $$.clone(DEFAULT_BORDER_STYLE); } else { details = $$.clone(details.border); } details[location] = borderValue; //sid = this.rs('generate.border', details, sid); sid = this.getModule('StylePool').generateBorder(details, sid); if ($$.isNdef(currentRow)) { rowsData[row] = {}; currentRow = rowsData[row]; } if ($$.isNdef(currentRow.cells)) { currentRow.cells = []; } // 当前处理的是独立单元格,则跳过 if ($$.isDefined(currentRow.cells[col])) { return; } currentRow.cells[col] = { si: sid }; }, this); },
var documentObserver = new WebKitMutationObserver(function(mutations) { forEach(mutations, function(i, mutation) { forEach(mutation.addedNodes, function(i, addedNode) { if (addedNode.nodeType == Node.ELEMENT_NODE) { if (addedNode.tagName == tagName) cb(addedNode); findChildTags(addedNode); } }); }); });
var getPattern = function (input) { var matchedIndex; utils.forEach(matchers, function (matcher, index) { if (matcher.test(input)) { matchedIndex = index; return false; } }); return matchedIndex === undefined ? null : patterns[matchedIndex]; };
function addProperties(m, parentDef) { var properties = parentDef.properties; if (!properties) return; forEach(properties, function(propertyName, propertyDef) { if (propertyName in m) return; // TODO(kalman): be strict like functions/events somehow. if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) return; if (!GetAvailability(schema.namespace + "." + propertyName).is_available || (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) { return; } var value = propertyDef.value; if (value) { // Values may just have raw types as defined in the JSON, such // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. // TODO(kalman): enforce that things with a "value" property can't // define their own types. var type = propertyDef.type || typeof(value); if (type === 'integer' || type === 'number') { value = parseInt(value); } else if (type === 'boolean') { value = value === 'true'; } else if (propertyDef['$ref']) { var ref = propertyDef['$ref']; var type = utils.loadTypeSchema(propertyDef['$ref'], schema); logging.CHECK(type, 'Schema for $ref type ' + ref + ' not found'); var constructor = createCustomType(type); var args = value; // For an object propertyDef, |value| is an array of constructor // arguments, but we want to pass the arguments directly (i.e. // not as an array), so we have to fake calling |new| on the // constructor. value = { __proto__: constructor.prototype }; $Function.apply(constructor, value, args); // Recursively add properties. addProperties(value, propertyDef); } else if (type === 'object') { // Recursively add properties. addProperties(value, propertyDef); } else if (type !== 'string') { throw new Error('NOT IMPLEMENTED (extension_api.json error): ' + 'Cannot parse values for type "' + type + '"'); } m[propertyName] = value; } }); };
exports.FindMatchingSelectors = function(cssSelectors) { var result = [] forEach(cssSelectors, function(index, selector) { try { if (document.querySelector(selector) != null) result.push(index); } catch (exception) { throw new Error("query Selector failed on '" + selector + "': " + exception.stack); } }); return result; };
utils.forEach(patternSpec, function (patternMatcher) { // Process single property object to obtain pattern and matcher. utils.forEach(patternMatcher, function (patternStr, matcherStr) { var parsedPattern = pattern.parse(patternStr), regExpMatcher = parseMatcher(matcherStr); matchers.push(regExpMatcher); patterns.push(parsedPattern); // Stop after one iteration. return false; }); });
function retrieveAll(prefix, callback) { var result = {}; if (prefix) { utils.forEach(cache, function (value) { if (value.prefix === prefix) { result[value.key] = value.value; } }); } if (callback) { callback(result); } }
translateStrings: function() { var t = this.getTranslationFunction(); var strings = this.placeholder.querySelectorAll('[data-vzb-translate]'); if(strings.length === 0) { return; } utils.forEach(strings, function(str) { if(!str || !str.getAttribute) { return; } str.innerHTML = t(str.getAttribute('data-vzb-translate')); }); },
function(tabId, message, options, responseCallback) { var connectInfo = { name: messaging.kMessageChannel }; if (options) { forEach(options, function(k, v) { connectInfo[k] = v; }); } var port = tabs.connect(tabId, connectInfo); messaging.sendMessageImpl(port, message, responseCallback); });