semantic-ui-sass 0.19.3.1 → 1.7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +5 -6
  4. data/app/assets/fonts/semantic-ui/icons.eot +0 -0
  5. data/app/assets/fonts/semantic-ui/icons.otf +0 -0
  6. data/app/assets/fonts/semantic-ui/icons.svg +472 -367
  7. data/app/assets/fonts/semantic-ui/icons.ttf +0 -0
  8. data/app/assets/fonts/semantic-ui/icons.woff +0 -0
  9. data/app/assets/images/semantic-ui/flags.png +0 -0
  10. data/app/assets/javascripts/semantic-ui.js +9 -5
  11. data/app/assets/javascripts/semantic-ui/accordion.js +169 -102
  12. data/app/assets/javascripts/semantic-ui/api.js +840 -0
  13. data/app/assets/javascripts/semantic-ui/checkbox.js +203 -46
  14. data/app/assets/javascripts/semantic-ui/{behavior/colorize.js → colorize.js} +4 -2
  15. data/app/assets/javascripts/semantic-ui/dimmer.js +110 -76
  16. data/app/assets/javascripts/semantic-ui/dropdown.js +897 -285
  17. data/app/assets/javascripts/semantic-ui/{behavior/form.js → form.js} +127 -42
  18. data/app/assets/javascripts/semantic-ui/modal.js +294 -219
  19. data/app/assets/javascripts/semantic-ui/nag.js +120 -186
  20. data/app/assets/javascripts/semantic-ui/popup.js +491 -223
  21. data/app/assets/javascripts/semantic-ui/progress.js +779 -0
  22. data/app/assets/javascripts/semantic-ui/rating.js +66 -22
  23. data/app/assets/javascripts/semantic-ui/search.js +219 -99
  24. data/app/assets/javascripts/semantic-ui/shape.js +72 -29
  25. data/app/assets/javascripts/semantic-ui/sidebar.js +678 -142
  26. data/app/assets/javascripts/semantic-ui/site.js +487 -0
  27. data/app/assets/javascripts/semantic-ui/{behavior/state.js → state.js} +116 -151
  28. data/app/assets/javascripts/semantic-ui/sticky.js +771 -0
  29. data/app/assets/javascripts/semantic-ui/tab.js +680 -603
  30. data/app/assets/javascripts/semantic-ui/transition.js +269 -158
  31. data/app/assets/javascripts/semantic-ui/video.js +113 -32
  32. data/app/assets/javascripts/semantic-ui/visibility.js +970 -0
  33. data/app/assets/javascripts/semantic-ui/visit.js +513 -0
  34. data/app/assets/stylesheets/semantic-ui.scss +2 -0
  35. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +58 -14
  36. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +464 -372
  37. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +1385 -533
  38. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +482 -655
  39. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +238 -139
  40. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +631 -280
  41. data/app/assets/stylesheets/semantic-ui/elements/_all.scss +3 -2
  42. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +1614 -657
  43. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +143 -80
  44. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +1018 -0
  45. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +302 -145
  46. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +1653 -1365
  47. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +160 -59
  48. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +247 -118
  49. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +501 -470
  50. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +888 -0
  51. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +189 -98
  52. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +125 -0
  53. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +147 -212
  54. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +328 -190
  55. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +261 -185
  56. data/app/assets/stylesheets/semantic-ui/globals/_all.scss +2 -0
  57. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +430 -0
  58. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +128 -0
  59. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +190 -106
  60. data/app/assets/stylesheets/semantic-ui/modules/_all.scss +2 -1
  61. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +303 -201
  62. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +72 -63
  63. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +711 -331
  64. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +262 -140
  65. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +82 -71
  66. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +163 -119
  67. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +435 -0
  68. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +163 -68
  69. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +223 -150
  70. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +39 -40
  71. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +413 -147
  72. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +80 -0
  73. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +49 -20
  74. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +542 -568
  75. data/app/assets/stylesheets/semantic-ui/modules/_video.scss +69 -37
  76. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +265 -0
  77. data/app/assets/stylesheets/semantic-ui/views/_all.scss +1 -1
  78. data/app/assets/stylesheets/semantic-ui/views/_card.scss +758 -0
  79. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +133 -92
  80. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +200 -87
  81. data/app/assets/stylesheets/semantic-ui/views/_item.scss +298 -523
  82. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +390 -12
  83. data/lib/semantic/ui/sass/version.rb +2 -2
  84. data/tasks/converter.rb +99 -216
  85. metadata +22 -27
  86. data/app/assets/fonts/semantic-ui/basic.icons.eot +0 -0
  87. data/app/assets/fonts/semantic-ui/basic.icons.svg +0 -450
  88. data/app/assets/fonts/semantic-ui/basic.icons.ttf +0 -0
  89. data/app/assets/fonts/semantic-ui/basic.icons.woff +0 -0
  90. data/app/assets/images/semantic-ui/loader-large-inverted.gif +0 -0
  91. data/app/assets/images/semantic-ui/loader-large.gif +0 -0
  92. data/app/assets/images/semantic-ui/loader-medium-inverted.gif +0 -0
  93. data/app/assets/images/semantic-ui/loader-medium.gif +0 -0
  94. data/app/assets/images/semantic-ui/loader-mini-inverted.gif +0 -0
  95. data/app/assets/images/semantic-ui/loader-mini.gif +0 -0
  96. data/app/assets/images/semantic-ui/loader-small-inverted.gif +0 -0
  97. data/app/assets/images/semantic-ui/loader-small.gif +0 -0
  98. data/app/assets/javascripts/semantic-ui/behavior/api.js +0 -634
  99. data/app/assets/javascripts/semantic-ui/chatroom.js +0 -772
  100. data/app/assets/stylesheets/semantic-ui/depends/_basic.icon.scss +0 -4
  101. data/app/assets/stylesheets/semantic-ui/depends/_icon.scss +0 -4
  102. data/app/assets/stylesheets/semantic-ui/depends/_loader.scss +0 -8
  103. data/app/assets/stylesheets/semantic-ui/elements/_basic.icon.scss +0 -1124
  104. data/app/assets/stylesheets/semantic-ui/elements/_progress.scss +0 -280
  105. data/app/assets/stylesheets/semantic-ui/modules/_chatroom.scss +0 -299
  106. data/app/assets/stylesheets/semantic-ui/modules/_reveal.scss +0 -322
  107. data/app/assets/stylesheets/semantic-ui/views/_list.scss +0 -700
