You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2009/03/19 12:24:20 UTC

svn commit: r755931 [9/9] - in /camel/trunk/components/camel-web/src/main/webapp/js/bespin: ./ client/ cmd/ editor/ mobwrite/ page/ page/dashboard/ page/editor/ page/index/ syntax/ user/ util/

Added: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/path.js
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/path.js?rev=755931&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/path.js (added)
+++ camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/path.js Thu Mar 19 11:24:18 2009
@@ -0,0 +1,94 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
+ * See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The Original Code is Bespin.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Bespin Team (bespin@mozilla.com)
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+dojo.provide("bespin.util.path");
+
+// = Path =
+//
+// Deal with paths that are sent into Bespin
+
+dojo.mixin(bespin.util.path, {
+    // ** {{{ bespin.util.path.combine }}} **
+    //
+    // Take the given arguments and combine them with one path seperator
+    //
+    // * combine("foo", "bar") -> foo/bar
+    // * combine(" foo/", "/bar  ") -> foo/bar
+    combine: function() {
+        var args = Array.prototype.slice.call(arguments); // clone to a true array
+
+        var path = args.join('/');
+        path = path.replace(/\/\/+/g, '/');
+        path = path.replace(/^\s+|\s+$/g, '');
+        return path;
+    },
+
+    // ** {{{ bespin.util.path.directory }}} **
+    //
+    // Given a {{{path}}} return the directory
+    //
+    // * directory("/path/to/directory/file.txt") -> /path/to/directory/
+    // * directory("/path/to/directory/") -> /path/to/directory/
+    // * directory("foo.txt") -> ""
+    directory: function(path) {
+        var dirs = path.split('/');
+        if (dirs.length == 1) { // no directory so return blank
+            return "";
+        } else if ((dirs.length == 2) && dirs[dirs.length -1] == "") { // a complete directory so return it
+            return path;
+        } else {
+            return dirs.slice(0, dirs.length - 1).join('/');
+        }
+    },
+
+    // ** {{{ bespin.util.path.makeDirectory }}} **
+    //
+    // Given a {{{path}}} make sure that it returns as a directory 
+    // (As in, ends with a '/')
+    //
+    // * makeDirectory("/path/to/directory") -> /path/to/directory/
+    // * makeDirectory("/path/to/directory/") -> /path/to/directory/
+    makeDirectory: function(path) {
+        if (!/\/$/.test(path)) path += '/';
+        return path;
+    },
+
+    // ** {{{ bespin.util.path.combineAsDirectory }}} **
+    //
+    // Take the given arguments and combine them with one path seperator and
+    // then make sure that you end up with a directory
+    //
+    // * combine("foo", "bar") -> foo/bar/
+    // * combine(" foo/", "/bar  ") -> foo/bar/
+    combineAsDirectory: function() {
+        return this.makeDirectory(this.combine.apply(this, arguments));
+    },
+
+    // ** {{{ bespin.util.path.escape }}} **
+    //
+    // This function doubles down and calls {{{combine}}} and then escapes the output
+    escape: function() {
+        return escape(this.combine.apply(this, arguments));
+    }
+});
\ No newline at end of file

