فهرست منبع

Update terminal tag to instantiate a new shell

This way, each terminal tag has its own shell object to track its own
state.
Weiyi Lou 10 سال پیش
والد
کامیت
bc84bc8f04
2فایلهای تغییر یافته به همراه9 افزوده شده و 10 حذف شده
  1. 0 1
      js/pgsh.js
  2. 9 9
      tags/terminal.tag

+ 0 - 1
js/pgsh.js

@@ -105,4 +105,3 @@ function pgsh() {
     return output
   }
 }
-var pgsh = new pgsh()

+ 9 - 9
tags/terminal.tag

@@ -2,7 +2,8 @@
  * # Terminal Riot Tag
  *
  * Provides a pretend commandline interface, capable of displaying output from a
- * "Shell" javascript object.
+ * "Shell" javascript class. Multiple terminal tags can be used on a page,
+ * acting independently of one another.
  *
  * ## Defaults
  *
@@ -11,7 +12,7 @@
  *
  * ## Usage
  *
- *     <terminal shell='jsobject' welcome='text' prompt='text'></terminal>
+ *     <terminal shell='jsclass' welcome='text' prompt='text'></terminal>
  *
  *     <script src='riot+compiler.min.js'></script>
  *     <script src='he.js'></script>
@@ -24,23 +25,22 @@
  * - riot.js (http://riotjs.com/)
  * - he.js (https://github.com/mathiasbynens/he) for HTML Entity conversion.
  *
- * ## Making a Shell javascript object
+ * ## Making a Shell javascript class
  *
- * Shell objects must be defined before the tag is mounted. Shells can keep
+ * Shell class must be defined before the tag is mounted. Shells can keep
  * prompt character and welcome message settings, and must define a `process()`
  * function. Here is the structure of a minimumal shell that does nothing:
  *
- *     // Contents of shell.js
- *     function() shell() {
+ *     // Contents of myshell.js
+ *     function() myshell() {
  *        this.prompt = ''
  *        this.welcome = ''
  *        this.process = function(input) {
  *          return ''
  *        }
  *     }
- *     var myshell = new shell()
  *
- *     // Shell object used by Terminal Riot Tag
+ *     // Shell class used by Terminal Riot Tag in index.html
  *     <terminal shell='myshell'></terminal>
  *
  * ## Special Return Values
@@ -57,7 +57,7 @@
 
   // Take defaults from shell, otherwise take from `<terminal>` options.
   var shell = { 'process': function() { return ''; } }
-  this.shell = window[opts.shell] ? window[opts.shell] : shell
+  this.shell = window[opts.shell] ? new window[opts.shell] : shell
   this.welcome = this.shell.welcome ? this.shell.welcome : opts.welcome
   this.prompt = this.shell.prompt ? this.shell.prompt : opts.prompt