benignware-jquery-rails 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- task :submodule do
3
+ task :update do
4
4
  sh 'git submodule update --init' unless File.exist?('checkview/README.md')
5
5
  end
6
6
 
@@ -10,22 +10,32 @@ task :clean do
10
10
  end
11
11
 
12
12
  desc "Generate the JavaScript assets"
13
- task :javascripts => :submodule do
13
+ task :assets => :update do
14
14
  target_dir = "vendor/assets/javascripts/benignware"
15
+
15
16
  mkdir_p target_dir
16
- Rake.rake_output_message 'Generating javascripts'
17
+
17
18
  Dir.glob("checkview/src/js/*.js").each do |path|
18
19
  basename = File.basename(path)
19
- dep_modules = get_js_dependencies(basename).map(&method(:remove_js_extension))
20
+ Rake.rake_output_message 'asset ' + basename
20
21
  File.open("#{target_dir}/#{basename}", "w") do |out|
21
- dep_modules.each do |mod|
22
- out.write("//= require #{mod}\n")
23
- end
24
- out.write("\n") unless dep_modules.empty?
22
+ out.write("\n")
25
23
  source_code = File.read(path)
26
- source_code.gsub!('@VERSION', version)
27
- protect_copyright_notice(source_code)
28
24
  out.write(source_code)
29
25
  end
30
26
  end
31
- end
27
+ end
28
+
29
+
30
+ desc 'Builds the gem'
31
+ task :build => [:clean, :assets] do
32
+ sh "gem build benignware-jquery-rails.gemspec"
33
+ end
34
+
35
+ desc 'Tags version, pushes to remote, and pushes gem'
36
+ task :release => :build do
37
+ sh "git push origin master"
38
+ sh "gem push benignware-jquery-rails-#{Benignware::Jquery::Rails::VERSION}.gem"
39
+ end
40
+
41
+ task :default => :build
@@ -1,7 +1,7 @@
1
1
  module Benignware
2
2
  module Jquery
