From b70a3addd356fd1d1e3de6ca520a4d9760f887ce Mon Sep 17 00:00:00 2001 From: Piotr Majewski Date: Sat, 8 Nov 2014 07:56:01 +0100 Subject: [PATCH] style: fix missing commas --- Gruntfile.js | 32 +-- mithril.js | 572 ++++++++++++++++++++++----------------------- mithril.min.js | 8 + mithril.min.js.map | 1 + 4 files changed, 311 insertions(+), 302 deletions(-) mode change 100644 => 100755 Gruntfile.js mode change 100644 => 100755 mithril.js create mode 100755 mithril.min.js create mode 100755 mithril.min.js.map diff --git a/Gruntfile.js b/Gruntfile.js old mode 100644 new mode 100755 index cf18babb..0affd13c --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,14 +1,14 @@ module.exports = function(grunt) { _ = require('lodash'); - var version = "0.1.23" + var version = "0.1.23"; - var inputFolder = "./docs" - var tempFolder = "./temp" - var archiveFolder = "./archive" - var outputFolder = "../mithril" + var inputFolder = "./docs"; + var tempFolder = "./temp"; + var archiveFolder = "./archive"; + var outputFolder = "../mithril"; - var guideLayout = "guide" + var guideLayout = "guide"; var guide = [ "auto-redrawing", "benchmarks", @@ -23,9 +23,9 @@ module.exports = function(grunt) { "refactoring", "routing", "tools", - "web-services", - ] - var apiLayout = "api" + "web-services" + ]; + var apiLayout = "api"; var api = [ "change-log", "roadmap", @@ -44,11 +44,11 @@ module.exports = function(grunt) { "mithril.trust", "mithril.withAttr", "mithril.xhr" - ] + ]; - var md2htmlTasks = {} + var md2htmlTasks = {}; var makeTasks = function(layout, pages) { pages.map(function(name) { md2htmlTasks[name] = { @@ -56,9 +56,9 @@ module.exports = function(grunt) { files: [{src: [inputFolder + "/" + name + ".md"], dest: tempFolder + "/" + name + ".html"}] } }) - } - makeTasks("guide", guide) - makeTasks("api", api) + }; + makeTasks("guide", guide); + makeTasks("api", api); var sauceBrowsers =[ { browserName: 'firefox', version: '19', platform: 'XP' }, @@ -67,7 +67,7 @@ module.exports = function(grunt) { { browserName: "iPad", platform: "OS X 10.9", version: "7.1"}, { browserName: "opera", platform: "Linux", version: "12"}, { browserName: "chrome", platform: "XP", version: "26"}, - { browserName: "chrome", platform: "Windows 8", version: "26"}, + { browserName: "chrome", platform: "Windows 8", version: "26"} ]; var sauceOnTestComplete = function(result, callback) { @@ -116,7 +116,7 @@ module.exports = function(grunt) { }; _.assign(sauceQunitOptions, sauceBaseOptions); - var currentVersionArchiveFolder = archiveFolder + "/v" + version + var currentVersionArchiveFolder = archiveFolder + "/v" + version; grunt.initConfig({ md2html: md2htmlTasks, uglify: { diff --git a/mithril.js b/mithril.js old mode 100644 new mode 100755 index 91348bb4..a4f4f97a --- a/mithril.js +++ b/mithril.js @@ -1,8 +1,8 @@ Mithril = m = new function app(window, undefined) { - var sObj = "[object Object]", sArr = "[object Array]", sStr = "[object String]", sFn = "function" - var type = {}.toString - var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/ - var voidElements = /AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR/ + var sObj = "[object Object]", sArr = "[object Array]", sStr = "[object String]", sFn = "function"; + var type = {}.toString; + var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/; + var voidElements = /AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR/; /* * @typedef {String} Tag @@ -18,25 +18,25 @@ Mithril = m = new function app(window, undefined) { * */ function m() { - var args = [].slice.call(arguments) - var hasAttrs = args[1] != null && type.call(args[1]) == sObj && !("tag" in args[1]) && !("subtree" in args[1]) - var attrs = hasAttrs ? args[1] : {} - var classAttrName = "class" in attrs ? "class" : "className" - var cell = {tag: "div", attrs: {}} - var match, classes = [] + var args = [].slice.call(arguments); + var hasAttrs = args[1] != null && type.call(args[1]) == sObj && !("tag" in args[1]) && !("subtree" in args[1]); + var attrs = hasAttrs ? args[1] : {}; + var classAttrName = "class" in attrs ? "class" : "className"; + var cell = {tag: "div", attrs: {}}; + var match, classes = []; while (match = parser.exec(args[0])) { - if (match[1] == "" && match[2]) cell.tag = match[2] - else if (match[1] == "#") cell.attrs.id = match[2] - else if (match[1] == ".") classes.push(match[2]) + if (match[1] == "" && match[2]) cell.tag = match[2]; + else if (match[1] == "#") cell.attrs.id = match[2]; + else if (match[1] == ".") classes.push(match[2]); else if (match[3][0] == "[") { - var pair = attrParser.exec(match[3]) + var pair = attrParser.exec(match[3]); cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" :true) } } - if (classes.length > 0) cell.attrs[classAttrName] = classes.join(" ") + if (classes.length > 0) cell.attrs[classAttrName] = classes.join(" "); - var children = hasAttrs ? args[2] : args[1] + var children = hasAttrs ? args[2] : args[1]; if (type.call(children) == sArr) { cell.children = children } @@ -45,7 +45,7 @@ Mithril = m = new function app(window, undefined) { } for (var attrName in attrs) { - if (attrName == classAttrName) cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName] + if (attrName == classAttrName) cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName]; else cell.attrs[attrName] = attrs[attrName] } return cell @@ -76,26 +76,26 @@ Mithril = m = new function app(window, undefined) { //there's logic that relies on the assumption that null and undefined data are equivalent to empty strings //- this prevents lifecycle surprises from procedural helpers that mix implicit and explicit return statements //- it simplifies diffing code - if (data == null) data = "" - if (data.subtree === "retain") return cached - var cachedType = type.call(cached), dataType = type.call(data) + if (data == null) data = ""; + if (data.subtree === "retain") return cached; + var cachedType = type.call(cached), dataType = type.call(data); if (cached == null || cachedType != dataType) { if (cached != null) { if (parentCache && parentCache.nodes) { - var offset = index - parentIndex - var end = offset + (dataType == sArr ? data : cached.nodes).length + var offset = index - parentIndex; + var end = offset + (dataType == sArr ? data : cached.nodes).length; clear(parentCache.nodes.slice(offset, end), parentCache.slice(offset, end)) } else if (cached.nodes) clear(cached.nodes, cached) } - cached = new data.constructor - if (cached.tag) cached = {} //if constructor creates a virtual dom element, use a blank object as the base cached node instead of copying the virtual el (#277) + cached = new data.constructor; + if (cached.tag) cached = {}; //if constructor creates a virtual dom element, use a blank object as the base cached node instead of copying the virtual el (#277) cached.nodes = [] } if (dataType == sArr) { - data = flatten(data) - var nodes = [], intact = cached.length === data.length, subArrayCount = 0 + data = flatten(data); + var nodes = [], intact = cached.length === data.length, subArrayCount = 0; //keys algorithm: sort elements without recreating them if keys are present //1) create a map of all existing keys, and mark all for deletion @@ -103,11 +103,11 @@ Mithril = m = new function app(window, undefined) { //3) if key exists in new list, change action from deletion to a move //4) for each key, handle its corresponding action as marked in previous steps //5) copy unkeyed items into their respective gaps - var DELETION = 1, INSERTION = 2 , MOVE = 3 - var existing = {}, unkeyed = [], shouldMaintainIdentities = false + var DELETION = 1, INSERTION = 2 , MOVE = 3; + var existing = {}, unkeyed = [], shouldMaintainIdentities = false; for (var i = 0; i < cached.length; i++) { if (cached[i] && cached[i].attrs && cached[i].attrs.key != null) { - shouldMaintainIdentities = true + shouldMaintainIdentities = true; existing[cached[i].attrs.key] = {action: DELETION, index: i} } } @@ -115,8 +115,8 @@ Mithril = m = new function app(window, undefined) { for (var i = 0; i < data.length; i++) { if (data[i] && data[i].attrs) { if (data[i].attrs.key != null) { - var key = data[i].attrs.key - if (!existing[key]) existing[key] = {action: INSERTION, index: i} + var key = data[i].attrs.key; + if (!existing[key]) existing[key] = {action: INSERTION, index: i}; else existing[key] = { action: MOVE, index: i, @@ -127,19 +127,19 @@ Mithril = m = new function app(window, undefined) { else unkeyed.push({index: i, element: parentElement.childNodes[i] || window.document.createElement("div")}) } } - var actions = Object.keys(existing).map(function(key) {return existing[key]}) - var changes = actions.sort(function(a, b) {return a.action - b.action || a.index - b.index}) - var newCached = cached.slice() + var actions = Object.keys(existing).map(function(key) {return existing[key]}); + var changes = actions.sort(function(a, b) {return a.action - b.action || a.index - b.index}); + var newCached = cached.slice(); for (var i = 0, change; change = changes[i]; i++) { if (change.action == DELETION) { - clear(cached[change.index].nodes, cached[change.index]) + clear(cached[change.index].nodes, cached[change.index]); newCached.splice(change.index, 1) } if (change.action == INSERTION) { - var dummy = window.document.createElement("div") - dummy.key = data[change.index].attrs.key - parentElement.insertBefore(dummy, parentElement.childNodes[change.index] || null) + var dummy = window.document.createElement("div"); + dummy.key = data[change.index].attrs.key; + parentElement.insertBefore(dummy, parentElement.childNodes[change.index] || null); newCached.splice(change.index, 0, {attrs: {key: data[change.index].attrs.key}, nodes: [dummy]}) } @@ -151,28 +151,28 @@ Mithril = m = new function app(window, undefined) { } } for (var i = 0; i < unkeyed.length; i++) { - var change = unkeyed[i] - parentElement.insertBefore(change.element, parentElement.childNodes[change.index] || null) + var change = unkeyed[i]; + parentElement.insertBefore(change.element, parentElement.childNodes[change.index] || null); newCached[change.index] = cached[change.index] } - cached = newCached - cached.nodes = [] + cached = newCached; + cached.nodes = []; for (var i = 0, child; child = parentElement.childNodes[i]; i++) cached.nodes.push(child) } //end key algorithm for (var i = 0, cacheCount = 0; i < data.length; i++) { //diff each item in the array - var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs) - if (item === undefined) continue - if (!item.nodes.intact) intact = false + var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs); + if (item === undefined) continue; + if (!item.nodes.intact) intact = false; if (item.$trusted) { //fix offset of next element if item was a trusted string w/ more than one html element //the first clause in the regexp matches elements //the second clause (after the pipe) matches text nodes subArrayCount += (item.match(/<[^\/]|\>\s*[^<]/g) || []).length } - else subArrayCount += type.call(item) == sArr ? item.length : 1 + else subArrayCount += type.call(item) == sArr ? item.length : 1; cached[cacheCount++] = item } if (!intact) { @@ -191,28 +191,28 @@ Mithril = m = new function app(window, undefined) { for (var i = cached.nodes.length, node; node = nodes[i]; i++) { if (node.parentNode == null) parentElement.appendChild(node) } - if (data.length < cached.length) cached.length = data.length + if (data.length < cached.length) cached.length = data.length; cached.nodes = nodes } } else if (data != null && dataType == sObj) { - if (!data.attrs) data.attrs = {} - if (!cached.attrs) cached.attrs = {} + if (!data.attrs) data.attrs = {}; + if (!cached.attrs) cached.attrs = {}; - var dataAttrKeys = Object.keys(data.attrs) + var dataAttrKeys = Object.keys(data.attrs); //if an element is different enough from the one in cache, recreate it if (data.tag != cached.tag || dataAttrKeys.join() != Object.keys(cached.attrs).join() || data.attrs.id != cached.attrs.id) { - if (cached.nodes.length) clear(cached.nodes) + if (cached.nodes.length) clear(cached.nodes); if (cached.configContext && typeof cached.configContext.onunload == sFn) cached.configContext.onunload() } - if (type.call(data.tag) != sStr) return + if (type.call(data.tag) != sStr) return; - var node, isNew = cached.nodes.length === 0 - if (data.attrs.xmlns) namespace = data.attrs.xmlns - else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg" - else if (data.tag === "math") namespace = "http://www.w3.org/1998/Math/MathML" + var node, isNew = cached.nodes.length === 0; + if (data.attrs.xmlns) namespace = data.attrs.xmlns; + else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg"; + else if (data.tag === "math") namespace = "http://www.w3.org/1998/Math/MathML"; if (isNew) { - node = namespace === undefined ? window.document.createElement(data.tag) : window.document.createElementNS(namespace, data.tag) + node = namespace === undefined ? window.document.createElement(data.tag) : window.document.createElementNS(namespace, data.tag); cached = { tag: data.tag, //set attributes first, then create children @@ -221,69 +221,69 @@ Mithril = m = new function app(window, undefined) { build(node, data.tag, undefined, undefined, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace, configs) : data.children, nodes: [node] - } - if (cached.children && !cached.children.nodes) cached.children.nodes = [] + }; + if (cached.children && !cached.children.nodes) cached.children.nodes = []; //edge case: setting value on