Propchange: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/path.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/tokenobject.js
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/tokenobject.js?rev=755931&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/tokenobject.js (added)
+++ camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/tokenobject.js Thu Mar 19 11:24:18 2009
@@ -0,0 +1,98 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
+ * See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The Original Code is Bespin.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Bespin Team (bespin@mozilla.com)
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+// = bespin.util.TokenObject =
+//
+// Given a string, make a token object that holds positions and has name access
+//
+// Examples,
+//
+// * args = new bespin.util.TokenObject(userString, { params: command.takes.order.join(' ') });
+//
+// * var test = new bespin.util.TokenObject(document.getElementById("input").value, { 
+//	     splitBy: document.getElementById("regex").value,
+//	     params: document.getElementById("params").value
+// });
+//
+// * var test = new bespin.util.TokenObject("male 'Dion Almaer'", {
+//    params: 'gender name'
+// })
+
+dojo.provide("bespin.util.tokenobject");
+
+dojo.declare("bespin.util.TokenObject", null, { 
+    constructor: function(input, options) {
+        this._input = input;
+        this._options = options;
+        this._splitterRegex = new RegExp(this._options.splitBy || '\\s+');
+        this._pieces = this.tokenize(input.split(this._splitterRegex));
+
+        if (this._options.params) { // -- create a hash for name based access
+            this._nametoindex = {};
+            var namedparams = this._options.params.split(' ');
+            for (var x = 0; x < namedparams.length; x++) {
+                this._nametoindex[namedparams[x]] = x;
+
+                if (!this._options['noshortcutvalues']) { // side step if you really don't want this
+                    this[namedparams[x]] = this._pieces[x];
+                }
+            }
+
+        }
+    },
+    
+    // Split up the input taking into account ' and "
+    tokenize: function(incoming) {
+        var tokens = [];
+        
+        var nextToken;
+        while (nextToken = incoming.shift()) {
+            if (nextToken[0] == '"' || nextToken[0] == "'") { // it's quoting time
+                var eaten = [ nextToken.substring(1, nextToken.length) ];
+                var eataway;
+                while (eataway = incoming.shift()) {
+                    if (eataway[eataway.length - 1] == '"' || eataway[eataway.length - 1] == "'") { // end quoting time
+                        eaten.push(eataway.substring(0, eataway.length - 1));
+                        break;
+                    } else {
+                        eaten.push(eataway);
+                    }
+                }
+                tokens.push(eaten.join(' '));
+            } else {
+                tokens.push(nextToken);
+            }
+        }
+        
+        return tokens;
+    },
+    
+    param: function(index) {
+        return (typeof index == "number") ? this._pieces[index] : this._pieces[this._nametoindex[index]];
+    },
+
+    length: function() {
+        return this._pieces.length;
+    }
+});
\ No newline at end of file

Propchange: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/tokenobject.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/urlbar.js
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/urlbar.js?rev=755931&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/urlbar.js (added)
+++ camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/urlbar.js Thu Mar 19 11:24:18 2009
@@ -0,0 +1,46 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
+ * See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The Original Code is Bespin.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Bespin Team (bespin@mozilla.com)
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+dojo.provide("bespin.util.urlbar");
+
+// = URLBar =
+//
+// URLBar watches the browser URL navigation bar for changes.
+// If it sees a change it tries to open the file
+// The common case is using the back/forward buttons
+dojo.mixin(bespin.util.urlbar, {
+    last: document.location.hash,
+    check: function() {
+        var hash = document.location.hash;
+        if (this.last != hash) {
+            var urlchange = new bespin.client.settings.URL(hash);
+            bespin.publish("bespin:url:changed", { was: this.last, now: urlchange });
+            this.last = hash;
+        }
+    }
+});
+
+setInterval(function() {
+    dojo.hitch(bespin.util.urlbar, "check")();
+}, 200);

