digital_opera 0.0.8 → 0.0.9

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.
@@ -0,0 +1,9 @@
1
+ beforeEach(function() {
2
+ // this.addMatchers({
3
+ // toBePlaying: function(expectedSong) {
4
+ // var player = this.actual;
5
+ // return player.currentlyPlayingSong === expectedSong &&
6
+ // player.isPlaying;
7
+ // }
8
+ // });
9
+ });
@@ -0,0 +1,7 @@
1
+ describe("digital_opera_namespace", function() {
2
+
3
+ it("should be in the global space", function() {
4
+ expect(window.digitalOpera).toBeDefined();
5
+ });
6
+
7
+ });
@@ -0,0 +1,55 @@
1
+ describe("ellipsis", function() {
2
+ describe("#ellipsis", function(){
3
+ var element;
4
+
5
+ beforeEach(function(){
6
+ element = $('<div></div>');
7
+ $('body').append(element);
8
+ });
9
+
10
+ afterEach(function(){
11
+ element.remove();
12
+ });
13
+
14
+ it('should animate ellipsis', function(){
15
+ len = element.text().length;
16
+
17
+ runs(function(){
18
+ window.digitalOpera.ellipsis(element);
19
+ });
20
+
21
+ waitsFor(function() {
22
+ return element.text().length == (len + 1)
23
+ }, "The text length should increment", 751);
24
+
25
+ runs(function(){
26
+ expect(element.text().length).toBe(1);
27
+ });
28
+
29
+ waitsFor(function() {
30
+ return element.text().length == (len + 2)
31
+ }, "The text length should increment", 751);
32
+
33
+ runs(function(){
34
+ expect(element.text().length).toBe(2);
35
+ });
36
+
37
+ waitsFor(function() {
38
+ return element.text().length == (len + 3)
39
+ }, "The text length should increment", 751);
40
+
41
+ runs(function(){
42
+ expect(element.text().length).toBe(3);
43
+ });
44
+
45
+ waitsFor(function() {
46
+ return element.text().length == len
47
+ }, "The text length should increment", 751);
48
+
49
+ runs(function(){
50
+ expect(element.text().length).toBe(0);
51
+ });
52
+
53
+ });
54
+ });
55
+ });
@@ -0,0 +1,84 @@
1
+ describe("events", function() {
2
+ describe("#isClickOutsideElement", function(){
3
+ var first, second;
4
+
5
+ beforeEach(function(){
6
+ first = $('<div id="first-element"></div>');
7
+ second = $('<div id="second-element"></div>');
8
+ $('body').append(first);
9
+ first.append(second);
10
+ });
11
+
12
+ afterEach(function(){
13
+ first.remove();
14
+ second.remove();
15
+ });
16
+
17
+ describe('when click is outside of element', function(){
18
+ it("should return true", function() {
19
+ var loggedEvent;
20
+
21
+ runs(function(){
22
+ first.on('click', function(e){
23
+ loggedEvent = e;
24
+ });
25
+ setTimeout(function(){
26
+ first.click();
27
+ });
28
+ });
29
+
30
+ waitsFor(function(){
31
+ return typeof loggedEvent !== 'undefined';
32
+ }, 'waiting for click', 1000)
33
+
34
+ runs(function(){
35
+ expect(window.digitalOpera.isClickOutsideElement(loggedEvent, second)).toBe(true);
36
+ });
37
+ });
38
+ });
39
+
40
+ describe('when click is inside of element', function(){
41
+ it("should return false if click is on element inside", function() {
42
+ var loggedEvent;
43
+
44
+ runs(function(){
45
+ second.on('click', function(e){
46
+ loggedEvent = e;
47
+ });
48
+ setTimeout(function(){
49
+ second.click();
50
+ });
51
+ });
52
+
53
+ waitsFor(function(){
54
+ return typeof loggedEvent !== 'undefined';
55
+ }, 'waiting for click', 1000)
56
+
57
+ runs(function(){
58
+ expect(window.digitalOpera.isClickOutsideElement(loggedEvent, first)).toBe(false);
59
+ });
60
+ });
61
+
62
+ it("should return false if click was on element", function() {
63
+ var loggedEvent;
64
+
65
+ runs(function(){
66
+ second.on('click', function(e){
67
+ loggedEvent = e;
68
+ });
69
+ setTimeout(function(){
70
+ second.click();
71
+ });
72
+ });
73
+
74
+ waitsFor(function(){
75
+ return typeof loggedEvent !== 'undefined';
76
+ }, 'waiting for click', 1000)
77
+
78
+ runs(function(){
79
+ expect(window.digitalOpera.isClickOutsideElement(loggedEvent, second)).toBe(false);
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
@@ -0,0 +1,24 @@
1
+ describe("forms", function() {
2
+ describe('#parameterizeObject', function(){
3
+ var obj = {
4
+ foo: 'bar',
5
+ test: {
6
+ jasper: 'johns',
7
+ jimmie: {
8
+ car: 24,
9
+ name: 'johnson'
10
+ }
11
+ }
12
+ }
13
+
14
+ it('should go one level deep', function(){
15
+ expect(window.digitalOpera.parameterizeObject(obj)['foo']).toBe('bar');
16
+ });
17
+
18
+ it('should go 2+ levels deep', function(){
19
+ expect(window.digitalOpera.parameterizeObject(obj)['test[jasper]']).toBe('johns');
20
+ expect(window.digitalOpera.parameterizeObject(obj)['test[jimmie][car]']).toBe(24);
21
+ });
22
+ });
23
+
24
+ });
@@ -0,0 +1,76 @@
1
+ describe("preload_images", function() {
2
+ describe("#preload_images", function(){
3
+ var google = 'https://www.google.com/images/srpr/logo11w.png',
4
+ yahoo = 'http://hsrd.yahoo.com/_ylt=Aik.d0d_wDz.Tgk8eZ3.fQebvZx4/RV=1/RE=1386289411/RH=aHNyZC55YWhvby5jb20-/RO=2/RU=aHR0cDovL3d3dy55YWhvby5jb20v/RS=%5EADApJ47g2yGOT5vjkk0x6iSuoumc_w-',
5
+ bad = 'http://www.digitalopera.com/bad.png';
6
+
7
+ it('should take a string', function(){
8
+ expect(function(){window.digitalOpera.preloadImages(google)}).not.toThrow();
9
+ });
10
+
11
+ it('should take an array', function(){
12
+ expect(function(){window.digitalOpera.preloadImages([google])}).not.toThrow();
13
+ });
14
+
15
+ it('should callback once a single image loaded', function(){
16
+ var images,
17
+ callbackCalled = false;
18
+
19
+ runs(function(){
20
+ images = window.digitalOpera.preloadImages(google, function(){
21
+ callbackCalled = true;
22
+ });
23
+ });
24
+
25
+ waitsFor(function(){
26
+ return callbackCalled == true;
27
+ }, 'callback should have been called', 5000);
28
+
29
+ runs(function(){
30
+ expect(images[0].complete).toBe(true);
31
+ });
32
+
33
+ });
34
+
35
+ it('should callback once all images are loaded', function(){
36
+ var images,
37
+ callbackCalled = false;
38
+
39
+ runs(function(){
40
+ images = window.digitalOpera.preloadImages([google, yahoo], function(){
41
+ callbackCalled = true;
42
+ });
43
+ });
44
+
45
+ waitsFor(function(){
46
+ return callbackCalled == true;
47
+ }, 'callback should have been called', 5000);
48
+
49
+ runs(function(){
50
+ expect(images[0].complete).toBe(true);
51
+ expect(images[1].complete).toBe(true);
52
+ });
53
+
54
+ });
55
+
56
+ it('should callback if there was an error', function(){
57
+ var images,
58
+ callbackCalled = false;
59
+
60
+ runs(function(){
61
+ images = window.digitalOpera.preloadImages(bad, function(){
62
+ callbackCalled = true;
63
+ });
64
+ });
65
+
66
+ waitsFor(function(){
67
+ return callbackCalled == true;
68
+ }, 'callback should have been called', 5000);
69
+
70
+ runs(function(){
71
+ expect(images[0].complete).toBe(true);
72
+ });
73
+ });
74
+
75
+ });
76
+ });
@@ -0,0 +1,51 @@
1
+ describe("strings", function() {
2
+ describe("#capitalize", function(){
3
+ it('should capitalize first character', function(){
4
+ expect(window.digitalOpera.capitalize('foobar')).toBe('Foobar');
5
+ });
6
+
7
+ it('should capitalize first character of only first word', function(){
8
+ expect(window.digitalOpera.capitalize('foo bar')).toBe('Foo bar');
9
+ });
10
+
11
+ it('should not change any character besides first', function(){
12
+ expect(window.digitalOpera.capitalize('foObar')).toBe('FoObar');
13
+ });
14
+ });
15
+
16
+ describe("#titleize", function(){
17
+ it('should capitalize first character', function(){
18
+ expect(window.digitalOpera.titleize('foobar')).toBe('Foobar');
19
+ });
20
+
21
+ it('should capitalize first character of each word', function(){
22
+ expect(window.digitalOpera.titleize('foo bar')).toBe('Foo Bar');
23
+ });
24
+
25
+ it('should lowercase all characters beside the first char of each word', function(){
26
+ expect(window.digitalOpera.titleize('foO bAr')).toBe('Foo Bar');
27
+ });
28
+ });
29
+
30
+ describe("#formatJSONErrors", function(){
31
+ var string = '{"email": ["must be at least 6 characters","must contain a number and a letter"], "name":["can not be blank"]}';
32
+ var json = JSON.parse(string);
33
+
34
+ it('should take a string', function(){
35
+ expect(function(){window.digitalOpera.formatJSONErrors(string)}).not.toThrow();
36
+ });
37
+
38
+ it('should take JSON', function(){
39
+ expect(function(){window.digitalOpera.formatJSONErrors(json)}).not.toThrow();
40
+ });
41
+
42
+ it('should make error sentences', function(){
43
+ expect(window.digitalOpera.formatJSONErrors(string)[0]).toMatch('Email must be at least 6 characters and must contain a number and a letter');
44
+ expect(window.digitalOpera.formatJSONErrors(string)[1]).toMatch('Name can not be blank');
45
+ });
46
+
47
+ it('should have 2 errors', function(){
48
+ expect(window.digitalOpera.formatJSONErrors(string).length).toBe(2);
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,48 @@
1
+ describe("tables", function() {
2
+ describe('row click with [data-href]', function(){
3
+ var table,
4
+ focusObject = {focus: function(){}};
5
+
6
+ beforeEach(function(){
7
+ table = $('<table><tr data-href="http://google.com">item1</td></tr></table>');
8
+ $('body').append(table);
9
+ });
10
+
11
+ afterEach(function(){
12
+ table.remove();
13
+ });
14
+
15
+ it('should navigate to link location', function(){
16
+ spyOn(window.digitalOpera.forTestingPurposes, 'getWindowLocation');
17
+ table.find('tr:first').click();
18
+ expect(window.digitalOpera.forTestingPurposes.getWindowLocation).toHaveBeenCalled();
19
+ });
20
+
21
+ it('should open new window if has data-does="open-window"', function(){
22
+ spyOn(window, 'open').andReturn(focusObject);
23
+ table.find('tr:first').attr('data-does', 'open-window');
24
+ table.find('tr:first').click();
25
+ expect(window.open).toHaveBeenCalled();
26
+ });
27
+
28
+ it('should not follow link if click is within the anchor', function(){
29
+ var anchor = $('<a href="http://bing.com">my link</a>')
30
+ table.find('tr:first td:first').append(anchor);
31
+ spyOn(window, 'open').andReturn(focusObject);
32
+ spyOn(window.digitalOpera.forTestingPurposes, 'getWindowLocation');
33
+ anchor.click();
34
+ expect(window.open).not.toHaveBeenCalled();
35
+ expect(window.digitalOpera.forTestingPurposes.getWindowLocation).not.toHaveBeenCalled();
36
+ });
37
+
38
+ it('should not follow link if click is within a span within the anchor', function(){
39
+ var anchor = $('<a href="http://bing.com"><span>my link</span></a>')
40
+ table.find('tr:first td:first').append(anchor);
41
+ spyOn(window, 'open').andReturn(focusObject);
42
+ spyOn(window.digitalOpera.forTestingPurposes, 'getWindowLocation');
43
+ anchor.find('span').click();
44
+ expect(window.open).not.toHaveBeenCalled();
45
+ expect(window.digitalOpera.forTestingPurposes.getWindowLocation).not.toHaveBeenCalled();
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,149 @@
1
+ // Generated by CoffeeScript 1.6.3
2
+ window.digitalOpera = window.digitalOpera || {};
3
+
4
+ (function(d) {
5
+ return d.ellipsis = function(el) {
6
+ var counter, ele, timer;
7
+ ele = $(el);
8
+ counter = 0;
9
+ return timer = setInterval(function() {
10
+ var arr, num;
11
+ counter++;
12
+ if (counter > 3) {
13
+ counter = 0;
14
+ }
15
+ num = 0;
16
+ arr = [];
17
+ while (num < counter) {
18
+ num++;
19
+ arr.push('.');
20
+ }
21
+ return ele.text(arr.join(''));
22
+ }, 750);
23
+ };
24
+ })(window.digitalOpera);
25
+
26
+ $('[data-does="animate-ellipsis"]').each(function(idx, ele) {
27
+ return window.digitalOpera(ele);
28
+ });
29
+
30
+ (function(d) {
31
+ return d.isClickOutsideElement = function(event, element) {
32
+ var target;
33
+ target = $(event.target);
34
+ if (target[0] === element[0] || element.children(target).length > 0) {
35
+ return false;
36
+ } else {
37
+ return true;
38
+ }
39
+ };
40
+ })(window.digitalOpera);
41
+
42
+ (function(d) {
43
+ return d.parameterizeObject = function(data) {
44
+ var accLoop, key, obj, val;
45
+ obj = {};
46
+ accLoop = function(key, val) {
47
+ var k, v;
48
+ if ($.isPlainObject(val)) {
49
+ for (k in val) {
50
+ v = val[k];
51
+ k = "" + key + "[" + k + "]";
52
+ accLoop(k, v);
53
+ }
54
+ } else {
55
+ obj[key] = val;
56
+ }
57
+ };
58
+ for (key in data) {
59
+ val = data[key];
60
+ accLoop(key, val);
61
+ }
62
+ return obj;
63
+ };
64
+ })(window.digitalOpera);
65
+
66
+ (function(d) {
67
+ return d.preloadImages = function(urls, callback) {
68
+ var images, increment, numLoaded;
69
+ if (typeof urls === 'string') {
70
+ urls = [urls];
71
+ }
72
+ images = [];
73
+ numLoaded = 0;
74
+ increment = function() {
75
+ numLoaded++;
76
+ if ((callback != null) && numLoaded === urls.length) {
77
+ return callback();
78
+ }
79
+ };
80
+ return urls.map(function(url, i) {
81
+ var img;
82
+ img = images[i];
83
+ img = new Image();
84
+ img.onload = increment;
85
+ img.onerror = increment;
86
+ img.src = url;
87
+ return img;
88
+ });
89
+ };
90
+ })(window.digitalOpera);
91
+
92
+ (function(d) {
93
+ d.capitalize = function(str) {
94
+ return str.charAt(0).toUpperCase() + str.slice(1);
95
+ };
96
+ d.titleize = function(str) {
97
+ var arr, newString, string, _i, _len;
98
+ arr = str.split(' ');
99
+ newString = '';
100
+ for (_i = 0, _len = arr.length; _i < _len; _i++) {
101
+ string = arr[_i];
102
+ arr[_i] = string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
103
+ }
104
+ return arr.join(' ');
105
+ };
106
+ return d.formatJSONErrors = function(str, withKeys) {
107
+ var errors;
108
+ errors = typeof str === 'string' ? JSON.parse(str) : str;
109
+ return $.map(errors, function(val, key) {
110
+ var obj, values;
111
+ values = val.join(' and ');
112
+ str = d.capitalize("" + key + " " + values);
113
+ if (withKeys != null) {
114
+ obj = {};
115
+ obj[key] = str;
116
+ return obj;
117
+ } else {
118
+ return str;
119
+ }
120
+ });
121
+ };
122
+ })(window.digitalOpera);
123
+
124
+ (function(d) {
125
+ $(document).on('click', 'tr[data-href]', function(e) {
126
+ var currentTarget, href, location, target, win;
127
+ target = $(e.target);
128
+ currentTarget = $(e.currentTarget);
129
+ if (target.is('a') === false && target.parents('a').length === 0) {
130
+ href = currentTarget.attr('data-href');
131
+ if (currentTarget.attr('data-does') === 'open-window') {
132
+ win = window.open(href, '_blank');
133
+ return win.focus();
134
+ } else {
135
+ location = d.forTestingPurposes.getWindowLocation();
136
+ return location = href;
137
+ }
138
+ }
139
+ });
140
+ return d.forTestingPurposes = (function() {
141
+ var getWindowLocation;
142
+ getWindowLocation = function() {
143
+ return window.location;
144
+ };
145
+ return {
146
+ getWindowLocation: getWindowLocation
147
+ };
148
+ })();
149
+ })(window.digitalOpera);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digital_opera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-20 00:00:00.000000000 Z
13
+ date: 2013-11-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: activesupport
16
+ name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
@@ -131,6 +131,14 @@ executables: []
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
+ - app/assets/javascripts/digital_opera/digital_opera.js
135
+ - app/assets/javascripts/digital_opera/digital_opera_namespace.js.coffee
136
+ - app/assets/javascripts/digital_opera/ellipsis.js.coffee
137
+ - app/assets/javascripts/digital_opera/events.js.coffee
138
+ - app/assets/javascripts/digital_opera/forms.js.coffee
139
+ - app/assets/javascripts/digital_opera/preload_images.js.coffee
140
+ - app/assets/javascripts/digital_opera/strings.js.coffee
141
+ - app/assets/javascripts/digital_opera/tables.js.coffee
134
142
  - lib/digital_opera/banker.rb
135
143
  - lib/digital_opera/base_extensions/object.rb
136
144
  - lib/digital_opera/presenter/base.rb
@@ -141,6 +149,20 @@ files:
141
149
  - Rakefile
142
150
  - spec/banker_spec.rb
143
151
  - spec/base_extensions/object_spec.rb
152
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine-html.js
153
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine.css
154
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine.js
155
+ - spec/javascripts/lib/jasmine-1.3.1/MIT.LICENSE
156
+ - spec/javascripts/spec/digital_opera_namespace_spec.js
157
+ - spec/javascripts/spec/ellipsis_spec.js
158
+ - spec/javascripts/spec/events_spec.js
159
+ - spec/javascripts/spec/forms_spec.js
160
+ - spec/javascripts/spec/preload_images_spec.js
161
+ - spec/javascripts/spec/SpecHelper.js
162
+ - spec/javascripts/spec/strings_spec.js
163
+ - spec/javascripts/spec/tables_spec.js
164
+ - spec/javascripts/SpecRunner.html
165
+ - spec/javascripts/src/digital_opera.js
144
166
  - spec/presenter/base_spec.rb
145
167
  - spec/spec_helper.rb
146
168
  - spec/support/base_presenter.rb
@@ -161,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
183
  version: '0'
162
184
  segments:
163
185
  - 0
164
- hash: 1294121815354848515
186
+ hash: 2783149347697451677
165
187
  required_rubygems_version: !ruby/object:Gem::Requirement
166
188
  none: false
167
189
  requirements:
@@ -170,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
192
  version: '0'
171
193
  segments:
172
194
  - 0
173
- hash: 1294121815354848515
195
+ hash: 2783149347697451677
174
196
  requirements: []
175
197
  rubyforge_project:
176
198
  rubygems_version: 1.8.23
@@ -180,6 +202,20 @@ summary: Tools and utilities for helping out in developing Ruby applications
180
202
  test_files:
181
203
  - spec/banker_spec.rb
182
204
  - spec/base_extensions/object_spec.rb
205
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine-html.js
206
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine.css
207
+ - spec/javascripts/lib/jasmine-1.3.1/jasmine.js
208
+ - spec/javascripts/lib/jasmine-1.3.1/MIT.LICENSE
209
+ - spec/javascripts/spec/digital_opera_namespace_spec.js
210
+ - spec/javascripts/spec/ellipsis_spec.js
211
+ - spec/javascripts/spec/events_spec.js
212
+ - spec/javascripts/spec/forms_spec.js
213
+ - spec/javascripts/spec/preload_images_spec.js
214
+ - spec/javascripts/spec/SpecHelper.js
215
+ - spec/javascripts/spec/strings_spec.js
216
+ - spec/javascripts/spec/tables_spec.js
217
+ - spec/javascripts/SpecRunner.html
218
+ - spec/javascripts/src/digital_opera.js
183
219
  - spec/presenter/base_spec.rb
184
220
  - spec/spec_helper.rb
185
221
  - spec/support/base_presenter.rb