diff --git a/js/aceBindings.js b/js/aceBindings.js index ae54048..7ba235e 100644 --- a/js/aceBindings.js +++ b/js/aceBindings.js @@ -1,4 +1,9 @@ -define(["command", "editor", "statusbar", "settings!user"], function(command, editor, status, Settings) { +define([ + "command", + "editor", + "ui/statusbar", + "settings!user" + ], function(command, editor, status, Settings) { var userConfig = Settings.get("user"); command.on("init:restart", function() { diff --git a/js/api.js b/js/api.js index 00def09..bb31ef5 100644 --- a/js/api.js +++ b/js/api.js @@ -1,4 +1,8 @@ -define(["command", "settings!api"], function(command, Settings) { +define([ + "command", + "settings!api" + ], function(command, Settings) { + //handles sending custom messages based on Caret commands (builds, plugins, etc) var targets = Settings.get("api"); command.on("init:restart", function() { diff --git a/js/command.js b/js/command.js index 0f5c6ac..df68f2d 100644 --- a/js/command.js +++ b/js/command.js @@ -1,4 +1,6 @@ -define(["dom2"], function() { +define([ + "util/dom2" + ], function() { /* diff --git a/js/editor.js b/js/editor.js index 9bed4d7..47e00b3 100644 --- a/js/editor.js +++ b/js/editor.js @@ -1,4 +1,9 @@ -define(["file", "command", "settings!ace,user", "dom2"], function(File, command, Settings) { +define([ + "storage/file", + "command", + "settings!ace,user", + "util/dom2" + ], function(File, command, Settings) { /* Module for loading the editor, adding window resizing and other events. Returns the editor straight from Ace. */ diff --git a/js/fileManager.js b/js/fileManager.js index 20ed44d..d2dac95 100644 --- a/js/fileManager.js +++ b/js/fileManager.js @@ -1,10 +1,10 @@ define([ "sessions", - "file", - "dialog", + "storage/file", + "ui/dialog", "command", "settings!", //not excited, it just runs as a RequireJS plugin, - "manos" + "util/manos" ], function(sessions, File, dialog, command, Settings, M) { var openFile = function() { diff --git a/js/main.js b/js/main.js index 6b487a8..9893485 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,13 @@ require([ - "command", - "settings!user", - "dialog", - "projectManager", - "keys", - "fileManager", - "menus", - "palette", - "api" + "command", + "settings!user", + "ui/dialog", + "ui/projectManager", + "ui/keys", + "fileManager", + "ui/menus", + "ui/palette", + "api" ], function(command, Settings, dialog) { var frame = chrome.app.window.current(); diff --git a/js/sessions.js b/js/sessions.js index e776b08..7c9994e 100644 --- a/js/sessions.js +++ b/js/sessions.js @@ -1,11 +1,11 @@ define([ "editor", - "dialog", + "ui/dialog", "command", - "file", + "storage/file", "tab", "settings!ace,user", - "statusbar", + "ui/statusbar", "aceBindings" ], function(editor, dialog, command, File, Tab, Settings, status) { diff --git a/js/settings.js b/js/settings.js index 27cf3cc..3a803b7 100644 --- a/js/settings.js +++ b/js/settings.js @@ -1,4 +1,6 @@ -define(["command"], function(command) { +define([ + "command" + ], function(command) { var defaults = {}; var local = {}; diff --git a/js/file.js b/js/storage/file.js similarity index 98% rename from js/file.js rename to js/storage/file.js index 555bd32..2eb6e8c 100644 --- a/js/file.js +++ b/js/storage/file.js @@ -1,4 +1,6 @@ -define(["manos"], function(M) { +define([ + "util/manos" + ], function(M) { /* diff --git a/js/tab.js b/js/tab.js index 704f048..306086c 100644 --- a/js/tab.js +++ b/js/tab.js @@ -1,4 +1,7 @@ -define(["command", "file"], function(command, File) { +define([ + "command", + "storage/file" + ], function(command, File) { var EditSession = ace.require("ace/edit_session").EditSession; diff --git a/js/contextMenus.js b/js/ui/contextMenus.js similarity index 87% rename from js/contextMenus.js rename to js/ui/contextMenus.js index 2deaad2..cdaae9a 100644 --- a/js/contextMenus.js +++ b/js/ui/contextMenus.js @@ -20,11 +20,12 @@ define(function() { var createRoute = function(route, handler) { var parts = route.split("/"); - var positions = {}; - parts = parts.map(function(s, i) { + var positionMap = {}; + var position = 1; + parts = parts.map(function(s) { if (s[0] == ":") { //set the key to be used on parsing - positions[i] = s.replace(/^:/, ""); + positionMap[position++] = s.replace(/^:/, ""); return "*"; } return s.replace(/[\^()\[\]]/, function(match) { return "\\" + match }); @@ -34,8 +35,8 @@ define(function() { var result = re.exec(url); if (!result) return result; var params = {}; - for (var place in positions) { - var key = positions[place]; + for (var place in positionMap) { + var key = positionMap[place]; params[key] = result[place]; } params.url = url; diff --git a/js/dialog.js b/js/ui/dialog.js similarity index 97% rename from js/dialog.js rename to js/ui/dialog.js index b780a14..6f8cc6f 100644 --- a/js/dialog.js +++ b/js/ui/dialog.js @@ -1,4 +1,7 @@ -define(["editor", "dom2"], function(editor) { +define([ + "editor", + "util/dom2" + ], function(editor) { return function(text, buttons, callback) { if (typeof buttons == "function" || typeof buttons == "undefined") { diff --git a/js/keys.js b/js/ui/keys.js similarity index 93% rename from js/keys.js rename to js/ui/keys.js index fab89a7..fe27119 100644 --- a/js/keys.js +++ b/js/ui/keys.js @@ -1,4 +1,9 @@ -define(["settings!keys", "command", "editor", "dom2"], function(Settings, command, editor) { +define([ + "settings!keys", + "command", + "editor", + "util/dom2" + ], function(Settings, command, editor) { /* Still need to set Sublime keybindings diff --git a/js/menus.js b/js/ui/menus.js similarity index 98% rename from js/menus.js rename to js/ui/menus.js index 891c16a..80ba027 100644 --- a/js/menus.js +++ b/js/ui/menus.js @@ -1,9 +1,9 @@ define([ - "settings!menus,keys", - "editor", - "dialog", - "command", - "dom2" + "settings!menus,keys", + "editor", + "ui/dialog", + "command", + "util/dom2" ], function(Settings, editor, dialog, command) { var commands = editor.commands.commands; diff --git a/js/palette.js b/js/ui/palette.js similarity index 98% rename from js/palette.js rename to js/ui/palette.js index d3ad9bc..243d420 100644 --- a/js/palette.js +++ b/js/ui/palette.js @@ -1,10 +1,10 @@ define([ - "sessions", - "command", - "editor", - "settings!menus,user", - "statusbar", - "dom2" + "sessions", + "command", + "editor", + "settings!menus,user", + "ui/statusbar", + "util/dom2" ], function(sessions, command, editor, Settings, status) { var TokenIterator = ace.require("ace/token_iterator").TokenIterator; diff --git a/js/projectManager.js b/js/ui/projectManager.js similarity index 98% rename from js/projectManager.js rename to js/ui/projectManager.js index aaffac9..a714cd8 100644 --- a/js/projectManager.js +++ b/js/ui/projectManager.js @@ -1,13 +1,13 @@ define([ - "settings!", - "command", - "sessions", - "file", - "manos", - "dialog", - "contextMenus", - "editor", - "dom2" + "settings!", + "command", + "sessions", + "storage/file", + "util/manos", + "ui/dialog", + "ui/contextMenus", + "editor", + "util/dom2" ], function(Settings, command, sessions, File, M, dialog, context, editor) { /* diff --git a/js/statusbar.js b/js/ui/statusbar.js similarity index 96% rename from js/statusbar.js rename to js/ui/statusbar.js index 29f71cb..8b59708 100644 --- a/js/statusbar.js +++ b/js/ui/statusbar.js @@ -1,4 +1,6 @@ -define(["editor"], function(editor) { +define([ + "editor" + ], function(editor) { var external = ""; var element = document.find(".status-text"); diff --git a/js/dom2.js b/js/util/dom2.js similarity index 95% rename from js/dom2.js rename to js/util/dom2.js index 9198225..efdd78e 100644 --- a/js/dom2.js +++ b/js/util/dom2.js @@ -1,95 +1,95 @@ -(function() { -"use strict"; - -/* - -Yes, you're not supposed to extend native prototypes. But in ChromeOS, who cares? Nobody's sharing your context. Why not paper over the cracks in the DOM? This library extends elements to do the following: - -- create a query() method that returns an array, instead of a nodeList -- create remove() and append() that work the way you expect them to. -- alias event listener methods to the much shorter on() and off() -- add a style method that handles prefixed CSS - -*/ - -var el = Element.prototype; -var doc = Document.prototype; -var frag = DocumentFragment.prototype; -var win = Window.prototype; - -el.find = doc.find = frag.find = function(selector) { - return this.querySelector(selector); -}; - -el.findAll = doc.findAll = frag.findAll = function(selector) { - var a = []; - a.push.apply(a, this.querySelectorAll(selector)); - return a; -}; - -el.matches = el.matches || el.webkitMatchesSelector; - -el.remove = function() { - this.parentElement.removeChild(this); -}; - -el.append = frag.append = function(element) { - if (typeof element == "string") { - this.innerHTML += element; - } else { - this.appendChild(element); - } -}; - -win.on = el.on = function(type, listener) { - this.addEventListener(type, listener); - return this; -}; - -win.off = el.off = function(type, listener) { - this.removeEventListener(type, listener); -}; - -el.css = function(style, one) { - if (typeof style === "string") { - var hash = {}; - hash[style] = one; - style = hash; - } - for (var key in style) { - var val = style[key]; - if (key.indexOf("-") > 0) { - key.replace(/-(\w)/g, function(_, match) { - return match.toUpperCase(); - }); - } - if (!(key in this.style)) { - ["webkit", "moz", "ms"].some(function(prefix) { - var test = prefix + key[0].toUpperCase() + key.substr(1); - if (test in this.style) { - key = test; - return true; - } - }, this); - } - this.style[key] = val; - } -}; - -el.addClass = function(name) { - this.classList.add(name); -}; - -el.removeClass = function(name) { - this.classList.remove(name); -}; - -el.toggle = function(name) { - this.classList.toggle(name); -}; - -el.hasClass = function(name) { - return this.classList.contains(name); -} - -})(); \ No newline at end of file +define(function() { +"use strict"; + +/* + +Yes, you're not supposed to extend native prototypes. But in ChromeOS, who cares? Nobody's sharing your context. Why not paper over the cracks in the DOM? This library extends elements to do the following: + +- create a query() method that returns an array, instead of a nodeList +- create remove() and append() that work the way you expect them to. +- alias event listener methods to the much shorter on() and off() +- add a style method that handles prefixed CSS + +*/ + +var el = Element.prototype; +var doc = Document.prototype; +var frag = DocumentFragment.prototype; +var win = Window.prototype; + +el.find = doc.find = frag.find = function(selector) { + return this.querySelector(selector); +}; + +el.findAll = doc.findAll = frag.findAll = function(selector) { + var a = []; + a.push.apply(a, this.querySelectorAll(selector)); + return a; +}; + +el.matches = el.matches || el.webkitMatchesSelector; + +el.remove = function() { + this.parentElement.removeChild(this); +}; + +el.append = frag.append = function(element) { + if (typeof element == "string") { + this.innerHTML += element; + } else { + this.appendChild(element); + } +}; + +win.on = el.on = function(type, listener) { + this.addEventListener(type, listener); + return this; +}; + +win.off = el.off = function(type, listener) { + this.removeEventListener(type, listener); +}; + +el.css = function(style, one) { + if (typeof style === "string") { + var hash = {}; + hash[style] = one; + style = hash; + } + for (var key in style) { + var val = style[key]; + if (key.indexOf("-") > 0) { + key.replace(/-(\w)/g, function(_, match) { + return match.toUpperCase(); + }); + } + if (!(key in this.style)) { + ["webkit", "moz", "ms"].some(function(prefix) { + var test = prefix + key[0].toUpperCase() + key.substr(1); + if (test in this.style) { + key = test; + return true; + } + }, this); + } + this.style[key] = val; + } +}; + +el.addClass = function(name) { + this.classList.add(name); +}; + +el.removeClass = function(name) { + this.classList.remove(name); +}; + +el.toggle = function(name) { + this.classList.toggle(name); +}; + +el.hasClass = function(name) { + return this.classList.contains(name); +} + +}) \ No newline at end of file diff --git a/js/manos.js b/js/util/manos.js similarity index 100% rename from js/manos.js rename to js/util/manos.js