[Pkg-javascript-commits] [jquery-timer.js] 01/04: Imported Upstream version 0.0~git20150215.0.233601d

Alexandre Viau aviau at moszumanska.debian.org
Tue Dec 29 19:50:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

aviau pushed a commit to branch master
in repository jquery-timer.js.

commit d0d1867c8900b15c3aea8304c07066501000c295
Author: aviau <alexandre at alexandreviau.net>
Date:   Mon Dec 28 17:19:35 2015 -0500

    Imported Upstream version 0.0~git20150215.0.233601d
---
 README.md       |  41 +++++++++++++++++++++
 demo.html       |  84 ++++++++++++++++++++++++++++++++++++++++++
 jquery.timer.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 236 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c00e3fe
--- /dev/null
+++ b/README.md
@@ -0,0 +1,41 @@
+# jQuery Timer
+
+Basically setTimeout with more options.
+
+View demo: [http://jchavannes.com/jquery-timer/demo](http://jchavannes.com/jquery-timer/demo)  
+  
+Download: [http://jchavannes.com/download/jquery-timer-demo.zip](http://jchavannes.com/download/jquery-timer-demo.zip)
+
+---
+
+## $.timer()
+
+#### $.timer( [ action ] , [ time ], [ autostart ] )
+
+* **action** A Function to be called by the timer.
+
+* **time A Number** determining how long between actions in milliseconds.
+
+* **autostart** A Boolean indicating whether to start the timer. Defaults to false.
+
+---
+
+## Usage
+
+```
+var timer = $.timer(function() {
+    alert('This message was sent by a timer.');
+});
+timer.set({ time : 5000, autostart : true });
+```
+
+```
+timer.set(options);
+timer.play(reset);  // Boolean. Defaults to false.
+timer.pause();
+timer.stop();  // Pause and resets
+timer.toggle(reset);  // Boolean. Defaults to false.
+timer.once(time);  // Number. Defaults to 0.
+timer.isActive  // Returns true if timer is running
+timer.remaining // Remaining time when paused
+```
diff --git a/demo.html b/demo.html
new file mode 100755
index 0000000..c168f13
--- /dev/null
+++ b/demo.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd"> 
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
+<head> 
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta name="author" content="Jason Chavannes" />
+    <title>jQuery Timer Demo</title>
+
+    <link rel="stylesheet" href="res/style.css" />
+    <script type="text/javascript" src="res/jquery.min.js"></script>
+    <script type="text/javascript" src="jquery.timer.js"></script>
+    <script type="text/javascript" src="res/demo.js"></script>
+</head> 
+<body>
+    <h1>jQuery Timer Demo</h1>
+    <p>Project home: <a href="http://jchavannes.com/jquery-timer" target="_blank">http://jchavannes.com/jquery-timer</a></p>
+    <p><a href="res/demo.js" target="_blank">View Source</a></p>
+
+    <hr/><h3 style='margin-top:20px;'>Example 1 - Stopwatch (counts ups)</h3>
+    <span id="stopwatch">00:00:00</span>
+    <p>
+        <input type='button' value='Play/Pause' onclick='Example1.Timer.toggle();' />
+        <input type='button' value='Stop/Reset' onclick='Example1.resetStopwatch();' />
+    </p>
+    <br/>
+    <br/>
+
+    <h3>Example 2 - Countdown Timer</h3>
+    <span id="countdown">05:00:00</span>
+    <form id="example2form">
+        <input type='button' value='Play/Pause' onclick='Example2.Timer.toggle();' />
+        <input type='button' value='Stop/Reset' onclick='Example2.resetCountdown();' />
+        <input type='text' name='startTime' value='300' style='width:30px;' />
+    </form>
+
+    <h3>Example 3 - Slideshow (preserves time remaining when paused)</h3>
+    <div class="galleryImages">
+        <img src='res/img/1.jpg' alt='' />
+        <img src='res/img/2.jpg' alt='' />
+        <img src='res/img/3.jpg' alt='' />
+        <img src='res/img/4.jpg' alt='' />
+        <img src='res/img/5.jpg' alt='' />
+        <img src='res/img/6.jpg' alt='' />
+        <img src='res/img/7.jpg' alt='' />
+        <img src='res/img/8.jpg' alt='' />
+        <img src='res/img/9.jpg' alt='' />
+        <img src='res/img/10.jpg' alt='' />
+        <img src='res/img/11.jpg' alt='' />
+        <img src='res/img/12.jpg' alt='' />
+        <img src='res/img/13.jpg' alt='' />
+        <img src='res/img/14.jpg' alt='' />
+        <img src='res/img/15.jpg' alt='' />
+        <img src='res/img/16.jpg' alt='' />
+        <img src='res/img/17.jpg' alt='' />
+    </div><br/>
+    <div id="timeRemaining"><br/></div>
+    <p class="example-three">
+        <input type='button' value='Play / Pause' onclick='Example3.toggleGallery();' />
+    </p>
+
+    <h3>Example 4 - The Basics (just a suped-up version of setTimeout)</h3>
+    <p>timer has been executed <span id='counter' style=''>0</span> times.</p>
+    <div class='example-four'>
+        <input type='button' value='timer.play()' onclick='timer.play();' /><br/>
+        <input type='button' value='timer.play(true)' onclick='timer.play(true);' /><br/>
+        <input type='button' value='timer.pause()' onclick='timer.pause();' /><br/>
+        <input type='button' value='timer.toggle()' onclick='timer.toggle();' /><br/>
+        <input type='button' value='timer.toggle(true)' onclick='timer.toggle(true);' /><br/>
+        <input type='button' value='timer.stop()' onclick='timer.stop();' />
+    </div>
+    <div class='example-four'>
+        <input type='button' value='timer.reset()' onclick='timer.reset();' /><br/>
+        <input type='button' value='timer.once()' onclick='timer.once();' /><br/>
+        <input type='button' value='timer.once(5000)' onclick='timer.once(5000);' /><br/>
+        <input type='button' value='timer.set({time:1000})' onclick='timer.set({time:1000});' /><br/>
+        <input type='button' value='timer.set({time:5000})' onclick='timer.set({time:5000});' />
+    </div>
+    <br/><pre style='margin-bottom:20px; padding:10px 15px;'>
+var count = 0;
+var timer = $.timer(function() {
+    $('#counter').html(++count);
+});
+timer.set({ time : 1000, autostart : true });</pre>
+</body>
+</html>
\ No newline at end of file
diff --git a/jquery.timer.js b/jquery.timer.js
new file mode 100644
index 0000000..89c2975
--- /dev/null
+++ b/jquery.timer.js
@@ -0,0 +1,111 @@
+/**
+ * jquery.timer.js
+ *
+ * Copyright (c) 2011 Jason Chavannes <jason.chavannes at gmail.com>
+ *
+ * http://jchavannes.com/jquery-timer
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+;(function($) {
+	$.timer = function(func, time, autostart) {	
+	 	this.set = function(func, time, autostart) {
+	 		this.init = true;
+	 	 	if(typeof func == 'object') {
+		 	 	var paramList = ['autostart', 'time'];
+	 	 	 	for(var arg in paramList) {if(func[paramList[arg]] != undefined) {eval(paramList[arg] + " = func[paramList[arg]]");}};
+ 	 			func = func.action;
+	 	 	}
+	 	 	if(typeof func == 'function') {this.action = func;}
+		 	if(!isNaN(time)) {this.intervalTime = time;}
+		 	if(autostart && !this.isActive) {
+			 	this.isActive = true;
+			 	this.setTimer();
+		 	}
+		 	return this;
+	 	};
+	 	this.once = function(time) {
+			var timer = this;
+	 	 	if(isNaN(time)) {time = 0;}
+			window.setTimeout(function() {timer.action();}, time);
+	 		return this;
+	 	};
+		this.play = function(reset) {
+			if(!this.isActive) {
+				if(reset) {this.setTimer();}
+				else {this.setTimer(this.remaining);}
+				this.isActive = true;
+			}
+			return this;
+		};
+		this.pause = function() {
+			if(this.isActive) {
+				this.isActive = false;
+				this.remaining -= new Date() - this.last;
+				this.clearTimer();
+			}
+			return this;
+		};
+		this.stop = function() {
+			this.isActive = false;
+			this.remaining = this.intervalTime;
+			this.clearTimer();
+			return this;
+		};
+		this.toggle = function(reset) {
+			if(this.isActive) {this.pause();}
+			else if(reset) {this.play(true);}
+			else {this.play();}
+			return this;
+		};
+		this.reset = function() {
+			this.isActive = false;
+			this.play(true);
+			return this;
+		};
+		this.clearTimer = function() {
+			window.clearTimeout(this.timeoutObject);
+		};
+	 	this.setTimer = function(time) {
+			var timer = this;
+	 	 	if(typeof this.action != 'function') {return;}
+	 	 	if(isNaN(time)) {time = this.intervalTime;}
+		 	this.remaining = time;
+	 	 	this.last = new Date();
+			this.clearTimer();
+			this.timeoutObject = window.setTimeout(function() {timer.go();}, time);
+		};
+	 	this.go = function() {
+	 		if(this.isActive) {
+				try { this.action(); }
+	 			finally { this.setTimer(); }
+	 		}
+	 	};
+	 	
+	 	if(this.init) {
+	 		return new $.timer(func, time, autostart);
+	 	} else {
+			this.set(func, time, autostart);
+	 		return this;
+	 	}
+	};
+})(jQuery);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/jquery-timer.js.git



More information about the Pkg-javascript-commits mailing list