@@ -1,15 +1,18 @@
1
- /* ******************************
2
- Module - Video
3
- Author: Jack Lukic
4
-
5
- This is a video playlist and video embed plugin which helps
6
- provide helpers for adding embed code for vimeo and youtube and
7
- abstracting event handlers for each library
8
-
9
- ****************************** */
1
+ /*
2
+ * # Semantic - Video
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Copyright 2014 Contributors
7
+ * Released under the MIT license
8
+ * http://opensource.org/licenses/MIT
9
+ *
10
+ */
10
11
 
11
12
  ;(function ($, window, document, undefined) {
12
13
 
14
+ "use strict";
15
+
13
16
  $.fn.video = function(parameters) {
14
17
 
15
18
  var
@@ -24,6 +27,12 @@ $.fn.video = function(parameters) {
24
27
  methodInvoked = (typeof query == 'string'),
25
28
  queryArguments = [].slice.call(arguments, 1),
26
29
 
30
+ requestAnimationFrame = window.requestAnimationFrame
31
+ || window.mozRequestAnimationFrame
32
+ || window.webkitRequestAnimationFrame
33
+ || window.msRequestAnimationFrame
34
+ || function(callback) { setTimeout(callback, 0); },
35
+
27
36
  returnedValue
28
37
  ;
29
38
 
@@ -39,10 +48,12 @@ $.fn.video = function(parameters) {
39
48
  error = settings.error,
40
49
  metadata = settings.metadata,
41
50
  namespace = settings.namespace,
51
+ templates = settings.templates,
42
52
 
43
53
  eventNamespace = '.' + namespace,
44
54
  moduleNamespace = 'module-' + namespace,
45
55
 
56
+ $window = $(window),
46
57
  $module = $(this),
47
58
  $placeholder = $module.find(selector.placeholder),
48
59
  $playButton = $module.find(selector.playButton),
@@ -57,6 +68,7 @@ $.fn.video = function(parameters) {
57
68
 
58
69
  initialize: function() {
59
70
  module.debug('Initializing video');
71
+ module.create();
60
72
  $placeholder
61
73
  .on('click' + eventNamespace, module.play)
62
74
  ;
@@ -74,8 +86,22 @@ $.fn.video = function(parameters) {
74
86
  ;
75
87
  },
76
88
 
89
+ create: function() {
90
+ var
91
+ image = $module.data(metadata.image),
92
+ html = templates.video(image)
93
+ ;
94
+ $module.html(html);
95
+ module.refresh();
96
+ if(!image) {
97
+ module.play();
98
+ }
99
+ module.debug('Creating html for video element', html);
100
+ },
101
+
77
102
  destroy: function() {
78
103
  module.verbose('Destroying previous instance of video');
104
+ module.reset();
79
105
  $module
80
106
  .removeData(moduleNamespace)
81
107
  .off(eventNamespace)
@@ -88,6 +114,13 @@ $.fn.video = function(parameters) {
88
114
  ;
89
115
  },
90
116
 
117
+ refresh: function() {
118
+ module.verbose('Refreshing selector cache');
119
+ $placeholder = $module.find(selector.placeholder);
120
+ $playButton = $module.find(selector.playButton);
121
+ $embed = $module.find(selector.embed);
122
+ },
123
+
91
124
  // sets new video
92
125
  change: function(source, id, url) {
93
126
  module.debug('Changing video to ', source, id, url);
@@ -131,42 +164,60 @@ $.fn.video = function(parameters) {
131
164
  settings.onPlay();
132
165
  },
133
166
 
167
+ get: {
168
+ source: function(url) {
169
+ if(typeof url !== 'string') {
170
+ return false;
171
+ }
172
+ if(url.search('youtube.com') !== -1) {
173
+ return 'youtube';
174
+ }
175
+ else if(url.search('vimeo.com') !== -1) {
176
+ return 'vimeo';
177
+ }
178
+ return false;
179
+ },
180
+ id: function(url) {
181
+ if(url.match(settings.regExp.youtube)) {
182
+ return url.match(settings.regExp.youtube)[1];
183
+ }
184
+ else if(url.match(settings.regExp.vimeo)) {
185
+ return url.match(settings.regExp.vimeo)[2];
186
+ }
187
+ return false;
188
+ }
189
+ },
190
+
134
191
  generate: {
135
192
  // generates iframe html
136
193
  html: function(source, id, url) {
137
194
  module.debug('Generating embed html');
138
195
  var
139
- width = (settings.width == 'auto')
140
- ? $module.width()
141
- : settings.width,
142
- height = (settings.height == 'auto')
143
- ? $module.height()
144
- : settings.height,
145
196
  html
146
197
  ;
147
- if(source && id) {
198
+ // allow override of settings
199
+ source = source || settings.source;
200
+ id = id || settings.id;
201
+ if((source && id) || url) {
202
+ if(!source || !id) {
203
+ source = module.get.source(url);
204
+ id = module.get.id(url);
205
+ }
148
206
  if(source == 'vimeo') {
149
207
  html = ''
150
208
  + '<iframe src="http://player.vimeo.com/video/' + id + '?=' + module.generate.url(source) + '"'
151
- + ' width="' + width + '" height="' + height + '"'
209
+ + ' width="100%" height="100%"'
152
210
  + ' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
153
211
  ;
154
212
  }
155
213
  else if(source == 'youtube') {
156
214
  html = ''
157
215
  + '<iframe src="http://www.youtube.com/embed/' + id + '?=' + module.generate.url(source) + '"'
158
- + ' width="' + width + '" height="' + height + '"'
216
+ + ' width="100%" height="100%"'
159
217
  + ' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
160
218
  ;
161
219
  }
162
220
  }
163
- else if(url) {
164
- html = ''
165
- + '<iframe src="' + url + '"'
166
- + ' width="' + width + '" height="' + height + '"'
167
- + ' frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'
168
- ;
169
- }
170
221
  else {
171
222
  module.error(error.noVideo);
172
223
  }
@@ -179,9 +230,9 @@ $.fn.video = function(parameters) {
179
230
  api = (settings.api)
180
231
  ? 1
181
232
  : 0,
182
- autoplay = (settings.autoplay)
183
- ? 1
184
- : 0,
233
+ autoplay = (settings.autoplay === 'auto')
234
+ ? ($module.data('image') !== undefined)
235
+ : settings.autoplay,
185
236
  hd = (settings.hd)
186
237
  ? 1
187
238
  : 0,
@@ -216,7 +267,7 @@ $.fn.video = function(parameters) {
216
267
  }
217
268
  else if(source == 'youtube') {
218
269
  url = ''
219
- + 'enablejsapi=' + api
270
+ + 'enablejsapi=' + api
220
271
  + '&amp;autoplay=' + autoplay
221
272
  + '&amp;autohide=' + hideUI
222
273
  + '&amp;hq=' + hd
@@ -231,6 +282,7 @@ $.fn.video = function(parameters) {
231
282
  },
232
283
 
233
284
  setting: function(name, value) {
285
+ module.debug('Changing setting', name, value);
234
286
  if( $.isPlainObject(name) ) {
235
287
  $.extend(true, settings, name);
236
288
  }
@@ -291,9 +343,9 @@ $.fn.video = function(parameters) {
291
343
  executionTime = currentTime - previousTime;
292
344
  time = currentTime;
293
345
  performance.push({
294
- 'Element' : element,
295
346
  'Name' : message[0],
296
347
  'Arguments' : [].slice.call(message, 1) || '',
348
+ 'Element' : element,
297
349
  'Execution Time' : executionTime
298
350
  });
299
351
  }
@@ -364,6 +416,7 @@ $.fn.video = function(parameters) {
364
416
  return false;
365
417
  }
366
418
  else {
419
+ module.error(error.method, query);
367
420
  return false;
368
421
  }
369
422
  });
@@ -417,11 +470,18 @@ $.fn.video.settings = {
417
470
  performance : true,
418
471
 
419
472
  metadata : {
420
- source : 'source',
421
473
  id : 'id',
474
+ image : 'image',
475
+ source : 'source',
422
476
  url : 'url'
423
477
  },
424
478
 
479
+ source : false,
480
+ url : false,
481
+ id : false,
482
+
483
+ aspectRatio : (16/9),
484
+
425
485
  onPlay : function(){},
426
486
  onReset : function(){},
427
487
  onChange : function(){},
@@ -433,12 +493,17 @@ $.fn.video.settings = {
433
493
  width : 'auto',
434
494
  height : 'auto',
435
495
 
436
- autoplay : false,
496
+ autoplay : 'auto',
437
497
  color : '#442359',
438
498
  hd : true,
439
499
  showUI : false,
440
500
  api : true,
441
501
 
502
+ regExp : {
503
+ youtube : /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/,
504
+ vimeo : /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/
505
+ },
506
+
442
507
  error : {
443
508
  noVideo : 'No video specified',
444
509
  method : 'The method you called is not defined'
@@ -455,5 +520,21 @@ $.fn.video.settings = {
455
520
  }
456
521
  };
457
522
 
523
+ $.fn.video.settings.templates = {
524
+ video: function(image) {
525
+ var
526
+ html = ''
527
+ ;
528
+ if(image) {
529
+ html += ''
530
+ + '<i class="video play icon"></i>'
531
+ + '<img class="placeholder" src="' + image + '">'
532
+ ;
533
+ }
534
+ html += '<div class="embed"></div>';
535
+ return html;
536
+ }
537
+ };
538
+
458
539
 
459
540
  })( jQuery, window , document );
@@ -0,0 +1,970 @@
1
+ /*
2
+ * # Semantic - Visibility
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Copyright 2014 Contributor
7
+ * Released under the MIT license
8
+ * http://opensource.org/licenses/MIT
9
+ *
10
+ */
11
+
12
+ ;(function ( $, window, document, undefined ) {
13
+
14
+ $.fn.visibility = function(parameters) {
15
+ var
16
+ $allModules = $(this),
17
+ moduleSelector = $allModules.selector || '',
18
+
19
+ time = new Date().getTime(),
20
+ performance = [],
21
+
22
+ query = arguments[0],
23
+ methodInvoked = (typeof query == 'string'),
24
+ queryArguments = [].slice.call(arguments, 1),
25
+ returnedValue
26
+ ;
27
+
28
+ $allModules
29
+ .each(function() {
30
+ var
31
+ settings = $.extend(true, {}, $.fn.visibility.settings, parameters),
32
+
33
+ className = settings.className,
34
+ namespace = settings.namespace,
35
+ error = settings.error,
36
+
37
+ eventNamespace = '.' + namespace,
38
+ moduleNamespace = 'module-' + namespace,
39
+
40
+ $window = $(window),
41
+ $module = $(this),
42
+ $context = $(settings.context),
43
+ $container = $module.offsetParent(),
44
+
45
+ selector = $module.selector || '',
46
+ instance = $module.data(moduleNamespace),
47
+
48
+ requestAnimationFrame = window.requestAnimationFrame
49
+ || window.mozRequestAnimationFrame
50
+ || window.webkitRequestAnimationFrame
51
+ || window.msRequestAnimationFrame
52
+ || function(callback) { setTimeout(callback, 0); },
53
+
54
+ element = this,
55
+ module
56
+ ;
57
+
58
+ module = {
59
+
60
+ initialize: function() {
61
+ module.verbose('Initializing visibility', settings);
62
+
63
+ module.setup.cache();
64
+ module.save.position();
65
+
66
+ if( module.should.trackChanges() ) {
67
+ module.bindEvents();
68
+ if(settings.type == 'image') {
69
+ module.setup.image();
70
+ }
71
+ if(settings.type == 'fixed') {
72
+ module.setup.fixed();
73
+ }
74
+ }
75
+ module.checkVisibility();
76
+ module.instantiate();
77
+ },
78
+
79
+ instantiate: function() {
80
+ module.verbose('Storing instance of module', module);
81
+ instance = module;
82
+ $module
83
+ .data(moduleNamespace, module)
84
+ ;
85
+ },
86
+
87
+ destroy: function() {
88
+ module.verbose('Destroying previous module');
89
+ $module
90
+ .off(eventNamespace)
91
+ .removeData(moduleNamespace)
92
+ ;
93
+ },
94
+
95
+ bindEvents: function() {
96
+ module.verbose('Binding visibility events to scroll and resize');
97
+ $window
98
+ .on('resize' + eventNamespace, module.event.refresh)
99
+ ;
100
+ $context
101
+ .on('scroll' + eventNamespace, module.event.scroll)
102
+ ;
103
+ },
104
+
105
+ event: {
106
+ refresh: function() {
107
+ requestAnimationFrame(module.refresh);
108
+ },
109
+ scroll: function() {
110
+ module.verbose('Scroll position changed');
111
+ if(settings.throttle) {
112
+ clearTimeout(module.timer);
113
+ module.timer = setTimeout(module.checkVisibility, settings.throttle);
114
+ }
115
+ else {
116
+ requestAnimationFrame(module.checkVisibility);
117
+ }
118
+ }
119
+ },
120
+
121
+ precache: function(images, callback) {
122
+ if (!(images instanceof Array)) {
123
+ images = [images];
124
+ }
125
+ var
126
+ imagesLength = images.length,
127
+ loadedCounter = 0,
128
+ cache = [],
129
+ cacheImage = document.createElement('img'),
130
+ handleLoad = function() {
131
+ loadedCounter++;
132
+ if (loadedCounter >= images.length) {
133
+ if ($.isFunction(callback)) {
134
+ callback();
135
+ }
136
+ }
137
+ }
138
+ ;
139
+ while (imagesLength--) {
140
+ cacheImage = document.createElement('img');
141
+ cacheImage.onload = handleLoad;
142
+ cacheImage.onerror = handleLoad;
143
+ cacheImage.src = images[imagesLength];
144
+ cache.push(cacheImage);
145
+ }
146
+ },
147
+
148
+ should: {
149
+
150
+ trackChanges: function() {
151
+ if(methodInvoked && queryArguments.length > 0) {
152
+ module.debug('One time query, no need to bind events');
153
+ return false;
154
+ }
155
+ module.debug('Query is attaching callbacks, watching for changes with scroll');
156
+ return true;
157
+ }
158
+
159
+ },
160
+
161
+ setup: {
162
+ cache: function() {
163
+ module.cache = {
164
+ occurred : {},
165
+ screen : {},
166
+ element : {},
167
+ };
168
+ },
169
+ image: function() {
170
+ var
171
+ src = $module.data('src')
172
+ ;
173
+ if(src) {
174
+ module.verbose('Lazy loading image', src);
175
+ // show when top visible
176
+ module.topVisible(function() {
177
+ module.precache(src, function() {
178
+ module.set.image(src);
179
+ settings.onTopVisible = false;
180
+ });
181
+ });
182
+ }
183
+ },
184
+ fixed: function() {
185
+ module.verbose('Setting up fixed on element pass');
186
+ $module
187
+ .visibility({
188
+ once: false,
189
+ continuous: false,
190
+ onTopPassed: function() {
191
+ $module
192
+ .addClass(className.fixed)
193
+ .css({
194
+ position: 'fixed',
195
+ top: settings.offset + 'px'
196
+ })
197
+ ;
198
+ if(settings.animation && $.fn.transition !== undefined) {
199
+ $module.transition(settings.transition, settings.duration);
200
+ }
201
+ },
202
+ onTopPassedReverse: function() {
203
+ $module
204
+ .removeClass(className.fixed)
205
+ .css({
206
+ position: '',
207
+ top: ''
208
+ })
209
+ ;
210
+ }
211
+ })
212
+ ;
213
+ }
214
+ },
215
+
216
+ set: {
217
+ image: function(src) {
218
+ var
219
+ offScreen = (module.cache.screen.bottom < module.cache.element.top)
220
+ ;
221
+ $module
222
+ .attr('src', src)
223
+ ;
224
+ if(offScreen) {
225
+ module.verbose('Image outside browser, no show animation');
226
+ $module.show();
227
+ }
228
+ else {
229
+ if(settings.transition && $.fn.transition !== undefined) {
230
+ $module.transition(settings.transition, settings.duration);
231
+ }
232
+ else {
233
+ $module.fadeIn(settings.duration);
234
+ }
235
+ }
236
+ }
237
+ },
238
+
239
+ refresh: function() {
240
+ module.debug('Refreshing constants (element width/height)');
241
+ module.reset();
242
+ module.save.position();
243
+ module.checkVisibility();
244
+ $.proxy(settings.onRefresh, element)();
245
+ },
246
+
247
+ reset: function() {
248
+ module.verbose('Reseting all cached values');
249
+ if( $.isPlainObject(module.cache) ) {
250
+ module.cache.screen = {};
251
+ module.cache.element = {};
252
+ }
253
+ },
254
+
255
+ checkVisibility: function() {
256
+ module.verbose('Checking visibility of element', module.cache.element);
257
+ module.save.calculations();
258
+
259
+ // percentage
260
+ module.passed();
261
+
262
+ // reverse (must be first)
263
+ module.passingReverse();
264
+ module.topVisibleReverse();
265
+ module.bottomVisibleReverse();
266
+ module.topPassedReverse();
267
+ module.bottomPassedReverse();
268
+
269
+ // one time
270
+ module.passing();
271
+ module.topVisible();
272
+ module.bottomVisible();
273
+ module.topPassed();
274
+ module.bottomPassed();
275
+ },
276
+
277
+ passed: function(amount, newCallback) {
278
+ var
279
+ calculations = module.get.elementCalculations(),
280
+ amountInPixels
281
+ ;
282
+ // assign callback
283
+ if(amount !== undefined && newCallback !== undefined) {
284
+ settings.onPassed[amount] = newCallback;
285
+ }
286
+ else if(amount !== undefined) {
287
+ return (module.get.pixelsPassed(amount) > calculations.pixelsPassed);
288
+ }
289
+ else if(calculations.passing) {
290
+ $.each(settings.onPassed, function(amount, callback) {
291
+ if(calculations.bottomVisible || calculations.pixelsPassed > module.get.pixelsPassed(amount)) {
292
+ module.execute(callback, amount);
293
+ }
294
+ else if(!settings.once) {
295
+ module.remove.occurred(callback);
296
+ }
297
+ });
298
+ }
299
+ },
300
+
301
+ passing: function(newCallback) {
302
+ var
303
+ calculations = module.get.elementCalculations(),
304
+ callback = newCallback || settings.onPassing,
305
+ callbackName = 'passing'
306
+ ;
307
+ if(newCallback) {
308
+ module.debug('Adding callback for passing', newCallback);
309
+ settings.onPassing = newCallback;
310
+ }
311
+ if(calculations.passing) {
312
+ module.execute(callback, callbackName);
313
+ }
314
+ else if(!settings.once) {
315
+ module.remove.occurred(callbackName);
316
+ }
317
+ if(newCallback !== undefined) {
318
+ return calculations.passing;
319
+ }
320
+ },
321
+
322
+
323
+ topVisible: function(newCallback) {
324
+ var
325
+ calculations = module.get.elementCalculations(),
326
+ callback = newCallback || settings.onTopVisible,
327
+ callbackName = 'topVisible'
328
+ ;
329
+ if(newCallback) {
330
+ module.debug('Adding callback for top visible', newCallback);
331
+ settings.onTopVisible = newCallback;
332
+ }
333
+ if(calculations.topVisible) {
334
+ module.execute(callback, callbackName);
335
+ }
336
+ else if(!settings.once) {
337
+ module.remove.occurred(callbackName);
338
+ }
339
+ if(newCallback === undefined) {
340
+ return calculations.topVisible;
341
+ }
342
+ },
343
+
344
+ bottomVisible: function(newCallback) {
345
+ var
346
+ calculations = module.get.elementCalculations(),
347
+ callback = newCallback || settings.onBottomVisible,
348
+ callbackName = 'bottomVisible'
349
+ ;
350
+ if(newCallback) {
351
+ module.debug('Adding callback for bottom visible', newCallback);
352
+ settings.onBottomVisible = newCallback;
353
+ }
354
+ if(calculations.bottomVisible) {
355
+ module.execute(callback, callbackName);
356
+ }
357
+ else if(!settings.once) {
358
+ module.remove.occurred(callbackName);
359
+ }
360
+ if(newCallback === undefined) {
361
+ return calculations.bottomVisible;
362
+ }
363
+ },
364
+
365
+ topPassed: function(newCallback) {
366
+ var
367
+ calculations = module.get.elementCalculations(),
368
+ callback = newCallback || settings.onTopPassed,
369
+ callbackName = 'topPassed'
370
+ ;
371
+ if(newCallback) {
372
+ module.debug('Adding callback for top passed', newCallback);
373
+ settings.onTopPassed = newCallback;
374
+ }
375
+ if(calculations.topPassed) {
376
+ module.execute(callback, callbackName);
377
+ }
378
+ else if(!settings.once) {
379
+ module.remove.occurred(callbackName);
380
+ }
381
+ if(newCallback === undefined) {
382
+ return calculations.topPassed;
383
+ }
384
+ },
385
+
386
+ bottomPassed: function(newCallback) {
387
+ var
388
+ calculations = module.get.elementCalculations(),
389
+ callback = newCallback || settings.onBottomPassed,
390
+ callbackName = 'bottomPassed'
391
+ ;
392
+ if(newCallback) {
393
+ module.debug('Adding callback for bottom passed', newCallback);
394
+ settings.onBottomPassed = newCallback;
395
+ }
396
+ if(calculations.bottomPassed) {
397
+ module.execute(callback, callbackName);
398
+ }
399
+ else if(!settings.once) {
400
+ module.remove.occurred(callbackName);
401
+ }
402
+ if(newCallback === undefined) {
403
+ return calculations.bottomPassed;
404
+ }
405
+ },
406
+
407
+ passingReverse: function(newCallback) {
408
+ var
409
+ calculations = module.get.elementCalculations(),
410
+ callback = newCallback || settings.onPassingReverse,
411
+ callbackName = 'passingReverse'
412
+ ;
413
+ if(newCallback) {
414
+ module.debug('Adding callback for passing reverse', newCallback);
415
+ settings.onPassingReverse = newCallback;
416
+ }
417
+ if(!calculations.passing) {
418
+ if(module.get.occurred('passing')) {
419
+ module.execute(callback, callbackName);
420
+ }
421
+ }
422
+ else if(!settings.once) {
423
+ module.remove.occurred(callbackName);
424
+ }
425
+ if(newCallback !== undefined) {
426
+ return !calculations.passing;
427
+ }
428
+ },
429
+
430
+
431
+ topVisibleReverse: function(newCallback) {
432
+ var
433
+ calculations = module.get.elementCalculations(),
434
+ callback = newCallback || settings.onTopVisibleReverse,
435
+ callbackName = 'topVisibleReverse'
436
+ ;
437
+ if(newCallback) {
438
+ module.debug('Adding callback for top visible reverse', newCallback);
439
+ settings.onTopVisibleReverse = newCallback;
440
+ }
441
+ if(!calculations.topVisible) {
442
+ if(module.get.occurred('topVisible')) {
443
+ module.execute(callback, callbackName);
444
+ }
445
+ }
446
+ else if(!settings.once) {
447
+ module.remove.occurred(callbackName);
448
+ }
449
+ if(newCallback === undefined) {
450
+ return !calculations.topVisible;
451
+ }
452
+ },
453
+
454
+ bottomVisibleReverse: function(newCallback) {
455
+ var
456
+ calculations = module.get.elementCalculations(),
457
+ callback = newCallback || settings.onBottomVisibleReverse,
458
+ callbackName = 'bottomVisibleReverse'
459
+ ;
460
+ if(newCallback) {
461
+ module.debug('Adding callback for bottom visible reverse', newCallback);
462
+ settings.onBottomVisibleReverse = newCallback;
463
+ }
464
+ if(!calculations.bottomVisible) {
465
+ if(module.get.occurred('bottomVisible')) {
466
+ module.execute(callback, callbackName);
467
+ }
468
+ }
469
+ else if(!settings.once) {
470
+ module.remove.occurred(callbackName);
471
+ }
472
+ if(newCallback === undefined) {
473
+ return !calculations.bottomVisible;
474
+ }
475
+ },
476
+
477
+ topPassedReverse: function(newCallback) {
478
+ var
479
+ calculations = module.get.elementCalculations(),
480
+ callback = newCallback || settings.onTopPassedReverse,
481
+ callbackName = 'topPassedReverse'
482
+ ;
483
+ if(newCallback) {
484
+ module.debug('Adding callback for top passed reverse', newCallback);
485
+ settings.onTopPassedReverse = newCallback;
486
+ }
487
+ if(!calculations.topPassed) {
488
+ if(module.get.occurred('topPassed')) {
489
+ module.execute(callback, callbackName);
490
+ }
491
+ }
492
+ else if(!settings.once) {
493
+ module.remove.occurred(callbackName);
494
+ }
495
+ if(newCallback === undefined) {
496
+ return !calculations.onTopPassed;
497
+ }
498
+ },
499
+
500
+ bottomPassedReverse: function(newCallback) {
501
+ var
502
+ calculations = module.get.elementCalculations(),
503
+ callback = newCallback || settings.onBottomPassedReverse,
504
+ callbackName = 'bottomPassedReverse'
505
+ ;
506
+ if(newCallback) {
507
+ module.debug('Adding callback for bottom passed reverse', newCallback);
508
+ settings.onBottomPassedReverse = newCallback;
509
+ }
510
+ if(!calculations.bottomPassed) {
511
+ if(module.get.occurred('bottomPassed')) {
512
+ module.execute(callback, callbackName);
513
+ }
514
+ }
515
+ else if(!settings.once) {
516
+ module.remove.occurred(callbackName);
517
+ }
518
+ if(newCallback === undefined) {
519
+ return !calculations.bottomPassed;
520
+ }
521
+ },
522
+
523
+ execute: function(callback, callbackName) {
524
+ var
525
+ calculations = module.get.elementCalculations(),
526
+ screen = module.get.screenCalculations()
527
+ ;
528
+ callback = callback || false;
529
+ if(callback) {
530
+ if(settings.continuous) {
531
+ module.debug('Callback being called continuously', callbackName, calculations);
532
+ $.proxy(callback, element)(calculations, screen);
533
+ }
534
+ else if(!module.get.occurred(callbackName)) {
535
+ module.debug('Conditions met', callbackName, calculations);
536
+ $.proxy(callback, element)(calculations, screen);
537
+ }
538
+ }
539
+ module.save.occurred(callbackName);
540
+ },
541
+
542
+ remove: {
543
+ occurred: function(callback) {
544
+ if(callback) {
545
+ if(module.cache.occurred[callback] !== undefined && module.cache.occurred[callback] === true) {
546
+ module.debug('Callback can now be called again', callback);
547
+ module.cache.occurred[callback] = false;
548
+ }
549
+ }
550
+ else {
551
+ module.cache.occurred = {};
552
+ }
553
+ }
554
+ },
555
+
556
+ save: {
557
+ calculations: function() {
558
+ module.verbose('Saving all calculations necessary to determine positioning');
559
+ module.save.scroll();
560
+ module.save.direction();
561
+ module.save.screenCalculations();
562
+ module.save.elementCalculations();
563
+ },
564
+ occurred: function(callback) {
565
+ if(callback) {
566
+ if(module.cache.occurred[callback] === undefined || (module.cache.occurred[callback] !== true)) {
567
+ module.verbose('Saving callback occurred', callback);
568
+ module.cache.occurred[callback] = true;
569
+ }
570
+ }
571
+ },
572
+ scroll: function() {
573
+ module.cache.scroll = $context.scrollTop() + settings.offset;
574
+ },
575
+ direction: function() {
576
+ var
577
+ scroll = module.get.scroll(),
578
+ lastScroll = module.get.lastScroll(),
579
+ direction
580
+ ;
581
+ if(scroll > lastScroll && lastScroll) {
582
+ direction = 'down';
583
+ }
584
+ else if(scroll < lastScroll && lastScroll) {
585
+ direction = 'up';
586
+ }
587
+ else {
588
+ direction = 'static';
589
+ }
590
+ module.cache.direction = direction;
591
+ return module.cache.direction;
592
+ },
593
+ elementPosition: function() {
594
+ var
595
+ screen = module.get.screenSize()
596
+ ;
597
+ module.verbose('Saving element position');
598
+ $.extend(module.cache.element, {
599
+ margin : {
600
+ top : parseInt($module.css('margin-top'), 10),
601
+ bottom : parseInt($module.css('margin-bottom'), 10)
602
+ },
603
+ fits : (element.height < screen.height),
604
+ offset : $module.offset(),
605
+ width : $module.outerWidth(),
606
+ height : $module.outerHeight()
607
+ });
608
+ return module.cache.element;
609
+ },
610
+ elementCalculations: function() {
611
+ var
612
+ screen = module.get.screenCalculations(),
613
+ element = module.get.elementPosition()
614
+ ;
615
+ // offset
616
+ if(settings.includeMargin) {
617
+ $.extend(module.cache.element, {
618
+ top : element.offset.top - element.margin.top,
619
+ bottom : element.offset.top + element.height + element.margin.bottom
620
+ });
621
+ }
622
+ else {
623
+ $.extend(module.cache.element, {
624
+ top : element.offset.top,
625
+ bottom : element.offset.top + element.height
626
+ });
627
+ }
628
+ // visibility
629
+ $.extend(module.cache.element, {
630
+ topVisible : (screen.bottom >= element.top),
631
+ topPassed : (screen.top >= element.top),
632
+ bottomVisible : (screen.bottom >= element.bottom),
633
+ bottomPassed : (screen.top >= element.bottom),
634
+ pixelsPassed : 0,
635
+ percentagePassed : 0
636
+ });
637
+ // meta calculations
638
+ $.extend(module.cache.element, {
639
+ visible : (module.cache.element.topVisible || module.cache.element.bottomVisible),
640
+ passing : (module.cache.element.topPassed && !module.cache.element.bottomPassed),
641
+ hidden : (!module.cache.element.topVisible && !module.cache.element.bottomVisible)
642
+ });
643
+ if(module.cache.element.passing) {
644
+ module.cache.element.pixelsPassed = (screen.top - element.top);
645
+ module.cache.element.percentagePassed = (screen.top - element.top) / element.height;
646
+ }
647
+ module.verbose('Updated element calculations', module.cache.element);
648
+ },
649
+ screenCalculations: function() {
650
+ var
651
+ scroll = $context.scrollTop() + settings.offset
652
+ ;
653
+ if(module.cache.scroll === undefined) {
654
+ module.cache.scroll = $context.scrollTop() + settings.offset;
655
+ }
656
+ module.save.direction();
657
+ $.extend(module.cache.screen, {
658
+ top : scroll,
659
+ bottom : scroll + module.cache.screen.height
660
+ });
661
+ return module.cache.screen;
662
+ },
663
+ screenSize: function() {
664
+ module.verbose('Saving window position');
665
+ module.cache.screen = {
666
+ height: $context.height()
667
+ };
668
+ },
669
+ position: function() {
670
+ module.save.screenSize();
671
+ module.save.elementPosition();
672
+ }
673
+ },
674
+
675
+ get: {
676
+ pixelsPassed: function(amount) {
677
+ var
678
+ element = module.get.elementCalculations()
679
+ ;
680
+ if(amount.search('%') > -1) {
681
+ return ( element.height * (parseInt(amount, 10) / 100) );
682
+ }
683
+ return parseInt(amount, 10);
684
+ },
685
+ occurred: function(callback) {
686
+ return (module.cache.occurred !== undefined)
687
+ ? module.cache.occurred[callback] || false
688
+ : false
689
+ ;
690
+ },
691
+ direction: function() {
692
+ if(module.cache.direction === undefined) {
693
+ module.save.direction();
694
+ }
695
+ return module.cache.direction;
696
+ },
697
+ elementPosition: function() {
698
+ if(module.cache.element === undefined) {
699
+ module.save.elementPosition();
700
+ }
701
+ return module.cache.element;
702
+ },
703
+ elementCalculations: function() {
704
+ if(module.cache.element === undefined) {
705
+ module.save.elementCalculations();
706
+ }
707
+ return module.cache.element;
708
+ },
709
+ screenCalculations: function() {
710
+ if(module.cache.screen === undefined) {
711
+ module.save.screenCalculations();
712
+ }
713
+ return module.cache.screen;
714
+ },
715
+ screenSize: function() {
716
+ if(module.cache.screen === undefined) {
717
+ module.save.screenSize();
718
+ }
719
+ return module.cache.screen;
720
+ },
721
+ scroll: function() {
722
+ if(module.cache.scroll === undefined) {
723
+ module.save.scroll();
724
+ }
725
+ return module.cache.scroll;
726
+ },
727
+ lastScroll: function() {
728
+ if(module.cache.screen === undefined) {
729
+ module.debug('First scroll event, no last scroll could be found');
730
+ return false;
731
+ }
732
+ return module.cache.screen.top;
733
+ }
734
+ },
735
+
736
+ setting: function(name, value) {
737
+ if( $.isPlainObject(name) ) {
738
+ $.extend(true, settings, name);
739
+ }
740
+ else if(value !== undefined) {
741
+ settings[name] = value;
742
+ }
743
+ else {
744
+ return settings[name];
745
+ }
746
+ },
747
+ internal: function(name, value) {
748
+ if( $.isPlainObject(name) ) {
749
+ $.extend(true, module, name);
750
+ }
751
+ else if(value !== undefined) {
752
+ module[name] = value;
753
+ }
754
+ else {
755
+ return module[name];
756
+ }
757
+ },
758
+ debug: function() {
759
+ if(settings.debug) {
760
+ if(settings.performance) {
761
+ module.performance.log(arguments);
762
+ }
763
+ else {
764
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
765
+ module.debug.apply(console, arguments);
766
+ }
767
+ }
768
+ },
769
+ verbose: function() {
770
+ if(settings.verbose && settings.debug) {
771
+ if(settings.performance) {
772
+ module.performance.log(arguments);
773
+ }
774
+ else {
775
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
776
+ module.verbose.apply(console, arguments);
777
+ }
778
+ }
779
+ },
780
+ error: function() {
781
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
782
+ module.error.apply(console, arguments);
783
+ },
784
+ performance: {
785
+ log: function(message) {
786
+ var
787
+ currentTime,
788
+ executionTime,
789
+ previousTime
790
+ ;
791
+ if(settings.performance) {
792
+ currentTime = new Date().getTime();
793
+ previousTime = time || currentTime;
794
+ executionTime = currentTime - previousTime;
795
+ time = currentTime;
796
+ performance.push({
797
+ 'Name' : message[0],
798
+ 'Arguments' : [].slice.call(message, 1) || '',
799
+ 'Element' : element,
800
+ 'Execution Time' : executionTime
801
+ });
802
+ }
803
+ clearTimeout(module.performance.timer);
804
+ module.performance.timer = setTimeout(module.performance.display, 100);
805
+ },
806
+ display: function() {
807
+ var
808
+ title = settings.name + ':',
809
+ totalTime = 0
810
+ ;
811
+ time = false;
812
+ clearTimeout(module.performance.timer);
813
+ $.each(performance, function(index, data) {
814
+ totalTime += data['Execution Time'];
815
+ });
816
+ title += ' ' + totalTime + 'ms';
817
+ if(moduleSelector) {
818
+ title += ' \'' + moduleSelector + '\'';
819
+ }
820
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
821
+ console.groupCollapsed(title);
822
+ if(console.table) {
823
+ console.table(performance);
824
+ }
825
+ else {
826
+ $.each(performance, function(index, data) {
827
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
828
+ });
829
+ }
830
+ console.groupEnd();
831
+ }
832
+ performance = [];
833
+ }
834
+ },
835
+ invoke: function(query, passedArguments, context) {
836
+ var
837
+ object = instance,
838
+ maxDepth,
839
+ found,
840
+ response
841
+ ;
842
+ passedArguments = passedArguments || queryArguments;
843
+ context = element || context;
844
+ if(typeof query == 'string' && object !== undefined) {
845
+ query = query.split(/[\. ]/);
846
+ maxDepth = query.length - 1;
847
+ $.each(query, function(depth, value) {
848
+ var camelCaseValue = (depth != maxDepth)
849
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
850
+ : query
851
+ ;
852
+ if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
853
+ object = object[camelCaseValue];
854
+ }
855
+ else if( object[camelCaseValue] !== undefined ) {
856
+ found = object[camelCaseValue];
857
+ return false;
858
+ }
859
+ else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
860
+ object = object[value];
861
+ }
862
+ else if( object[value] !== undefined ) {
863
+ found = object[value];
864
+ return false;
865
+ }
866
+ else {
867
+ module.error(error.method, query);
868
+ return false;
869
+ }
870
+ });
871
+ }
872
+ if ( $.isFunction( found ) ) {
873
+ response = found.apply(context, passedArguments);
874
+ }
875
+ else if(found !== undefined) {
876
+ response = found;
877
+ }
878
+ if($.isArray(returnedValue)) {
879
+ returnedValue.push(response);
880
+ }
881
+ else if(returnedValue !== undefined) {
882
+ returnedValue = [returnedValue, response];
883
+ }
884
+ else if(response !== undefined) {
885
+ returnedValue = response;
886
+ }
887
+ return found;
888
+ }
889
+ };
890
+
891
+ if(methodInvoked) {
892
+ if(instance === undefined) {
893
+ module.initialize();
894
+ }
895
+ module.invoke(query);
896
+ }
897
+ else {
898
+ if(instance !== undefined) {
899
+ module.destroy();
900
+ }
901
+ module.initialize();
902
+ }
903
+ })
904
+ ;
905
+
906
+ return (returnedValue !== undefined)
907
+ ? returnedValue
908
+ : this
909
+ ;
910
+ };
911
+
912
+ $.fn.visibility.settings = {
913
+
914
+ name : 'Visibility',
915
+ namespace : 'visibility',
916
+
917
+ className: {
918
+ fixed: 'fixed'
919
+ },
920
+
921
+ debug : false,
922
+ verbose : false,
923
+ performance : true,
924
+
925
+ offset : 0,
926
+ includeMargin : false,
927
+
928
+ context : window,
929
+
930
+ // visibility check delay in ms (defaults to animationFrame)
931
+ throttle : false,
932
+
933
+ // special visibility type (image, fixed)
934
+ type : false,
935
+
936
+ // image only animation settings
937
+ transition : false,
938
+ duration : 500,
939
+
940
+ // array of callbacks for percentage
941
+ onPassed : {},
942
+
943
+ // standard callbacks
944
+ onPassing : false,
945
+ onTopVisible : false,
946
+ onBottomVisible : false,
947
+ onTopPassed : false,
948
+ onBottomPassed : false,
949
+
950
+ // reverse callbacks
951
+ onPassingReverse : false,
952
+ onTopVisibleReverse : false,
953
+ onBottomVisibleReverse : false,
954
+ onTopPassedReverse : false,
955
+ onBottomPassedReverse : false,
956
+
957
+ once : true,
958
+ continuous : false,
959
+
960
+ // utility callbacks
961
+ onRefresh : function(){},
962
+ onScroll : function(){},
963
+
964
+ error : {
965
+ method : 'The method you called is not defined.'
966
+ }
967
+
968
+ };
969
+
970
+ })( jQuery, window , document );