Permalink
Browse files

Added functionality for quoted flag values. Added include() to includ…

…e modules and files in modules. Fixed IE7 bug.
  • Loading branch information...
1 parent 8d9011a commit 79fbd0da807926085ef973d141991f348e796c9e @twisterghost committed Dec 27, 2011
Showing with 49 additions and 8 deletions.
  1. +11 −2 README.markdown
  2. +3 −1 index.html
  3. +35 −5 intercom.js
View
@@ -15,8 +15,12 @@ easy extension using a module system.
##1. Installation
Installing a setup of intercom is as simple as dropping the project files into
your folder of choice.
-To add a module to your installation, add a javascript include line under the
-specified comment in index.html:
+To add a module to your installation, use the `include()` function.
+
+`include("filename.js")`
+
+Or use an html script src directly:
+
<script type='text/javascript' src='module_name.js'></script>
##2. Creating Modules
@@ -203,3 +207,8 @@ Returns true if the input command matches the given command.
`extractArguments(input)`
Returns an array of arguments from the given input.
+
+
+`include(filepath)`
+
+Loads the given js file into the DOM
View
@@ -12,7 +12,9 @@
<script type='text/javascript' src='intercom.js'></script>
<!-- Plugins -->
- <script type='text/javascript' src='demo.js'></script>
+ <script>
+ include("demo.js");
+ </script>
</head>
<body>
View
@@ -1,5 +1,5 @@
// Define constants
-var VERSION = "1.0.1.3";
+var VERSION = "1.0.1.4";
// Define variables
var inputStream = parseInput;
@@ -26,11 +26,10 @@ $(document).ready(function(){
/**
* Runs upon every time a key is pressed in #input.
* Listening for enter key upon which it then runs the current parser
- * @param e
*/
function checkKey(e){
if (e.keyCode == 13){
- input = $('#input').val();
+ var input = $('#input').val();
$('#input').val('');
if (input == "forcequit") {
outputWithCarrot(input);
@@ -63,7 +62,6 @@ function checkKey(e){
/**
* Attempts to parse input for main functionality.
- * @param input
*/
function parseInput(input){
output("&raquo;&nbsp;" + input);
@@ -273,15 +271,38 @@ function extractFlags(input) {
input = input.substring(input.indexOf("-") + 1);
// Is there an = sign?
+ isQuotedValue = input.indexOf('="');
+ isSingleQuotedValue = input.indexOf("='");
nextEquals = input.indexOf("=");
nextSpace = input.indexOf(" ");
+
if (nextSpace == -1) {
nextSpace = input.length;
}
- if (nextEquals != -1 && nextEquals < nextSpace) {
+ // If there is the =" pair and it is followed by a "
+ if (isQuotedValue != -1 &&
+ isQuotedValue < input.substring(isQuotedValue+2).indexOf('"')) {
+
+ // Its a value pair
+ key = input.substring(0, isQuotedValue);
+ value = input.substring(isQuotedValue+2, (isQuotedValue+2) +
+ input.substring(isQuotedValue+2).indexOf('"'));
+ flags_array[key] = value;
+
+ } else if (isSingleQuotedValue != -1 &&
+ isSingleQuotedValue <
+ input.substring(isSingleQuotedValue+2).indexOf("'")) {
+ // Its a value pair
+ key = input.substring(0, isSingleQuotedValue);
+ value = input.substring(isSingleQuotedValue+2, (isSingleQuotedValue+2) +
+ input.substring(isSingleQuotedValue+2).indexOf("'"));
+ flags_array[key] = value;
+
+ } else if (nextEquals != -1 && nextEquals < nextSpace) {
// Its a value pair
+
key = input.substring(0, nextEquals);
value = input.substring(nextEquals+1, nextSpace);
flags_array[key] = value;
@@ -350,3 +371,12 @@ function extractArguments(input) {
}
return returnArr;
}
+
+
+/**
+ * Includes the given filepath by writing the html
+ */
+function include(filepath) {
+ document.write("<script type='text/javascript' src='" + filepath + "'>" +
+ "</script>");
+}

0 comments on commit 79fbd0d

Please sign in to comment.