tradewind 0.3 → 1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11c9d1926266fad520bfcc32ab90e5f63a74eb6c
4
- data.tar.gz: a91aabcfbfa396b53f905b9d58d6b54f38a44eb7
3
+ metadata.gz: eaef55f20c87352ebbe30abf6728e6233d375785
4
+ data.tar.gz: 93c55e7443c8453e4080ae45224d7fbb859a6ab1
5
5
  SHA512:
6
- metadata.gz: d7b55da37fe93b0057d5388ff1ccdc3c254d2779fc8cdb0a94daacb5afd4f081503a4fd16a0266419efa8d564e1556449a422bf66161346aef7c7141b87384f0
7
- data.tar.gz: bcfaad7be8d4a3936a8cf4ece85ced3fc2c64026d5f5fc9a1d23e69d9841d908c3a986d9655d47e38f6509ba5621749f6f1c4391026dbb748dced82094047a64
6
+ metadata.gz: fd266955c1372ed9bff726fb222bacdf9bedec96817fd6b4c1803b7625e17cda309b7c863136b05d483abc8897abd8301051606a30f5903490194ad07592c293
7
+ data.tar.gz: 4f8bee33bc2ee70f7fc95d6240b17b8cdaf9d094b5aae137333476e9122321de172eaa7fa648e49390778ab96ea5c47df6d241837c9796e20ea9f3220bb7909a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tradewind
2
2
 