Propchange: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/urlbar.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/util.js
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/util.js?rev=755931&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/util.js (added)
+++ camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/util.js Thu Mar 19 11:24:18 2009
@@ -0,0 +1,141 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
+ * See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The Original Code is Bespin.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Bespin Team (bespin@mozilla.com)
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+dojo.provide("bespin.util.util");
+
+// === Helpful Utilities ===
+//
+// We gotta keep some of the Prototype spirit around :)
+
+// = queryToObject =
+//
+// While dojo.queryToObject() is mainly for URL query strings,
+// this version allows to specify a seperator character
+
+bespin.util.queryToObject = function(str, seperator) {
+    var ret = {};
+    var qp = str.split(seperator);
+    var dec = decodeURIComponent;
+    dojo.forEach(qp, function(item) {
+    	if (item.length){
+    		var parts = item.split("=");
+    		var name = dec(parts.shift());
+    		var val = dec(parts.join("="));
+    		if (dojo.isString(ret[name])){
+    			ret[name] = [ret[name]];
+    		}
+    		if (dojo.isArray(ret[name])){
+    			ret[name].push(val);
+    		} else {
+    			ret[name] = val;
+    		}
+    	}
+    });
+    return ret;
+}
+
+// = endsWith =
+//
+// A la Prototype endsWith(). Takes a regex exclusing the '$' end marker
+bespin.util.endsWith = function(str, end) {
+    return str.match(new RegExp(end + "$"));
+}
+
+// = include =
+//
+// A la Prototype include().
+bespin.util.include = function(array, item) {
+    return dojo.indexOf(array, item) > -1;
+}
+
+// = last =
+//
+// A la Prototype last().
+bespin.util.last = function(array) {
+    if (dojo.isArray(array)) return array[array.length - 1];
+}
+
+// = shrinkArray =
+//
+// Knock off any undefined items from the end of an array
+bespin.util.shrinkArray = function(array) {
+    var newArray = [];
+    
+    var stillAtBeginning = true;
+    dojo.forEach(array.reverse(), function(item) {
+        if (stillAtBeginning && item === undefined) {
+            return;
+        }
+
+        stillAtBeginning = false;
+
+        newArray.push(item);
+    });
+
+    return newArray.reverse();
+};
+
+// = makeArray =
+//
+// {{number}} - The size of the new array to create
+// {{character}} - The item to put in the array, defaults to ' '
+bespin.util.makeArray = function(number, character) {
+    if (number < 1) return []; // give us a normal number please!
+    if (!character) character = ' ';
+
+    var newArray = [];
+    for (var i = 0; i < number; i++) {
+        newArray.push(character);
+    }
+    return newArray;
+};
+
+// = leadingSpaces =
+//
+// Given a row, find the number of leading spaces.
+// E.g. an array with the string "  aposjd" would return 2
+//
+// {{row}} - The row to hunt through
+bespin.util.leadingSpaces = function(row) {
+    var numspaces = 0;
+    for (var i = 0; i < row.length; i++) {
+        if (row[i] == ' ' || row[i] == '' || row[i] === undefined) {
+            numspaces++;
+        } else {
+            return numspaces;
+        }
+    }
+    return numspaces;
+};
+
+// = isMac =
+//
+// I hate doing this, but we need some way to determine if the user is on a Mac
+// The reason is that users have different expectations of their key combinations.
+//
+// Take copy as an example, Mac people expect to use CMD or APPLE + C
+// Windows folks expect to use CTRL + C
+bespin.util.isMac = function() {
+    return navigator.appVersion.indexOf("Macintosh") >= 0;
+}

Propchange: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/util.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/webpieces.js
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/webpieces.js?rev=755931&view=auto
==============================================================================
--- camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/webpieces.js (added)
+++ camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/webpieces.js Thu Mar 19 11:24:18 2009
@@ -0,0 +1,83 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
+ * See the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The Original Code is Bespin.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Bespin Team (bespin@mozilla.com)
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+dojo.provide("bespin.util.webpieces");
+
+// = Utility functions for Web snippets =
+//
+// There are little widgets and components that we want to reuse
+
+dojo.mixin(bespin.util.webpieces, {
+    // -- Center Popup
+    showCenterPopup: function(el) {
+        this.showOverlay();
+        dojo.style(el, 'display', 'block');
+
+        // retrieve required dimensions
+        var elDims = dojo.coords(el);
+        var browserDims = dijit.getViewport();
+        
+        // calculate the center of the page using the browser and element dimensions
+        var y = (browserDims.h - elDims.h) / 2;
+        var x = (browserDims.w - elDims.w) / 2;
+
+        // set the style of the element so it is centered
+        dojo.style(el, {
+            position: 'absolute',
+            top: y + 'px',
+            left: x + 'px'
+        });
+    },
+
+    hideCenterPopup: function(el) {
+        dojo.style(el, 'display', 'none');
+        this.hideOverlay();
+    },
+
+    // -- Overlay
+    
+    showOverlay: function() {
+        dojo.style('overlay', 'display', 'block');
+    },
+
+    hideOverlay: function() {
+        dojo.style('overlay', 'display', 'none');
+    },
+
+    // take the overlay and make sure it stretches on the entire height of the screen
+    fillScreenOverlay: function() {
+	    var coords = dojo.coords(document.body);
+	    
+	    if (coords.h) {
+            dojo.style(dojo.byId('overlay'), 'height', coords.h + "px");
+        }
+    },
+
+    // -- Status
+    showStatus: function(msg) {
+        dojo.byId("status").innerHTML = msg;
+        dojo.style('status', 'display', 'block');
+    }
+
+});

Propchange: camel/trunk/components/camel-web/src/main/webapp/js/bespin/util/webpieces.js
------------------------------------------------------------------------------
    svn:eol-style = native