pietimer-cis 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/jquery.pietimer.js +185 -0
- data/app/assets/javascripts/jquery.pietimer.min.js +1 -0
- data/lib/generators/pietimer_cis/install/install_generator.rb +37 -0
- data/lib/pietimer-cis.rb +14 -0
- data/lib/pietimer-cis/rails.rb +3 -0
- data/lib/pietimer-cis/rails/engine.rb +6 -0
- data/lib/pietimer-cis/rails/railtie.rb +8 -0
- data/lib/pietimer-cis/view_helpers.rb +16 -0
- metadata +90 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
pietimer-cis
|
2
|
+
=================
|
3
|
+
|
4
|
+
With the help of this gem you can easily have the counter as a pie for your application on load(page load). :-)
|
5
|
+
|
6
|
+
INSTALLTION
|
7
|
+
|
8
|
+
First thing you need to do is the installation , you can follow the below mentioned steps to install the gem inside your rails application.
|
9
|
+
You need to add sudo if you are not using rvm(ruby version manager)
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install pietimer-cis -v 0.0.5
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
Add this following line in your Gemfile and then run bundle install.
|
17
|
+
```
|
18
|
+
gem "pietimer-cis", "~> 0.0.5"
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
USAGE
|
24
|
+
|
25
|
+
Once you have installed this gem you can do the following :-
|
26
|
+
|
27
|
+
#Call generater for required js of pietimer-cis.
|
28
|
+
```
|
29
|
+
rails generate pietimer_cis:install
|
30
|
+
```
|
31
|
+
|
32
|
+
#application.html.haml
|
33
|
+
```
|
34
|
+
#demo
|
35
|
+
```
|
36
|
+
|
37
|
+
# 'pietimer_tag' put where you want the pietimer.
|
38
|
+
```
|
39
|
+
= pietimer_tag(:id=>"demo",:time=>10,:color=>'green',:callback=>"function(){alert('Hello World')}")
|
40
|
+
```
|
41
|
+
here,in pietimer_tag we can set any time period,color and can call any function but that must be defined.
|
42
|
+
|
43
|
+
OR
|
44
|
+
|
45
|
+
```
|
46
|
+
= pietimer_tag(:id=>"demo",:time=>10,:color=>'green',:callback=>"function(){test();}")
|
47
|
+
```
|
48
|
+
|
49
|
+
```Javascript
|
50
|
+
function test(){
|
51
|
+
alert("This is testing");
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2012, Northfield X Ltd
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Modified BSD License
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
9
|
+
* Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
* Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
* Neither the name of the <organization> nor the
|
15
|
+
names of its contributors may be used to endorse or promote products
|
16
|
+
derived from this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
*/
|
29
|
+
(function ($) {
|
30
|
+
'use strict';
|
31
|
+
|
32
|
+
var DEFAULT_VALUE = 360;
|
33
|
+
|
34
|
+
var DEFAULT_SETTINGS = {
|
35
|
+
seconds: 10,
|
36
|
+
color: 'rgba(255, 255, 255, 0.8)',
|
37
|
+
height: null,
|
38
|
+
width: null,
|
39
|
+
elementID: null
|
40
|
+
};
|
41
|
+
|
42
|
+
// Internal constants
|
43
|
+
var PIE_TIMER_INTERVAL = 40;
|
44
|
+
|
45
|
+
var TIMER_CSS_CLASS = 'pie_timer';
|
46
|
+
|
47
|
+
var PIE_TIMER_DATA_NAME = 'pie_timer';
|
48
|
+
|
49
|
+
// Math constants
|
50
|
+
var THREE_PI_BY_TWO = 3 * Math.PI / 2;
|
51
|
+
|
52
|
+
var PI_BY_180 = Math.PI / 180;
|
53
|
+
|
54
|
+
var PieTimer = function (jquery_object, settings, callback) {
|
55
|
+
if (settings.width === null) {
|
56
|
+
settings.width = jquery_object.width();
|
57
|
+
}
|
58
|
+
if (settings.height === null) {
|
59
|
+
settings.height = jquery_object.height();
|
60
|
+
}
|
61
|
+
|
62
|
+
this.settings = settings;
|
63
|
+
this.jquery_object = jquery_object;
|
64
|
+
this.interval_id = null;
|
65
|
+
this.current_value = DEFAULT_VALUE;
|
66
|
+
this.callback = callback;
|
67
|
+
this.is_paused = true;
|
68
|
+
this.jquery_object.html('<canvas class="' + TIMER_CSS_CLASS + '" width="' + settings.width + '" height="' + settings.height + '"></canvas>');
|
69
|
+
this.canvas = this.jquery_object.children('.' + TIMER_CSS_CLASS)[0];
|
70
|
+
this.pieSeconds = this.settings.seconds;
|
71
|
+
};
|
72
|
+
|
73
|
+
PieTimer.prototype = {
|
74
|
+
start: function () {
|
75
|
+
if (this.is_paused) {
|
76
|
+
if (this.current_value <= 0) {
|
77
|
+
this.current_value = DEFAULT_VALUE;
|
78
|
+
}
|
79
|
+
this.interval_id = setInterval($.proxy(this.run_timer, this), PIE_TIMER_INTERVAL);
|
80
|
+
this.is_paused = false;
|
81
|
+
}
|
82
|
+
},
|
83
|
+
|
84
|
+
pause: function () {
|
85
|
+
if (!this.is_paused) {
|
86
|
+
clearInterval(this.interval_id);
|
87
|
+
this.is_paused = true;
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
run_timer: function () {
|
92
|
+
if (this.canvas.getContext) {
|
93
|
+
|
94
|
+
this.current_value -= (DEFAULT_VALUE / this.settings.seconds) / 24;
|
95
|
+
|
96
|
+
if(this.settings.elementID){
|
97
|
+
var seconds = Math.ceil(this.current_value/DEFAULT_VALUE * this.settings.seconds);
|
98
|
+
if(this.pieSeconds !== seconds){
|
99
|
+
this.pieSeconds = seconds;
|
100
|
+
$('#'+this.settings.elementID).html(this.pieSeconds);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
if (this.current_value <= 0) {
|
105
|
+
clearInterval(this.interval_id);
|
106
|
+
|
107
|
+
// This is a total hack to clear the canvas. It would be
|
108
|
+
// better to fill the canvas with the background color
|
109
|
+
this.canvas.width = this.settings.width;
|
110
|
+
|
111
|
+
if ($.isFunction(this.callback)) {
|
112
|
+
this.callback.call();
|
113
|
+
}
|
114
|
+
this.is_paused = true;
|
115
|
+
|
116
|
+
} else {
|
117
|
+
// This is a total hack to clear the canvas. It would be
|
118
|
+
// better to fill the canvas with the background color
|
119
|
+
this.canvas.width = this.settings.width;
|
120
|
+
|
121
|
+
var ctx = this.canvas.getContext('2d');
|
122
|
+
|
123
|
+
var canvas_size = [this.canvas.width, this.canvas.height];
|
124
|
+
var radius = Math.min(canvas_size[0], canvas_size[1]) / 2;
|
125
|
+
var center = [canvas_size[0] / 2, canvas_size[1] / 2];
|
126
|
+
|
127
|
+
ctx.beginPath();
|
128
|
+
ctx.moveTo(center[0], center[1]);
|
129
|
+
var start = THREE_PI_BY_TWO;
|
130
|
+
ctx.arc(
|
131
|
+
center[0],
|
132
|
+
center[1],
|
133
|
+
radius,
|
134
|
+
start - this.current_value * PI_BY_180,
|
135
|
+
start,
|
136
|
+
false
|
137
|
+
);
|
138
|
+
|
139
|
+
ctx.closePath();
|
140
|
+
ctx.fillStyle = this.settings.color;
|
141
|
+
ctx.fill();
|
142
|
+
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
var create_timer = function (options, callback) {
|
149
|
+
var settings = $.extend({}, DEFAULT_SETTINGS, options);
|
150
|
+
|
151
|
+
return this.each(function () {
|
152
|
+
var $element = $(this);
|
153
|
+
var pie_timer = new PieTimer($element, settings, callback);
|
154
|
+
$element.data(PIE_TIMER_DATA_NAME, pie_timer);
|
155
|
+
});
|
156
|
+
};
|
157
|
+
|
158
|
+
var call_timer_method = function (method_name) {
|
159
|
+
if (!(method_name in PieTimer.prototype)) {
|
160
|
+
$.error('Method ' + method_name + ' does not exist on jQuery.pietimer');
|
161
|
+
}
|
162
|
+
var sliced_arguments = Array.prototype.slice.call(arguments, 1);
|
163
|
+
|
164
|
+
return this.each(function () {
|
165
|
+
var $element = $(this);
|
166
|
+
var pie_timer = $element.data(PIE_TIMER_DATA_NAME);
|
167
|
+
|
168
|
+
if (!pie_timer) {
|
169
|
+
// This element hasn't had pie timer constructed yet, so skip it
|
170
|
+
return true;
|
171
|
+
}
|
172
|
+
pie_timer[method_name].apply(pie_timer, sliced_arguments);
|
173
|
+
});
|
174
|
+
};
|
175
|
+
|
176
|
+
$.fn.pietimer = function (method) {
|
177
|
+
|
178
|
+
if (typeof method === 'object' || ! method) {
|
179
|
+
return create_timer.apply(this, arguments);
|
180
|
+
} else {
|
181
|
+
return call_timer_method.apply(this, arguments);
|
182
|
+
}
|
183
|
+
};
|
184
|
+
|
185
|
+
})(jQuery);
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(e){"use strict";var t=360,n={seconds:10,color:"rgba(255, 255, 255, 0.8)",height:null,width:null,elementID:null},r=40,i="pie_timer",s="pie_timer",o=3*Math.PI/2,u=Math.PI/180,a=function(e,n,r){n.width===null&&(n.width=e.width());n.height===null&&(n.height=e.height());this.settings=n;this.jquery_object=e;this.interval_id=null;this.current_value=t;this.callback=r;this.is_paused=!0;this.jquery_object.html('<canvas class="'+i+'" width="'+n.width+'" height="'+n.height+'"></canvas>');this.canvas=this.jquery_object.children("."+i)[0];this.pieSeconds=this.settings.seconds};a.prototype={start:function(){if(this.is_paused){this.current_value<=0&&(this.current_value=t);this.interval_id=setInterval(e.proxy(this.run_timer,this),r);this.is_paused=!1}},pause:function(){if(!this.is_paused){clearInterval(this.interval_id);this.is_paused=!0}},run_timer:function(){if(this.canvas.getContext){this.current_value-=t/this.settings.seconds/24;if(this.settings.elementID){var n=Math.ceil(this.current_value/t*this.settings.seconds);if(this.pieSeconds!==n){this.pieSeconds=n;e("#"+this.settings.elementID).html(this.pieSeconds)}}if(this.current_value<=0){clearInterval(this.interval_id);this.canvas.width=this.settings.width;e.isFunction(this.callback)&&this.callback.call();this.is_paused=!0}else{this.canvas.width=this.settings.width;var r=this.canvas.getContext("2d"),i=[this.canvas.width,this.canvas.height],s=Math.min(i[0],i[1])/2,a=[i[0]/2,i[1]/2];r.beginPath();r.moveTo(a[0],a[1]);var f=o;r.arc(a[0],a[1],s,f-this.current_value*u,f,!1);r.closePath();r.fillStyle=this.settings.color;r.fill()}}}};var f=function(t,r){var i=e.extend({},n,t);return this.each(function(){var t=e(this),n=new a(t,i,r);t.data(s,n)})},l=function(t){t in a.prototype||e.error("Method "+t+" does not exist on jQuery.pietimer");var n=Array.prototype.slice.call(arguments,1);return this.each(function(){var r=e(this),i=r.data(s);if(!i)return!0;i[t].apply(i,n)})};e.fn.pietimer=function(e){return typeof e=="object"||!e?f.apply(this,arguments):l.apply(this,arguments)}})(jQuery);
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
if ::Rails.version < "3.1"
|
4
|
+
module PietimerCis
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < ::Rails::Generators::Base
|
7
|
+
|
8
|
+
desc "This generator installs Jquery , CSS and Images"
|
9
|
+
source_root File.expand_path('../../../../../app/assets', __FILE__)
|
10
|
+
|
11
|
+
def copy_jquery_nested
|
12
|
+
copy_file "javascripts/jquery.pietimer.min.js", "public/javascripts/jquery.pietimer.min.js"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
module PietimerCis
|
19
|
+
module Generators
|
20
|
+
class InstallGenerator < ::Rails::Generators::Base
|
21
|
+
desc "This generator installs Jquery , CSS and Images"
|
22
|
+
source_root File.expand_path('../../../../../app/assets', __FILE__)
|
23
|
+
def add_assets
|
24
|
+
if detect_js_format.nil?
|
25
|
+
copy_file "javascripts/jquery.pietimer.min.js", "app/assets/javascripts/jquery.pietimer.min.js"
|
26
|
+
else
|
27
|
+
insert_into_file "app/assets/javascripts/application#{detect_js_format[0]}", "#{detect_js_format[1]} require jquery.pietimer.min\n", :after => "jquery_ujs\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def detect_js_format
|
31
|
+
return ['.js.coffee', '#='] if File.exist?('app/assets/javascripts/application.js.coffee')
|
32
|
+
return ['.js', '//='] if File.exist?('app/assets/javascripts/application.js')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/pietimer-cis.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module PietimerCis
|
2
|
+
module ViewHelpers
|
3
|
+
def pietimer_tag(options={})
|
4
|
+
messages = "<script type=\"text/javascript\">"
|
5
|
+
|
6
|
+
unless options.blank?
|
7
|
+
messages += "$(function(){"
|
8
|
+
messages += "$(\"##{options[:id]}\").pietimer({seconds: #{options[:time].blank? ? 10 : options[:time].to_i },color: \"#{options[:color].blank? ? 'blank' : options[:color] }\",height: 100,width: 100},#{options[:callback].blank? ? "function(){alert('Time is Out.')}" : options[:callback] });"
|
9
|
+
messages += "$(\"##{options[:id]}\").pietimer('start');"
|
10
|
+
messages += "});"
|
11
|
+
end
|
12
|
+
messages += "</script>"
|
13
|
+
messages.html_safe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pietimer-cis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mohan Salvi
|
9
|
+
- CISROR Team
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jquery-rails
|
17
|
+
requirement: &11084600 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *11084600
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: coffee-rails
|
28
|
+
requirement: &11083860 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *11083860
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: railties
|
39
|
+
requirement: &11083020 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *11083020
|
48
|
+
description: pietimer-cis will provide you a counter as a pie
|
49
|
+
email:
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/pietimer-cis/view_helpers.rb
|
55
|
+
- lib/pietimer-cis/rails.rb
|
56
|
+
- lib/pietimer-cis/rails/railtie.rb
|
57
|
+
- lib/pietimer-cis/rails/engine.rb
|
58
|
+
- lib/pietimer-cis.rb
|
59
|
+
- lib/generators/pietimer_cis/install/install_generator.rb
|
60
|
+
- app/assets/javascripts/jquery.pietimer.js
|
61
|
+
- app/assets/javascripts/jquery.pietimer.min.js
|
62
|
+
- Rakefile
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
homepage:
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.3.6
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: jquery-rails
|
86
|
+
rubygems_version: 1.8.11
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: pietimer-cis will provide you a counter as a pie
|
90
|
+
test_files: []
|