Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cut tests folder to root folder, implement init,start,reset methods i…

…n jQuery.progressBar plugin
  • Loading branch information...
commit 1662696fb191bca3d8fca4261f3e6cd7b265ef24 1 parent 2872f3c
Acaz Souza authored April 22, 2012
27  src/jquery.progressbar.js
@@ -5,14 +5,33 @@
5 5
         'done': null
6 6
     };
7 7
 
  8
+    var decreaseBar = function (barElement) {
  9
+        $(barElement).stop();
  10
+
  11
+        var barElementWidth = $(barElement).width();
  12
+        $(barElement).animate({ width: 0 }, settings.velocity, function () {
  13
+            if (0 >= $(barElement).width() && $.isFunction(settings.done)) {
  14
+                settings.done();
  15
+            }
  16
+        });
  17
+    }
  18
+
8 19
     var methods = {
9 20
         init: function (options) {
10 21
             settings = $.extend(settings, options);
11 22
 
12  
-            return this.each(function(){
13  
-                alert($.isFunction(settings.done));
14  
-                if ($.isFunction(settings.done))
15  
-                    settings.done();
  23
+            return this.each(function () {
  24
+
  25
+            });
  26
+        },
  27
+        start: function () {
  28
+            return this.each(function () {
  29
+                decreaseBar(this);
  30
+            });
  31
+        },
  32
+        reset: function () {
  33
+            return this.each(function () {
  34
+                $(this).width($(this).parent().width());
16 35
             });
17 36
         }
18 37
     };
47  src/tests/jQuery.ProgressBarTests.html
... ...
@@ -1,47 +0,0 @@
1  
-<!DOCTYPE html>
2  
-<html>
3  
-<head>
4  
-    <meta charset="utf-8">
5  
-    <title>jQuery.ProgressBar Tests</title>
6  
-
7  
-    <link href="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
8  
-
9  
-    <script type="text/javascript" src="../../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
10  
-    <script type="text/javascript" src="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
11  
-
12  
-    <script type="text/javascript" src="../jquery.progressbar.js"></script>
13  
-
14  
-    <script type="text/javascript">
15  
-        $(function () {
16  
-            test("$('#SomeDiv').progressBar() should return a jQuery Object", function () {
17  
-                var progressaBar = $('#SomeDiv').progressBar();
18  
-                equal(null != progressaBar.jquery, true);
19  
-            });
20  
-
21  
-            test("Done() event should trigger when barProgress finish", function () {
22  
-                var wasCalled = false;
23  
-
24  
-                $('#SomeDiv').progressBar({
25  
-                    done: function () {
26  
-                        wasCalled = true;
27  
-                        alert('teste');
28  
-                    }
29  
-                });
30  
-
31  
-                equal(wasCalled, true);
32  
-            });
33  
-
34  
-            test("$('#SomeDiv').progressBar() should trigger an function when done.", function () {
35  
-            });
36  
-        });
37  
-    </script>
38  
-</head>
39  
-<body>
40  
-    <h1 id="qunit-header">jQuery.ProgressBar Tests</h1>
41  
-    <h2 id="qunit-banner"></h2>
42  
-    <div id="qunit-testrunner-toolbar"></div>
43  
-    <h2 id="qunit-userAgent"></h2>
44  
-    <ol id="qunit-tests"></ol>
45  
-    <div id="qunit-fixture">test markup, will be hidden</div>
46  
-</body>
47  
-</html>
8  src/tests/TwinooTests.html → tests/TwinooTests.html
@@ -4,12 +4,12 @@
4 4
     <meta charset="utf-8">
5 5
     <title>Twinoo Tests</title>
6 6
 
7  
-    <link href="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
  7
+    <link href="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
8 8
 
9  
-    <script type="text/javascript" src="../../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
10  
-    <script type="text/javascript" src="../../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
  9
+    <script type="text/javascript" src="../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
  10
+    <script type="text/javascript" src="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
11 11
 
12  
-    <script type="text/javascript" src="../twinoo.js"></script>
  12
+    <script type="text/javascript" src="../src/twinoo.js"></script>
13 13
 
14 14
     <script type="text/javascript">
15 15
         $(function () {
83  tests/jQuery.ProgressBarTests.html
... ...
@@ -0,0 +1,83 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+    <meta charset="utf-8">
  5
+    <title>jQuery.ProgressBar Tests</title>
  6
+
  7
+    <link href="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.css" rel="stylesheet" />
  8
+
  9
+    <script type="text/javascript" src="../libs/jquery-1.7.2/jquery-1.7.2.js"></script>
  10
+    <script type="text/javascript" src="../libs/jquery-qunit-v1.5.0-7-g4f51c3f/qunit/qunit.js"></script>
  11
+
  12
+    <script type="text/javascript" src="../src/jquery.progressbar.js"></script>
  13
+
  14
+    <style type="text/css">
  15
+        .barProgress { width:100%; height:20px; border:solid 1px #000; position:relative }
  16
+        
  17
+        .barProgress .bar { width:100%; height:20px; position:absolute; right:0; background-color:red  }
  18
+    </style>
  19
+
  20
+    <script type="text/javascript">
  21
+        $(function () {
  22
+
  23
+            module("$.progressBar() Tests", {
  24
+                setup: function () {
  25
+                    var HTMLStub = '<div id="div-id" class="barProgress"><div class="bar"></div><div>';
  26
+                    $(HTMLStub).appendTo('body');
  27
+                },
  28
+                teardown: function () {
  29
+                    $('#div-id').remove();
  30
+                }
  31
+            });
  32
+
  33
+            test("$('#div-id').progressBar() should return a jQuery Object", function () {
  34
+                var myProgressBar = $('#div-id').progressBar();
  35
+                equal(null != myProgressBar.jquery, true);
  36
+            });
  37
+
  38
+            asyncTest("done() event should trigger when barProgress finish", function () {
  39
+                var wasCalled = false;
  40
+
  41
+                var myProgressBar = $('#div-id').progressBar({
  42
+                    done: function () {
  43
+                        wasCalled = true;
  44
+                    }
  45
+                });
  46
+
  47
+                myProgressBar.progressBar('start');
  48
+
  49
+                setTimeout(function () {
  50
+                    start();
  51
+                    equal(wasCalled, true);
  52
+                }, 100);
  53
+            });
  54
+
  55
+            asyncTest("start() method should decrease the width of .bar div to 0", function () {
  56
+                var myProgressBar = $('#div-id').progressBar();
  57
+                myProgressBar.progressBar('start');
  58
+
  59
+                setTimeout(function () {
  60
+                    start();
  61
+                    equal(0 == myProgressBar.find('.bar').width(), true);
  62
+                }, 100);
  63
+            });
  64
+
  65
+            test("reset() method should increase the width of .bar div to 100", function () {
  66
+                var myProgressBar = $('#div-id').progressBar();
  67
+                myProgressBar.progressBar('start');
  68
+                myProgressBar.progressBar('reset');
  69
+
  70
+                equal($('.barProgress').width() == myProgressBar.find('.bar').width(), true);
  71
+            });
  72
+        });
  73
+    </script>
  74
+</head>
  75
+<body>
  76
+    <h1 id="qunit-header">jQuery.ProgressBar Tests</h1>
  77
+    <h2 id="qunit-banner"></h2>
  78
+    <div id="qunit-testrunner-toolbar"></div>
  79
+    <h2 id="qunit-userAgent"></h2>
  80
+    <ol id="qunit-tests"></ol>
  81
+    <div id="qunit-fixture">test markup, will be hidden</div>
  82
+</body>
  83
+</html>

0 notes on commit 1662696

Please sign in to comment.
Something went wrong with that request. Please try again.