diff options
author | Trent Richardson <trentdrichardson@gmail.com> | 2014-12-10 11:07:38 -0500 |
---|---|---|
committer | Trent Richardson <trentdrichardson@gmail.com> | 2014-12-10 11:07:38 -0500 |
commit | 3002c704116baab9c89c8ff0d1de10961729bcb1 (patch) | |
tree | 44f4b72fefed52c67b1fd082179e0b2091897654 /src | |
parent | 5b16726790f61d5ea5325729825439a782c9dfa6 (diff) | |
download | jQuery-Impromptu-3002c704116baab9c89c8ff0d1de10961729bcb1.zip jQuery-Impromptu-3002c704116baab9c89c8ff0d1de10961729bcb1.tar.gz jQuery-Impromptu-3002c704116baab9c89c8ff0d1de10961729bcb1.tar.bz2 |
Converts $.prompt to a stack to manage Impromptu instances
Diffstat (limited to 'src')
-rw-r--r-- | src/index.html | 37 | ||||
-rw-r--r-- | src/jquery-impromptu.js | 69 |
2 files changed, 88 insertions, 18 deletions
diff --git a/src/index.html b/src/index.html index 6444650..445924b 100644 --- a/src/index.html +++ b/src/index.html @@ -128,7 +128,20 @@ <!-- ---------------------------------------------- --> <div id="Options" class="section"> <h2>Options</h2> - <pre><code>$.prompt.open( msg , options )</code></pre> + + <h3>Usage</h3> + <pre><code>var jqPromptEl = $.prompt( msg , options ); + +// OR + +var api = new Impromptu( msg , options );</code></pre> + + <p>Impromptu can be called through $.prompt() or by creating a new instance of the Impromptu object. Whats the difference?</p> + <p>An Impromptu instance is a single prompt. The constructor returns it's api so you can manipulate it.</p> + <p>$.prompt is an object that manages a stack of Impromptu instances. What does this mean? You can continuously call $.prompt without closing the previous prompt, and $.prompt will always manage the newest prompt on the stack by acting as a proxy to the latest Impromptu instance. $.prompt() will return a jQuery object of the latests prompt.</p> + + <p>Since $.prompt acts as a simple proxy to Impromptu, they accept the same options.</p> + <h3>msg</h3> <p>The message can either be an html string, or an object of "states". Each state has the following properties:</p> <dl> @@ -247,19 +260,19 @@ <div id="Methods" class="section"> <h2>Methods</h2> <dl class="methoddl"> - <dt>Impromptu.setDefaults(options)</dt> + <dt>$.prompt.setDefaults(options)</dt> <dd> Sets the defaults for prompts.<br /> -<pre><code>Impromptu.setDefaults({ +<pre><code>$.prompt.setDefaults({ prefix: 'myPrompt', show: 'slideDown' });</pre></code> </dd> - <dt>Impromptu.setStateDefaults(options)</dt> + <dt>$.prompt.setStateDefaults(options)</dt> <dd> Sets the defaults for states.<br /> -<pre><code>Impromptu.setStateDefaults({ +<pre><code>$.prompt.setStateDefaults({ buttons: { Ok:true, Cancel:false }, focus: 1 });</pre></code> @@ -338,7 +351,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>A prompt in the simplest of fashion.</p> -<pre class="code">$.prompt.open("Hello World!");</pre> +<pre class="code">$.prompt("Hello World!");</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -346,7 +359,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>Lets add some buttons and a title.</p> -<pre class="code">$.prompt.open("Proceeding may be good for your site..", { +<pre class="code">$.prompt("Proceeding may be good for your site..", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false } });</pre> @@ -357,7 +370,7 @@ $.prompt.getState('state2') <div class="example-container"> <p>Use the submit function to get the answer.</p> -<pre class="code">$.prompt.open("Open your javascript console to see the answer.", { +<pre class="code">$.prompt("Open your javascript console to see the answer.", { title: "Are you Ready?", buttons: { "Yes, I'm Ready": true, "No, Lets Wait": false }, submit: function(e,v,m,f){ @@ -404,7 +417,7 @@ $.prompt.getState('state2') } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -448,7 +461,7 @@ $.prompt.open(statesdemo);</pre> } }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -517,7 +530,7 @@ tourStates = [ submit: tourSubmitFunc } ]; -$.prompt.open(tourStates);</pre> +$.prompt(tourStates);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> @@ -575,7 +588,7 @@ $.prompt.open(tourStates);</pre> }, }; -$.prompt.open(statesdemo);</pre> +$.prompt(statesdemo);</pre> <div class="buttons"> <button class="run">Run It!</button> </div> diff --git a/src/jquery-impromptu.js b/src/jquery-impromptu.js index 803b920..34d07b6 100644 --- a/src/jquery-impromptu.js +++ b/src/jquery-impromptu.js @@ -480,6 +480,14 @@ },
/**
+ * get - Get the box containing fade and prompt
+ * @return jQuery - the prompt
+ */
+ getBox: function() {
+ return this.jqib;
+ },
+
+ /**
* get - Get the prompt
* @return jQuery - the prompt
*/
@@ -738,6 +746,61 @@ };
// ########################################################################
+ // $.prompt will manage a queue of Impromptu instances
+ // ########################################################################
+
+ /**
+ * $.prompt create a new Impromptu instance and push it on the stack of instances
+ * @param message String/Object - String of html or Object of states
+ * @param options Object - Options to set the prompt
+ * @return jQuery - the jQuery object of the prompt within the modal
+ */
+ $.prompt = function(message, options){
+ var api = new Imp();
+ $.prompt.lifo.push(api);
+
+ api.open.apply(api, arguments);
+ return api.jqi;
+ };
+
+ /**
+ * @var Array - An array of Impromptu intances in a LIFO queue (last in first out)
+ */
+ $.prompt.lifo = [];
+
+ /**
+ * $.prompt.getLast - get the last element from the queue (doesn't pop, just returns)
+ * @return Imp - the instance of this Impromptu object or false if queue is empty
+ */
+ $.prompt.getLast = function(){
+ var l = $.prompt.lifo.length;
+ return (l > 0)? $.prompt.lifo[l-1] : false;
+ };
+
+ /**
+ * Copy over static methods
+ */
+ $.each(Imp, function(k,v){
+ $.prompt[k] = v;
+ });
+
+ /**
+ * Create a proxy for accessing all instance methods. The close method pops from queue.
+ */
+ $.each(Imp.prototype, function(k,v){
+ $.prompt[k] = function(){
+ var api = $.prompt.getLast();
+
+ if(api && typeof api[k] === "function"){
+ if(k === 'close'){
+ $.prompt.lifo.pop();
+ }
+ return api[k].apply(api, arguments);
+ }
+ };
+ });
+
+ // ########################################################################
// jQuery Plugin and public access
// ########################################################################
@@ -762,10 +825,4 @@ */
window.Impromptu = Imp;
- /**
- * Set $.prompt as a single instance
- * Can be used from here forth as $.prompt.open(state, opts)
- */
- $.prompt = new Imp();
-
}));
|