3
3
  module Rails
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.9"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,198 @@
1
+
2
+ (function ( $, window) {
3
+
4
+ var pluginName = 'checkView';
5
+
6
+ var defaults = {
7
+ 'containerClass': 'checkview',
8
+ 'iconClass': 'icon-ok',
9
+ 'autoSubmit': true
10
+ };
11
+
12
+ // TODO: replace with jquery has
13
+ function isChildOf(child, parent) {
14
+ if (parent == child) return false;
15
+ var c = child;
16
+ try {
17
+ while (c) {
18
+ if (child.ownerDocument != null && c == child.ownerDocument.documentElement) return false;
19
+ if (c.parentNode == parent) return true;
20
+ if (c.parentNode == null) return false;
21
+ c = c.parentNode;
22
+ }
23
+ } catch (e) {
24
+ //console.error(e);
25
+ }
26
+ return false;
27
+ }
28
+
29
+ var pluginClass = function CheckView(element, options) {
30
+
31
+ var eventType = 'click';
32
+
33
+ var checkboxView = this;
34
+
35
+ var doc = element.ownerDocument;
36
+
37
+ var $elem = $(element);
38
+ element.tabIndex = "-1";
39
+
40
+ element.style.position = 'absolute';
41
+ element.style.width = '0';
42
+ element.style.height = '0';
43
+
44
+ var nextElement = $(element).next();
45
+ var previousElement = $(element).prev();
46
+ var valueElement = nextElement && nextElement.tagName == "input" && nextElement.type == "hidden" ? nextElement
47
+ : previousElement && previousElement.tagName == "input" && previousElement.type == "hidden" ? previousElement
48
+ : null;
49
+
50
+ var containerView = $(element).parents("." + options.containerClass)[0];
51
+ if (!containerView) {
52
+ containerView = doc.createElement('span');
53
+ element.parentNode.insertBefore(containerView, element);
54
+ }
55
+
56
+ containerView.tabIndex = "0";
57
+ containerView.className = options.containerClass;
58
+ containerView.style.display = 'inline-block';
59
+ containerView.style.lineHeight = "0";
60
+ containerView.style.cursor = "pointer";
61
+
62
+ var checkmarkIcon = doc.createElement('i');
63
+ checkmarkIcon.style.margin = "0";
64
+ checkmarkIcon.className = options.iconClass;
65
+ containerView.appendChild(checkmarkIcon);
66
+
67
+ // private methods
68
+
69
+ function toggleCheckbox() {
70
+ element.checked = !element.checked;
71
+ checkboxView.invalidate();
72
+ }
73
+
74
+ function init() {
75
+
76
+ if (!element.value) {
77
+ element.value = "on";
78
+ }
79
+
80
+ element.style.visibility = "hidden";
81
+ containerView.appendChild(element);
82
+ checkmarkIcon.style.verticalAlign = "top";
83
+
84
+ var $label;
85
+
86
+ $(containerView).bind('keypress', function(event) {
87
+
88
+ if (event.which == 32) {
89
+ element.checked = !element.checked;
90
+ checkboxView.invalidate();
91
+ }
92
+
93
+ if (event.which == 13 && options.autoSubmit) {
94
+ if (element.form) {
95
+ element.form.submit();
96
+ }
97
+ }
98
+
99
+ });
100
+
101
+
102
+ $(element).bind('change', function(event) {
103
+ checkboxView.invalidate();
104
+ window.clearTimeout(toggleClickTimeoutId);
105
+ });
106
+
107
+ $(containerView).parents('label').bind("click", function(event) {
108
+ if (event.target != element && event.target != containerView && !isChildOf(event.target, containerView)) {
109
+ event.stopImmediatePropagation();
110
+ $(containerView).trigger('click');
111
+ }
112
+ });
113
+
114
+ var toggleClickTimeoutId = null;
115
+
116
+ function toggleClick() {
117
+ element.checked = !element.checked;
118
+ $(element).trigger('change');
119
+ }
120
+
121
+ $(containerView).bind("click", function(event) {
122
+ if (event.target != element) {
123
+ window.clearTimeout(toggleClickTimeoutId);
124
+ toggleClickTimeoutId = window.setTimeout(function() {
125
+ toggleClick();
126
+ }, 100);
127
+ event.preventDefault();
128
+ };
129
+ });
130
+
131
+ $(window).bind('resize', function() {
132
+ checkboxView.invalidate();
133
+ });
134
+
135
+ this.invalidate();
136
+
137
+ };
138
+
139
+ function layout() {
140
+ if (element.checked) {
141
+ $(containerView).addClass('checked');
142
+ } else {
143
+ $(containerView).removeClass('checked');
144
+ }
145
+ checkmarkIcon.style.visibility = element.checked ? '' : 'hidden';
146
+ checkmarkIcon.style.position = 'relative';
147
+ checkmarkIcon.style.left = (($(containerView).width() - $(checkmarkIcon).width()) / 2) + 'px';
148
+ checkmarkIcon.style.top = (($(containerView).height() - $(checkmarkIcon).height()) / 2) + 'px';
149
+ };
150
+
151
+ // public methods
152
+
153
+ this.setChecked = function(bool) {
154
+ element.checked = bool;
155
+ if (bool) {
156
+ $(element).attr('checked', 'checked');
157
+ } else {
158
+ $(element).removeAttr('checked');
159
+ }
160
+ this.invalidate();
161
+ };
162
+
163
+ this.isChecked = function() {
164
+ return $(element).is(":checked");
165
+ };
166
+
167
+ this.invalidate = function() {
168
+ layout.call(this);
169
+ };
170
+
171
+ init.call(this);
172
+
173
+ };
174
+
175
+
176
+
177
+
178
+ // bootstrap plugin
179
+
180
+ $.fn[pluginName] = function(options) {
181
+
182
+ options = $.extend({}, defaults, options);
183
+
184
+ return this.each(function() {
185
+
186
+ if (!$(this).data(pluginName)) {
187
+
188
+ $(this).data(pluginName, new pluginClass(this, options));
189
+
190
+ }
191
+
192
+ return $(this);
193
+
194
+ });
195
+
196
+ };
197
+
198
+ })( jQuery, window );
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benignware-jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70242681900500 !ruby/object:Gem::Requirement
16
+ requirement: &70226902349420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: '5.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70242681900500
27
+ version_requirements: *70226902349420
28
28
  description: gem description
29
29
  email:
30
30
  - mail@benignware.com
@@ -41,7 +41,7 @@ files:
41
41
  - benignware-jquery-rails.gemspec
42
42
  - lib/benignware-jquery-rails.rb
43
43
  - lib/benignware-jquery-rails/version.rb
44
- - vendor/assets/javascripts/test.js
44
+ - vendor/assets/javascripts/benignware/jquery.checkView.js
45
45
  homepage: ''
46
46
  licenses: []
47
47
  post_install_message:
@@ -1 +0,0 @@
1
- console.info("RAILS GEM JAVASCRIPT TEST");