3
- TODO: Write a gem description
3
+ Gem wrapper for [tradewind.js](https://github.com/adrdilauro/tradewind.js)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Check out [tradewind.js official documentation](https://github.com/adrdilauro/tradewind.js/wiki)
24
24
 
25
25
  ## Contributing
26
26
 
@@ -1,353 +1 @@
1
- (function () {
2
- "use strict";
3
-
4
- window.tradeWind = {
5
- padding: 100,
6
- property: {
7
- unspecified: "all",
8
- prefixes: [
9
- "-webkit-transition-property",
10
- "-moz-transition-property",
11
- "-o-transition-property",
12
- "transition-property"
13
- ]
14
- },
15
- duration: {
16
- unspecified: "0s",
17
- prefixes: [
18
- "-webkit-transition-duration",
19
- "-moz-transition-duration",
20
- "-o-transition-duration",
21
- "transition-duration"
22
- ]
23
- },
24
- easing: {
25
- unspecified: "ease",
26
- prefixes: [
27
- "-webkit-transition-timing-function",
28
- "-moz-transition-timing-function",
29
- "-o-transition-timing-function",
30
- "transition-timing-function"
31
- ]
32
- },
33
- delay: {
34
- unspecified: "0s",
35
- prefixes: [
36
- "-webkit-transition-delay",
37
- "-moz-transition-delay",
38
- "-o-transition-delay",
39
- "transition-delay"
40
- ]
41
- }
42
- };
43
-
44
- var temporary_animation, temporary_final, temporary_prestyles;
45
-
46
- function DoubleElementError (element) {
47
- this.message = "TradeWind - you inserted twice the same object in the instructions: " + element;
48
- };
49
- DoubleElementError.prototype = new Error;
50
-
51
- function EmptyArrayError (type) {
52
- this.message = "TradeWind - the array of " + type + " cannot be empty";
53
- };
54
- EmptyArrayError.prototype = new Error;
55
-
56
- function EmptySelectorError () {
57
- this.message = "TradeWind - the selector of animated elements cannot be empty";
58
- };
59
- EmptySelectorError.prototype = new Error;
60
-
61
- function MissingFieldError (type, field) {
62
- this.message = "TradeWind - " + type + " is missing the required field '" + field + "'";
63
- };
64
- MissingFieldError.prototype = new Error;
65
-
66
- function UndefinedAnimationsError () {
67
- this.message = "TradeWind - an instruction is missing array of animations";
68
- };
69
- UndefinedAnimationsError.prototype = new Error;
70
-
71
- function UndefinedError (type) {
72
- this.message = "TradeWind - Found an empty element in the array of " + type + "s, probably due to an unnecessary comma which is not accepted by IE";
73
- };
74
- UndefinedError.prototype = new Error;
75
-
76
- function UnexpectedObjectArrayError (type) {
77
- this.message = "TradeWind - expecting an array of " + type + ", got a different object";
78
- };
79
- UnexpectedObjectArrayError.prototype = new Error;
80
-
81
- function UnexpectedObjectSelectorError () {
82
- this.message = "TradeWind - expecting a selector of animated elements, got a different object";
83
- };
84
- UnexpectedObjectSelectorError.prototype = new Error;
85
-
86
- function UndefinedSelectorError () {
87
- this.message = "TradeWind - cannot parse an undefined selector of animated elements";
88
- };
89
- UndefinedSelectorError.prototype = new Error;
90
-
91
- function addNewElementToParsedInstructions (instructions, index, element) {
92
- for (var i = 0; i < instructions.length; i++) {
93
- if (instructions[i][0] === element) throw new DoubleElementError(stringifyElement(element));
94
- }
95
- instructions[index] = [element];
96
- };
97
-
98
- function applyAnimationCss (instructions) {
99
- var response = [];
100
- var counter = 0;
101
- for (var i = 0; i < instructions.length; i++) {
102
- for (var j = 0; j < 4; j++) {
103
- for (var k = 0; k < 4; k++) {
104
- applyCss(instructions[i][0], window.tradeWind[instructions[i][1][j][0]].prefixes[k], instructions[i][1][j][1]);
105
- }
106
- }
107
- response[counter] = [instructions[i][0], instructions[i][2]];
108
- counter += 1;
109
- }
110
- return response;
111
- };
112
-
113
- function applyCss (element, property, content) {
114
- element.style[property] = content;
115
- };
116
-
117
- function applyFinalCss (instructions) {
118
- for (var i = 0; i < instructions.length; i++) {
119
- for (var j = 0; j < instructions[i][1].length; j++) {
120
- applyCss(instructions[i][0], instructions[i][1][j][0], instructions[i][1][j][1]);
121
- }
122
- }
123
- };
124
-
125
- function applyPreStylingCss (instructions) {
126
- setNeutralAnimation(instructions);
127
- for (var i = 0; i < instructions.length; i++) {
128
- if (instructions[i][3]) {
129
- for (var j = 0; j < instructions[i][3].length; j++) {
130
- applyCss(instructions[i][0], instructions[i][3][j][0], instructions[i][3][j][1]);
131
- }
132
- }
133
- }
134
- };
135
-
136
- function applyUniformAnimationCss (instructions, css_applier) {
137
- var properties = ["property", "duration", "easing", "delay"];
138
- var current;
139
- for (var i = 0; i < instructions.length; i++) {
140
- for (var j = 0; j < 4; j++) {
141
- current = window.tradeWind[properties[j]];
142
- for (var k = 0; k < 4; k++) {
143
- applyCss(instructions[i][0], current.prefixes[k], css_applier(properties[j]));
144
- }
145
- }
146
- }
147
- };
148
-
149
- function checkIfPreliminaryStyles (instruction, locals) {
150
- if (instruction.preStyling) {
151
- // Exception for pre-styling
152
- handleExceptionForPreStyling(instruction.preStyling);
153
- /////////
154
- locals.preStyling = true;
155
- var resp = [];
156
- for (var i = 0; i < instruction.preStyling.length; i++) {
157
- // Exception for pre-style
158
- handleExceptionForUndefined(instruction.preStyling[i], "pre-style");
159
- handleExceptionForSinglePreStyle(instruction.preStyling[i]);
160
- /////////
161
- resp[i] = [instruction.preStyling[i].property, instruction.preStyling[i].value]
162
- }
163
- return resp;
164
- } else {
165
- return undefined;
166
- }
167
- };
168
-
169
- function compareAndUpdateTiming (duration, delay, locals) {
170
- var new_timing = (parseInt(parseFloat(duration) * 100) + parseInt(parseFloat(delay) * 100)) / 100;
171
- if (new_timing > locals.timing) locals.timing = new_timing;
172
- };
173
-
174
- function extractRule (property, rule) {
175
- if (!rule) {
176
- return window.tradeWind[property].unspecified;
177
- } else {
178
- return rule;
179
- }
180
- };
181
-
182
- function handleExceptionForAnimations (animations) {
183
- if (!animations) throw new UndefinedAnimationsError();
184
- if (!(animations instanceof Array)) throw new UnexpectedObjectArrayError("animations");
185
- if (animations.length === 0) throw new EmptyArrayError("animations");
186
- };
187
-
188
- function handleExceptionForNodeList (items) {
189
- if (items.length === 0) throw new EmptySelectorError();
190
- };
191
-
192
- function handleExceptionForPreStyling (prestyles) {
193
- if (!(prestyles instanceof Array)) throw new UnexpectedObjectArrayError("pre-styling");
194
- if (prestyles.length === 0) throw new EmptyArrayError("pre-styling");
195
- };
196
-
197
- function handleExceptionForSelector (selector) {
198
- if (!selector) throw new UndefinedSelectorError();
199
- if (!(typeof(selector) === "string" || (selector instanceof String))) throw new UnexpectedObjectSelectorError();
200
- };
201
-
202
- function handleExceptionForSingleAnimation (animation) {
203
- if (!animation.property) throw new MissingFieldError("animation", "property");
204
- if (!animation.final) throw new MissingFieldError("animation", "final");
205
- };
206
-
207
- function handleExceptionForSinglePreStyle (prestyle) {
208
- if (!prestyle.property) throw new MissingFieldError("pre-style", "property");
209
- if (!prestyle.value) throw new MissingFieldError("pre-style", "value");
210
- };
211
-
212
- function handleExceptionForUndefined (instruction, type) {
213
- if (!instruction) throw new UndefinedError(type);
214
- };
215
-
216
- function parseAnimation (animations, locals) {
217
- var parsed = [["property", ""], ["duration", ""], ["easing", ""], ["delay", ""]];
218
- for (var j = 0; j < animations.length; j++) {
219
- // Exception for animation
220
- handleExceptionForUndefined(animations[j], "animation");
221
- handleExceptionForSingleAnimation(animations[j]);
222
- /////////
223
- if (!animations[j].animationDetails) animations[j].animationDetails = {};
224
- parsed[0][1] += animations[j].property + ", ";
225
- parsed[1][1] += extractRule(
226
- "duration",
227
- animations[j].animationDetails.duration
228
- ) + ", ";
229
- parsed[2][1] += extractRule(
230
- "easing",
231
- animations[j].animationDetails.easing
232
- ) + ", ";
233
- parsed[3][1] += extractRule(
234
- "delay",
235
- animations[j].animationDetails.delay
236
- ) + ", ";
237
- compareAndUpdateTiming(
238
- extractRule("duration", animations[j].animationDetails.duration),
239
- extractRule("delay", animations[j].animationDetails.delay),
240
- locals
241
- );
242
- temporary_final.push([
243
- animations[j].property,
244
- animations[j].final
245
- ]);
246
- }
247
- parsed[0][1] = trimCss(parsed[0][1]);
248
- parsed[1][1] = trimCss(parsed[1][1]);
249
- parsed[2][1] = trimCss(parsed[2][1]);
250
- parsed[3][1] = trimCss(parsed[3][1]);
251
- temporary_animation = parsed;
252
- }
253
-
254
- function parseElement (element, instruction, response, index, locals) {
255
- addNewElementToParsedInstructions(response, index, element);
256
- if (!temporary_animation) {
257
- // Exception for animations
258
- handleExceptionForAnimations(instruction.animations);
259
- /////////
260
- temporary_final = [];
261
- temporary_prestyles = checkIfPreliminaryStyles(instruction, locals);
262
- parseAnimation(instruction.animations, locals);
263
- }
264
- response[index][1] = temporary_animation;
265
- response[index][2] = temporary_final;
266
- response[index][3] = temporary_prestyles;
267
- };
268
-
269
- function resetAnimation (instructions) {
270
- applyUniformAnimationCss(instructions, function (property) {
271
- return "";
272
- });
273
- };
274
-
275
- function setNeutralAnimation (instructions) {
276
- applyUniformAnimationCss(instructions, function (property) {
277
- return extractRule(property);
278
- });
279
- };
280
-
281
- function stringifyElement (element) {
282
- return "#" + element.id + "." + String(element.className).replace(" ", ".");
283
- };
284
-
285
- function trimCss (css) {
286
- if (css === "") return "";
287
- return css.substring(0, css.length - 2);
288
- };
289
-
290
- // Public function, initializes the variables
291
- window.tradeWind.initialize = function () {
292
- return {
293
- timing: 0,
294
- preStyling: false
295
- };
296
- };
297
-
298
- // PUblic method, parses the human-friendly instructions and converts them into an appliable array
299
- window.tradeWind.parse = function (instructions, locals) {
300
- var response = [], curr_index = 0;
301
- for (var i = 0; i < instructions.length; i++) {
302
- // Exception for instruction
303
- handleExceptionForUndefined(instructions[i], "instruction");
304
- /////////
305
- temporary_animation = undefined;
306
- temporary_final = undefined;
307
- temporary_prestyles = undefined;
308
- // Exception for selector
309
- handleExceptionForSelector(instructions[i].elements);
310
- /////////
311
- instructions[i].elements = document.querySelectorAll(instructions[i].elements);
312
- // Exception for elements
313
- handleExceptionForNodeList(instructions[i].elements);
314
- /////////
315
- for (var j = 0; j < instructions[i].elements.length; j++) {
316
- parseElement(instructions[i].elements[j], instructions[i], response, curr_index, locals);
317
- curr_index += 1;
318
- }
319
- }
320
- return response;
321
- };
322
-
323
- // Public method, applies the CSS; used differently in case of pre-styling
324
- window.tradeWind.apply = function (instructions, callback, locals) {
325
- var final_padding, new_vals = applyAnimationCss(instructions);
326
- applyFinalCss(new_vals);
327
- final_padding = locals.timing * 1000 + window.tradeWind.padding;
328
- if (window.Modernizr && !Modernizr.csstransitions) final_padding = window.tradeWind.padding;
329
- setTimeout(function () {
330
- resetAnimation(new_vals);
331
- if (callback !== undefined) callback();
332
- }, final_padding);
333
- };
334
-
335
- // Public method, runs the animation; for a sample of configuration see the spec
336
- window.tradeWind.run = function (instructions, callback) {
337
- var locals = window.tradeWind.initialize();
338
- var instructions = window.tradeWind.parse(instructions, locals);
339
- if (locals.preStyling) {
340
- applyPreStylingCss(instructions);
341
- setTimeout(function () {
342
- window.tradeWind.apply(instructions, callback, locals);
343
- }, window.tradeWind.padding);
344
- } else {
345
- window.tradeWind.apply(instructions, callback, locals);
346
- }
347
- };
348
-
349
- }());
350
-
351
- function alertHello () {
352
- alert("hello")
353
- }
1
+ !function(){"use strict";function n(n){this.message="TradeWind - you inserted twice the same object in the instructions: "+n}function i(n){this.message="TradeWind - the array of "+n+" cannot be empty"}function t(){this.message="TradeWind - the selector of animated elements cannot be empty"}function e(n,i){this.message="TradeWind - "+n+" is missing the required field '"+i+"'"}function r(){this.message="TradeWind - an instruction is missing array of animations"}function o(n){this.message="TradeWind - Found an empty element in the array of "+n+"s, probably due to an unnecessary comma which is not accepted by IE"}function a(n){this.message="TradeWind - expecting an array of "+n+", got a different object"}function s(){this.message="TradeWind - expecting a selector of animated elements, got a different object"}function d(){this.message="TradeWind - cannot parse an undefined selector of animated elements"}function f(i,t,e){for(var r=0;r<i.length;r++)if(i[r][0]===e)throw new n(j(e));i[t]=[e]}function p(n){for(var i=[],t=0,e=0;e<n.length;e++){for(var r=0;4>r;r++)for(var o=0;4>o;o++)u(n[e][0],window.tradeWind[n[e][1][r][0]].prefixes[o],n[e][1][r][1]);i[t]=[n[e][0],n[e][2]],t+=1}return i}function u(n,i,t){n.style[i]=t}function l(n){for(var i=0;i<n.length;i++)for(var t=0;t<n[i][1].length;t++)u(n[i][0],n[i][1][t][0],n[i][1][t][1])}function c(n){k(n);for(var i=0;i<n.length;i++)if(n[i][3])for(var t=0;t<n[i][3].length;t++)u(n[i][0],n[i][3][t][0],n[i][3][t][1])}function w(n,i){for(var t,e=["property","duration","easing","delay"],r=0;r<n.length;r++)for(var o=0;4>o;o++){t=window.tradeWind[e[o]];for(var a=0;4>a;a++)u(n[r][0],t.prefixes[a],i(e[o]))}}function y(n,i){if(n.preStyling){W(n.preStyling),i.preStyling=!0;for(var t=[],e=0;e<n.preStyling.length;e++)E(n.preStyling[e],"pre-style"),T(n.preStyling[e]),t[e]=[n.preStyling[e].property,n.preStyling[e].value];return t}return void 0}function g(n,i,t){var e=(parseInt(100*parseFloat(n))+parseInt(100*parseFloat(i)))/100;e>t.timing&&(t.timing=e)}function m(n,i){return i?i:window.tradeWind[n].unspecified}function h(n){if(!n)throw new r;if(!(n instanceof Array))throw new a("animations");if(0===n.length)throw new i("animations")}function v(n){if(0===n.length)throw new t}function W(n){if(!(n instanceof Array))throw new a("pre-styling");if(0===n.length)throw new i("pre-styling")}function b(n){if(!n)throw new d;if(!("string"==typeof n||n instanceof String))throw new s}function S(n){if(!n.property)throw new e("animation","property");if(!n["final"])throw new e("animation","final")}function T(n){if(!n.property)throw new e("pre-style","property");if(!n.value)throw new e("pre-style","value")}function E(n,i){if(!n)throw new o(i)}function x(n,i){for(var t=[["property",""],["duration",""],["easing",""],["delay",""]],e=0;e<n.length;e++)E(n[e],"animation"),S(n[e]),n[e].animationDetails||(n[e].animationDetails={}),t[0][1]+=n[e].property+", ",t[1][1]+=m("duration",n[e].animationDetails.duration)+", ",t[2][1]+=m("easing",n[e].animationDetails.easing)+", ",t[3][1]+=m("delay",n[e].animationDetails.delay)+", ",g(m("duration",n[e].animationDetails.duration),m("delay",n[e].animationDetails.delay),i),I.push([n[e].property,n[e]["final"]]);t[0][1]=A(t[0][1]),t[1][1]=A(t[1][1]),t[2][1]=A(t[2][1]),t[3][1]=A(t[3][1]),F=t}function z(n,i,t,e,r){f(t,e,n),F||(h(i.animations),I=[],q=y(i,r),x(i.animations,r)),t[e][1]=F,t[e][2]=I,t[e][3]=q}function D(n){w(n,function(){return""})}function k(n){w(n,function(n){return m(n)})}function j(n){return"#"+n.id+"."+String(n.className).replace(" ",".")}function A(n){return""===n?"":n.substring(0,n.length-2)}window.tradeWind={padding:100,property:{unspecified:"all",prefixes:["-webkit-transition-property","-moz-transition-property","-o-transition-property","transition-property"]},duration:{unspecified:"0s",prefixes:["-webkit-transition-duration","-moz-transition-duration","-o-transition-duration","transition-duration"]},easing:{unspecified:"ease",prefixes:["-webkit-transition-timing-function","-moz-transition-timing-function","-o-transition-timing-function","transition-timing-function"]},delay:{unspecified:"0s",prefixes:["-webkit-transition-delay","-moz-transition-delay","-o-transition-delay","transition-delay"]}};var F,I,q;n.prototype=new Error,i.prototype=new Error,t.prototype=new Error,e.prototype=new Error,r.prototype=new Error,o.prototype=new Error,a.prototype=new Error,s.prototype=new Error,d.prototype=new Error,window.tradeWind.initialize=function(){return{timing:0,preStyling:!1}},window.tradeWind.parse=function(n,i){for(var t=[],e=0,r=0;r<n.length;r++){E(n[r],"instruction"),F=void 0,I=void 0,q=void 0,b(n[r].elements),n[r].elements=document.querySelectorAll(n[r].elements),v(n[r].elements);for(var o=0;o<n[r].elements.length;o++)z(n[r].elements[o],n[r],t,e,i),e+=1}return t},window.tradeWind.apply=function(n,i,t){var e,r=p(n);l(r),e=1e3*t.timing+window.tradeWind.padding,window.Modernizr&&!Modernizr.csstransitions&&(e=window.tradeWind.padding),setTimeout(function(){D(r),void 0!==i&&i()},e)},window.tradeWind.run=function(n,i){var t=window.tradeWind.initialize(),n=window.tradeWind.parse(n,t);t.preStyling?(c(n),setTimeout(function(){window.tradeWind.apply(n,i,t)},window.tradeWind.padding)):window.tradeWind.apply(n,i,t)}}();
@@ -1,3 +1,3 @@
1
1
  module Tradewind
2
- VERSION = "0.3"
2
+ VERSION = "1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tradewind
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano di Lauro