vapid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (433) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.gitmodules +6 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +133 -0
  6. data/.travis.yml +5 -0
  7. data/Gemfile +10 -0
  8. data/README.md +37 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/vapid +7 -0
  13. data/lib/vapid.rb +24 -0
  14. data/lib/vapid/assets/javascripts/vapid/admin.coffee +2 -0
  15. data/lib/vapid/assets/stylesheets/vapid/admin.scss +72 -0
  16. data/lib/vapid/builder.rb +70 -0
  17. data/lib/vapid/cli.rb +96 -0
  18. data/lib/vapid/controllers/admin_controller.rb +282 -0
  19. data/lib/vapid/controllers/project_controller.rb +41 -0
  20. data/lib/vapid/db/migrate/20170202182310_create_groups.rb +12 -0
  21. data/lib/vapid/db/migrate/20170202183017_create_records.rb +11 -0
  22. data/lib/vapid/db/migrate/20170202185150_create_users.rb +11 -0
  23. data/lib/vapid/directive.rb +168 -0
  24. data/lib/vapid/directives.rb +30 -0
  25. data/lib/vapid/directives/audio.rb +27 -0
  26. data/lib/vapid/directives/group.rb +71 -0
  27. data/lib/vapid/directives/hide.rb +11 -0
  28. data/lib/vapid/directives/href.rb +11 -0
  29. data/lib/vapid/directives/image.rb +14 -0
  30. data/lib/vapid/directives/richtext.rb +15 -0
  31. data/lib/vapid/directives/show.rb +11 -0
  32. data/lib/vapid/directives/text.rb +24 -0
  33. data/lib/vapid/directives/video.rb +28 -0
  34. data/lib/vapid/generator_template/.gitignore +21 -0
  35. data/lib/vapid/generator_template/Gemfile.tt +13 -0
  36. data/lib/vapid/generator_template/README.md +0 -0
  37. data/lib/vapid/generator_template/assets/favicon.ico +0 -0
  38. data/lib/vapid/generator_template/assets/images/.keep +0 -0
  39. data/lib/vapid/generator_template/assets/javascripts/.keep +0 -0
  40. data/lib/vapid/generator_template/assets/stylesheets/.keep +0 -0
  41. data/lib/vapid/generator_template/assets/stylesheets/application.css +120 -0
  42. data/lib/vapid/generator_template/config.ru +3 -0
  43. data/lib/vapid/generator_template/config/database.yml +12 -0
  44. data/lib/vapid/generator_template/config/settings.yml.tt +11 -0
  45. data/lib/vapid/generator_template/templates/index.html.erb +25 -0
  46. data/lib/vapid/generator_template/templates/layouts/default.html.erb +22 -0
  47. data/lib/vapid/models.rb +18 -0
  48. data/lib/vapid/models/group.rb +36 -0
  49. data/lib/vapid/models/record.rb +30 -0
  50. data/lib/vapid/models/user.rb +16 -0
  51. data/lib/vapid/server.rb +93 -0
  52. data/lib/vapid/settings.rb +13 -0
  53. data/lib/vapid/template.rb +79 -0
  54. data/lib/vapid/template/node.rb +91 -0
  55. data/lib/vapid/template/parser.rb +50 -0
  56. data/lib/vapid/vendor/semantic-ui/.versions +4 -0
  57. data/lib/vapid/vendor/semantic-ui/LICENSE +22 -0
  58. data/lib/vapid/vendor/semantic-ui/README.md +7 -0
  59. data/lib/vapid/vendor/semantic-ui/components/accordion.css +252 -0
  60. data/lib/vapid/vendor/semantic-ui/components/accordion.js +610 -0
  61. data/lib/vapid/vendor/semantic-ui/components/accordion.min.css +9 -0
  62. data/lib/vapid/vendor/semantic-ui/components/accordion.min.js +10 -0
  63. data/lib/vapid/vendor/semantic-ui/components/ad.css +275 -0
  64. data/lib/vapid/vendor/semantic-ui/components/ad.min.css +10 -0
  65. data/lib/vapid/vendor/semantic-ui/components/api.js +1167 -0
  66. data/lib/vapid/vendor/semantic-ui/components/api.min.js +10 -0
  67. data/lib/vapid/vendor/semantic-ui/components/breadcrumb.css +124 -0
  68. data/lib/vapid/vendor/semantic-ui/components/breadcrumb.min.css +9 -0
  69. data/lib/vapid/vendor/semantic-ui/components/button.css +3450 -0
  70. data/lib/vapid/vendor/semantic-ui/components/button.min.css +9 -0
  71. data/lib/vapid/vendor/semantic-ui/components/card.css +964 -0
  72. data/lib/vapid/vendor/semantic-ui/components/card.min.css +9 -0
  73. data/lib/vapid/vendor/semantic-ui/components/checkbox.css +625 -0
  74. data/lib/vapid/vendor/semantic-ui/components/checkbox.js +831 -0
  75. data/lib/vapid/vendor/semantic-ui/components/checkbox.min.css +9 -0
  76. data/lib/vapid/vendor/semantic-ui/components/checkbox.min.js +10 -0
  77. data/lib/vapid/vendor/semantic-ui/components/colorize.js +274 -0
  78. data/lib/vapid/vendor/semantic-ui/components/colorize.min.js +11 -0
  79. data/lib/vapid/vendor/semantic-ui/components/comment.css +270 -0
  80. data/lib/vapid/vendor/semantic-ui/components/comment.min.css +9 -0
  81. data/lib/vapid/vendor/semantic-ui/components/container.css +147 -0
  82. data/lib/vapid/vendor/semantic-ui/components/container.min.css +9 -0
  83. data/lib/vapid/vendor/semantic-ui/components/dimmer.css +200 -0
  84. data/lib/vapid/vendor/semantic-ui/components/dimmer.js +708 -0
  85. data/lib/vapid/vendor/semantic-ui/components/dimmer.min.css +9 -0
  86. data/lib/vapid/vendor/semantic-ui/components/dimmer.min.js +10 -0
  87. data/lib/vapid/vendor/semantic-ui/components/divider.css +260 -0
  88. data/lib/vapid/vendor/semantic-ui/components/divider.min.css +9 -0
  89. data/lib/vapid/vendor/semantic-ui/components/dropdown.css +1442 -0
  90. data/lib/vapid/vendor/semantic-ui/components/dropdown.js +3767 -0
  91. data/lib/vapid/vendor/semantic-ui/components/dropdown.min.css +9 -0
  92. data/lib/vapid/vendor/semantic-ui/components/dropdown.min.js +11 -0
  93. data/lib/vapid/vendor/semantic-ui/components/embed.css +166 -0
  94. data/lib/vapid/vendor/semantic-ui/components/embed.js +696 -0
  95. data/lib/vapid/vendor/semantic-ui/components/embed.min.css +9 -0
  96. data/lib/vapid/vendor/semantic-ui/components/embed.min.js +10 -0
  97. data/lib/vapid/vendor/semantic-ui/components/feed.css +296 -0
  98. data/lib/vapid/vendor/semantic-ui/components/feed.min.css +9 -0
  99. data/lib/vapid/vendor/semantic-ui/components/flag.css +1031 -0
  100. data/lib/vapid/vendor/semantic-ui/components/flag.min.css +9 -0
  101. data/lib/vapid/vendor/semantic-ui/components/form.css +1067 -0
  102. data/lib/vapid/vendor/semantic-ui/components/form.js +1603 -0
  103. data/lib/vapid/vendor/semantic-ui/components/form.min.css +9 -0
  104. data/lib/vapid/vendor/semantic-ui/components/form.min.js +10 -0
  105. data/lib/vapid/vendor/semantic-ui/components/grid.css +2002 -0
  106. data/lib/vapid/vendor/semantic-ui/components/grid.min.css +9 -0
  107. data/lib/vapid/vendor/semantic-ui/components/header.css +721 -0
  108. data/lib/vapid/vendor/semantic-ui/components/header.min.css +9 -0
  109. data/lib/vapid/vendor/semantic-ui/components/icon.css +3292 -0
  110. data/lib/vapid/vendor/semantic-ui/components/icon.min.css +9 -0
  111. data/lib/vapid/vendor/semantic-ui/components/image.css +306 -0
  112. data/lib/vapid/vendor/semantic-ui/components/image.min.css +9 -0
  113. data/lib/vapid/vendor/semantic-ui/components/input.css +510 -0
  114. data/lib/vapid/vendor/semantic-ui/components/input.min.css +9 -0
  115. data/lib/vapid/vendor/semantic-ui/components/item.css +486 -0
  116. data/lib/vapid/vendor/semantic-ui/components/item.min.css +9 -0
  117. data/lib/vapid/vendor/semantic-ui/components/label.css +1307 -0
  118. data/lib/vapid/vendor/semantic-ui/components/label.min.css +9 -0
  119. data/lib/vapid/vendor/semantic-ui/components/list.css +951 -0
  120. data/lib/vapid/vendor/semantic-ui/components/list.min.css +9 -0
  121. data/lib/vapid/vendor/semantic-ui/components/loader.css +347 -0
  122. data/lib/vapid/vendor/semantic-ui/components/loader.min.css +9 -0
  123. data/lib/vapid/vendor/semantic-ui/components/menu.css +2002 -0
  124. data/lib/vapid/vendor/semantic-ui/components/menu.min.css +1 -0
  125. data/lib/vapid/vendor/semantic-ui/components/message.css +477 -0
  126. data/lib/vapid/vendor/semantic-ui/components/message.min.css +9 -0
  127. data/lib/vapid/vendor/semantic-ui/components/modal.css +502 -0
  128. data/lib/vapid/vendor/semantic-ui/components/modal.js +913 -0
  129. data/lib/vapid/vendor/semantic-ui/components/modal.min.css +9 -0
  130. data/lib/vapid/vendor/semantic-ui/components/modal.min.js +10 -0
  131. data/lib/vapid/vendor/semantic-ui/components/nag.css +147 -0
  132. data/lib/vapid/vendor/semantic-ui/components/nag.js +507 -0
  133. data/lib/vapid/vendor/semantic-ui/components/nag.min.css +9 -0
  134. data/lib/vapid/vendor/semantic-ui/components/nag.min.js +10 -0
  135. data/lib/vapid/vendor/semantic-ui/components/popup.css +733 -0
  136. data/lib/vapid/vendor/semantic-ui/components/popup.js +1475 -0
  137. data/lib/vapid/vendor/semantic-ui/components/popup.min.css +9 -0
  138. data/lib/vapid/vendor/semantic-ui/components/popup.min.js +10 -0
  139. data/lib/vapid/vendor/semantic-ui/components/progress.css +516 -0
  140. data/lib/vapid/vendor/semantic-ui/components/progress.js +931 -0
  141. data/lib/vapid/vendor/semantic-ui/components/progress.min.css +9 -0
  142. data/lib/vapid/vendor/semantic-ui/components/progress.min.js +10 -0
  143. data/lib/vapid/vendor/semantic-ui/components/rail.css +152 -0
  144. data/lib/vapid/vendor/semantic-ui/components/rail.min.css +9 -0
  145. data/lib/vapid/vendor/semantic-ui/components/rating.css +263 -0
  146. data/lib/vapid/vendor/semantic-ui/components/rating.js +508 -0
  147. data/lib/vapid/vendor/semantic-ui/components/rating.min.css +9 -0
  148. data/lib/vapid/vendor/semantic-ui/components/rating.min.js +10 -0
  149. data/lib/vapid/vendor/semantic-ui/components/reset.css +424 -0
  150. data/lib/vapid/vendor/semantic-ui/components/reset.min.css +9 -0
  151. data/lib/vapid/vendor/semantic-ui/components/reveal.css +284 -0
  152. data/lib/vapid/vendor/semantic-ui/components/reveal.min.css +9 -0
  153. data/lib/vapid/vendor/semantic-ui/components/search.css +408 -0
  154. data/lib/vapid/vendor/semantic-ui/components/search.js +1442 -0
  155. data/lib/vapid/vendor/semantic-ui/components/search.min.css +9 -0
  156. data/lib/vapid/vendor/semantic-ui/components/search.min.js +10 -0
  157. data/lib/vapid/vendor/semantic-ui/components/segment.css +798 -0
  158. data/lib/vapid/vendor/semantic-ui/components/segment.min.css +9 -0
  159. data/lib/vapid/vendor/semantic-ui/components/shape.css +157 -0
  160. data/lib/vapid/vendor/semantic-ui/components/shape.js +921 -0
  161. data/lib/vapid/vendor/semantic-ui/components/shape.min.css +9 -0
  162. data/lib/vapid/vendor/semantic-ui/components/shape.min.js +10 -0
  163. data/lib/vapid/vendor/semantic-ui/components/sidebar.css +634 -0
  164. data/lib/vapid/vendor/semantic-ui/components/sidebar.js +1036 -0
  165. data/lib/vapid/vendor/semantic-ui/components/sidebar.min.css +9 -0
  166. data/lib/vapid/vendor/semantic-ui/components/sidebar.min.js +10 -0
  167. data/lib/vapid/vendor/semantic-ui/components/site.css +160 -0
  168. data/lib/vapid/vendor/semantic-ui/components/site.js +487 -0
  169. data/lib/vapid/vendor/semantic-ui/components/site.min.css +9 -0
  170. data/lib/vapid/vendor/semantic-ui/components/site.min.js +10 -0
  171. data/lib/vapid/vendor/semantic-ui/components/state.js +708 -0
  172. data/lib/vapid/vendor/semantic-ui/components/state.min.js +10 -0
  173. data/lib/vapid/vendor/semantic-ui/components/statistic.css +569 -0
  174. data/lib/vapid/vendor/semantic-ui/components/statistic.min.css +9 -0
  175. data/lib/vapid/vendor/semantic-ui/components/step.css +623 -0
  176. data/lib/vapid/vendor/semantic-ui/components/step.min.css +9 -0
  177. data/lib/vapid/vendor/semantic-ui/components/sticky.css +78 -0
  178. data/lib/vapid/vendor/semantic-ui/components/sticky.js +942 -0
  179. data/lib/vapid/vendor/semantic-ui/components/sticky.min.css +9 -0
  180. data/lib/vapid/vendor/semantic-ui/components/sticky.min.js +10 -0
  181. data/lib/vapid/vendor/semantic-ui/components/tab.css +91 -0
  182. data/lib/vapid/vendor/semantic-ui/components/tab.js +952 -0
  183. data/lib/vapid/vendor/semantic-ui/components/tab.min.css +9 -0
  184. data/lib/vapid/vendor/semantic-ui/components/tab.min.js +10 -0
  185. data/lib/vapid/vendor/semantic-ui/components/table.css +1108 -0
  186. data/lib/vapid/vendor/semantic-ui/components/table.min.css +9 -0
  187. data/lib/vapid/vendor/semantic-ui/components/transition.css +1964 -0
  188. data/lib/vapid/vendor/semantic-ui/components/transition.js +1095 -0
  189. data/lib/vapid/vendor/semantic-ui/components/transition.min.css +9 -0
  190. data/lib/vapid/vendor/semantic-ui/components/transition.min.js +10 -0
  191. data/lib/vapid/vendor/semantic-ui/components/video.css +125 -0
  192. data/lib/vapid/vendor/semantic-ui/components/video.js +532 -0
  193. data/lib/vapid/vendor/semantic-ui/components/video.min.css +10 -0
  194. data/lib/vapid/vendor/semantic-ui/components/video.min.js +11 -0
  195. data/lib/vapid/vendor/semantic-ui/components/visibility.js +1288 -0
  196. data/lib/vapid/vendor/semantic-ui/components/visibility.min.js +10 -0
  197. data/lib/vapid/vendor/semantic-ui/components/visit.js +517 -0
  198. data/lib/vapid/vendor/semantic-ui/components/visit.min.js +11 -0
  199. data/lib/vapid/vendor/semantic-ui/package.js +34 -0
  200. data/lib/vapid/vendor/semantic-ui/package.json +20 -0
  201. data/lib/vapid/vendor/semantic-ui/semantic.css +36844 -0
  202. data/lib/vapid/vendor/semantic-ui/semantic.js +22617 -0
  203. data/lib/vapid/vendor/semantic-ui/semantic.min.css +364 -0
  204. data/lib/vapid/vendor/semantic-ui/semantic.min.js +19 -0
  205. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.eot +0 -0
  206. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.otf +0 -0
  207. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.svg +2671 -0
  208. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.ttf +0 -0
  209. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff +0 -0
  210. data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
  211. data/lib/vapid/vendor/semantic-ui/themes/default/assets/images/flags.png +0 -0
  212. data/lib/vapid/vendor/trix/.blade.yml +45 -0
  213. data/lib/vapid/vendor/trix/.github/ISSUE_TEMPLATE.md +13 -0
  214. data/lib/vapid/vendor/trix/.gitignore +3 -0
  215. data/lib/vapid/vendor/trix/.ruby-version +1 -0
  216. data/lib/vapid/vendor/trix/.travis.yml +6 -0
  217. data/lib/vapid/vendor/trix/CONDUCT.md +79 -0
  218. data/lib/vapid/vendor/trix/Gemfile +17 -0
  219. data/lib/vapid/vendor/trix/Gemfile.lock +152 -0
  220. data/lib/vapid/vendor/trix/LICENSE +20 -0
  221. data/lib/vapid/vendor/trix/README.md +382 -0
  222. data/lib/vapid/vendor/trix/assets/index.html +55 -0
  223. data/lib/vapid/vendor/trix/assets/trix-core.coffee +2 -0
  224. data/lib/vapid/vendor/trix/assets/trix.coffee +3 -0
  225. data/lib/vapid/vendor/trix/assets/trix.scss +5 -0
  226. data/lib/vapid/vendor/trix/assets/trix/banner/index.coffee.erb +3 -0
  227. data/lib/vapid/vendor/trix/assets/trix/banner/index.scss.erb +3 -0
  228. data/lib/vapid/vendor/trix/assets/trix/banner/index.txt.erb +3 -0
  229. data/lib/vapid/vendor/trix/assets/trix/images/README.md +6 -0
  230. data/lib/vapid/vendor/trix/assets/trix/images/attach.svg +5 -0
  231. data/lib/vapid/vendor/trix/assets/trix/images/bold.svg +5 -0
  232. data/lib/vapid/vendor/trix/assets/trix/images/bullets.svg +5 -0
  233. data/lib/vapid/vendor/trix/assets/trix/images/code.svg +5 -0
  234. data/lib/vapid/vendor/trix/assets/trix/images/heading_1.svg +5 -0
  235. data/lib/vapid/vendor/trix/assets/trix/images/italic.svg +5 -0
  236. data/lib/vapid/vendor/trix/assets/trix/images/link.svg +6 -0
  237. data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_decrease.svg +5 -0
  238. data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_increase.svg +5 -0
  239. data/lib/vapid/vendor/trix/assets/trix/images/numbers.svg +5 -0
  240. data/lib/vapid/vendor/trix/assets/trix/images/quote.svg +5 -0
  241. data/lib/vapid/vendor/trix/assets/trix/images/redo.svg +5 -0
  242. data/lib/vapid/vendor/trix/assets/trix/images/remove.svg +4 -0
  243. data/lib/vapid/vendor/trix/assets/trix/images/strike.svg +6 -0
  244. data/lib/vapid/vendor/trix/assets/trix/images/trash.svg +5 -0
  245. data/lib/vapid/vendor/trix/assets/trix/images/undo.svg +5 -0
  246. data/lib/vapid/vendor/trix/assets/trix/stylesheets/attachments.scss +112 -0
  247. data/lib/vapid/vendor/trix/assets/trix/stylesheets/content.scss +88 -0
  248. data/lib/vapid/vendor/trix/assets/trix/stylesheets/editor.scss +8 -0
  249. data/lib/vapid/vendor/trix/assets/trix/stylesheets/icons.scss +14 -0
  250. data/lib/vapid/vendor/trix/assets/trix/stylesheets/media-queries.scss +7 -0
  251. data/lib/vapid/vendor/trix/assets/trix/stylesheets/toolbar.scss +194 -0
  252. data/lib/vapid/vendor/trix/bin/blade +16 -0
  253. data/lib/vapid/vendor/trix/bin/ci +21 -0
  254. data/lib/vapid/vendor/trix/bin/rackup +16 -0
  255. data/lib/vapid/vendor/trix/bin/rake +16 -0
  256. data/lib/vapid/vendor/trix/bin/release +139 -0
  257. data/lib/vapid/vendor/trix/bin/setup +69 -0
  258. data/lib/vapid/vendor/trix/bin/update-status-image +100 -0
  259. data/lib/vapid/vendor/trix/bower.json +34 -0
  260. data/lib/vapid/vendor/trix/config.ru +32 -0
  261. data/lib/vapid/vendor/trix/dist/trix-core.js +11 -0
  262. data/lib/vapid/vendor/trix/dist/trix.css +286 -0
  263. data/lib/vapid/vendor/trix/dist/trix.js +20 -0
  264. data/lib/vapid/vendor/trix/package.json +29 -0
  265. data/lib/vapid/vendor/trix/polyfills/polyfills.coffee +3 -0
  266. data/lib/vapid/vendor/trix/polyfills/set.coffee +24 -0
  267. data/lib/vapid/vendor/trix/polyfills/vendor/CustomElements.js +1029 -0
  268. data/lib/vapid/vendor/trix/polyfills/vendor/README.md +2 -0
  269. data/lib/vapid/vendor/trix/polyfills/vendor/promise.js +228 -0
  270. data/lib/vapid/vendor/trix/src/trix/VERSION +1 -0
  271. data/lib/vapid/vendor/trix/src/trix/config/block_attributes.coffee +37 -0
  272. data/lib/vapid/vendor/trix/src/trix/config/css.coffee +12 -0
  273. data/lib/vapid/vendor/trix/src/trix/config/file_size_formatting.coffee +22 -0
  274. data/lib/vapid/vendor/trix/src/trix/config/index.coffee +9 -0
  275. data/lib/vapid/vendor/trix/src/trix/config/lang.coffee +26 -0
  276. data/lib/vapid/vendor/trix/src/trix/config/selection_elements.coffee +26 -0
  277. data/lib/vapid/vendor/trix/src/trix/config/serialization.coffee +63 -0
  278. data/lib/vapid/vendor/trix/src/trix/config/text_attributes.coffee +25 -0
  279. data/lib/vapid/vendor/trix/src/trix/config/toolbar.coffee +41 -0
  280. data/lib/vapid/vendor/trix/src/trix/config/undo_interval.coffee +7 -0
  281. data/lib/vapid/vendor/trix/src/trix/controllers/attachment_editor_controller.coffee +104 -0
  282. data/lib/vapid/vendor/trix/src/trix/controllers/composition_controller.coffee +117 -0
  283. data/lib/vapid/vendor/trix/src/trix/controllers/controller.coffee +3 -0
  284. data/lib/vapid/vendor/trix/src/trix/controllers/editor_controller.coffee +369 -0
  285. data/lib/vapid/vendor/trix/src/trix/controllers/input/composition_input.coffee +57 -0
  286. data/lib/vapid/vendor/trix/src/trix/controllers/input_controller.coffee +473 -0
  287. data/lib/vapid/vendor/trix/src/trix/controllers/toolbar_controller.coffee +173 -0
  288. data/lib/vapid/vendor/trix/src/trix/core/basic_object.coffee +44 -0
  289. data/lib/vapid/vendor/trix/src/trix/core/collections/element_store.coffee +21 -0
  290. data/lib/vapid/vendor/trix/src/trix/core/collections/hash.coffee +98 -0
  291. data/lib/vapid/vendor/trix/src/trix/core/collections/index.coffee +4 -0
  292. data/lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee +37 -0
  293. data/lib/vapid/vendor/trix/src/trix/core/collections/object_map.coffee +10 -0
  294. data/lib/vapid/vendor/trix/src/trix/core/helpers/arrays.coffee +34 -0
  295. data/lib/vapid/vendor/trix/src/trix/core/helpers/config.coffee +23 -0
  296. data/lib/vapid/vendor/trix/src/trix/core/helpers/custom_elements.coffee +45 -0
  297. data/lib/vapid/vendor/trix/src/trix/core/helpers/dom.coffee +185 -0
  298. data/lib/vapid/vendor/trix/src/trix/core/helpers/extend.coffee +4 -0
  299. data/lib/vapid/vendor/trix/src/trix/core/helpers/functions.coffee +3 -0
  300. data/lib/vapid/vendor/trix/src/trix/core/helpers/global.coffee +23 -0
  301. data/lib/vapid/vendor/trix/src/trix/core/helpers/index.coffee +10 -0
  302. data/lib/vapid/vendor/trix/src/trix/core/helpers/objects.coffee +11 -0
  303. data/lib/vapid/vendor/trix/src/trix/core/helpers/ranges.coffee +33 -0
  304. data/lib/vapid/vendor/trix/src/trix/core/helpers/selection.coffee +25 -0
  305. data/lib/vapid/vendor/trix/src/trix/core/helpers/strings.coffee +46 -0
  306. data/lib/vapid/vendor/trix/src/trix/core/index.coffee +4 -0
  307. data/lib/vapid/vendor/trix/src/trix/core/object.coffee +33 -0
  308. data/lib/vapid/vendor/trix/src/trix/core/utilities/index.coffee +2 -0
  309. data/lib/vapid/vendor/trix/src/trix/core/utilities/operation.coffee +37 -0
  310. data/lib/vapid/vendor/trix/src/trix/core/utilities/utf16_string.coffee +93 -0
  311. data/lib/vapid/vendor/trix/src/trix/elements/trix_editor_element.coffee +166 -0
  312. data/lib/vapid/vendor/trix/src/trix/elements/trix_toolbar_element.coffee +28 -0
  313. data/lib/vapid/vendor/trix/src/trix/index.coffee.erb +14 -0
  314. data/lib/vapid/vendor/trix/src/trix/inspector/control_element.coffee +60 -0
  315. data/lib/vapid/vendor/trix/src/trix/inspector/debugger.coffee +104 -0
  316. data/lib/vapid/vendor/trix/src/trix/inspector/element.coffee +86 -0
  317. data/lib/vapid/vendor/trix/src/trix/inspector/index.coffee +17 -0
  318. data/lib/vapid/vendor/trix/src/trix/inspector/polyfills/vendor/details-element-polyfill.js +5 -0
  319. data/lib/vapid/vendor/trix/src/trix/inspector/templates/debug.jst.eco +17 -0
  320. data/lib/vapid/vendor/trix/src/trix/inspector/templates/document.jst.eco +33 -0
  321. data/lib/vapid/vendor/trix/src/trix/inspector/templates/performance.jst.eco +10 -0
  322. data/lib/vapid/vendor/trix/src/trix/inspector/templates/render.jst.eco +1 -0
  323. data/lib/vapid/vendor/trix/src/trix/inspector/templates/selection.jst.eco +5 -0
  324. data/lib/vapid/vendor/trix/src/trix/inspector/templates/undo.jst.eco +13 -0
  325. data/lib/vapid/vendor/trix/src/trix/inspector/view.coffee +58 -0
  326. data/lib/vapid/vendor/trix/src/trix/inspector/views/debug_view.coffee +33 -0
  327. data/lib/vapid/vendor/trix/src/trix/inspector/views/document_view.coffee +12 -0
  328. data/lib/vapid/vendor/trix/src/trix/inspector/views/performance_view.coffee +51 -0
  329. data/lib/vapid/vendor/trix/src/trix/inspector/views/render_view.coffee +21 -0
  330. data/lib/vapid/vendor/trix/src/trix/inspector/views/selection_view.coffee +33 -0
  331. data/lib/vapid/vendor/trix/src/trix/inspector/views/undo_view.coffee +12 -0
  332. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/deserializer.coffee +55 -0
  333. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/index.coffee +5 -0
  334. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee +60 -0
  335. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_controller.coffee +43 -0
  336. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_element.coffee +32 -0
  337. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_view.coffee +133 -0
  338. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recorder.coffee +82 -0
  339. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee +54 -0
  340. data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/serializer.coffee +61 -0
  341. data/lib/vapid/vendor/trix/src/trix/models/attachment.coffee +157 -0
  342. data/lib/vapid/vendor/trix/src/trix/models/attachment_manager.coffee +24 -0
  343. data/lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee +47 -0
  344. data/lib/vapid/vendor/trix/src/trix/models/block.coffee +230 -0
  345. data/lib/vapid/vendor/trix/src/trix/models/composition.coffee +521 -0
  346. data/lib/vapid/vendor/trix/src/trix/models/document.coffee +538 -0
  347. data/lib/vapid/vendor/trix/src/trix/models/editor.coffee +141 -0
  348. data/lib/vapid/vendor/trix/src/trix/models/html_parser.coffee +335 -0
  349. data/lib/vapid/vendor/trix/src/trix/models/line_break_insertion.coffee +31 -0
  350. data/lib/vapid/vendor/trix/src/trix/models/location_mapper.coffee +156 -0
  351. data/lib/vapid/vendor/trix/src/trix/models/managed_attachment.coffee +28 -0
  352. data/lib/vapid/vendor/trix/src/trix/models/piece.coffee +95 -0
  353. data/lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee +28 -0
  354. data/lib/vapid/vendor/trix/src/trix/models/selection_manager.coffee +129 -0
  355. data/lib/vapid/vendor/trix/src/trix/models/splittable_list.coffee +168 -0
  356. data/lib/vapid/vendor/trix/src/trix/models/string_piece.coffee +49 -0
  357. data/lib/vapid/vendor/trix/src/trix/models/text.coffee +168 -0
  358. data/lib/vapid/vendor/trix/src/trix/models/undo_manager.coffee +40 -0
  359. data/lib/vapid/vendor/trix/src/trix/observers/mutation_observer.coffee +131 -0
  360. data/lib/vapid/vendor/trix/src/trix/observers/selection_change_observer.coffee +56 -0
  361. data/lib/vapid/vendor/trix/src/trix/operations/file_verification_operation.coffee +15 -0
  362. data/lib/vapid/vendor/trix/src/trix/operations/image_preload_operation.coffee +15 -0
  363. data/lib/vapid/vendor/trix/src/trix/views/attachment_view.coffee +99 -0
  364. data/lib/vapid/vendor/trix/src/trix/views/block_view.coffee +37 -0
  365. data/lib/vapid/vendor/trix/src/trix/views/document_view.coffee +68 -0
  366. data/lib/vapid/vendor/trix/src/trix/views/object_group_view.coffee +23 -0
  367. data/lib/vapid/vendor/trix/src/trix/views/object_view.coffee +86 -0
  368. data/lib/vapid/vendor/trix/src/trix/views/piece_view.coffee +97 -0
  369. data/lib/vapid/vendor/trix/src/trix/views/previewable_attachment_view.coffee +49 -0
  370. data/lib/vapid/vendor/trix/src/trix/views/text_view.coffee +30 -0
  371. data/lib/vapid/vendor/trix/test/.gitignore +1 -0
  372. data/lib/vapid/vendor/trix/test/src/system/attachment_test.coffee +70 -0
  373. data/lib/vapid/vendor/trix/test/src/system/basic_input_test.coffee +68 -0
  374. data/lib/vapid/vendor/trix/test/src/system/block_formatting_test.coffee +602 -0
  375. data/lib/vapid/vendor/trix/test/src/system/caching_test.coffee +21 -0
  376. data/lib/vapid/vendor/trix/test/src/system/composition_input_test.coffee +138 -0
  377. data/lib/vapid/vendor/trix/test/src/system/cursor_movement_test.coffee +54 -0
  378. data/lib/vapid/vendor/trix/test/src/system/custom_element_test.coffee +314 -0
  379. data/lib/vapid/vendor/trix/test/src/system/html_loading_test.coffee +62 -0
  380. data/lib/vapid/vendor/trix/test/src/system/html_replacement_test.coffee +101 -0
  381. data/lib/vapid/vendor/trix/test/src/system/installation_process_test.coffee +59 -0
  382. data/lib/vapid/vendor/trix/test/src/system/list_formatting_test.coffee +70 -0
  383. data/lib/vapid/vendor/trix/test/src/system/mutation_input_test.coffee +73 -0
  384. data/lib/vapid/vendor/trix/test/src/system/pasting_test.coffee +215 -0
  385. data/lib/vapid/vendor/trix/test/src/system/text_formatting_test.coffee +151 -0
  386. data/lib/vapid/vendor/trix/test/src/system/undo_test.coffee +48 -0
  387. data/lib/vapid/vendor/trix/test/src/test.coffee +16 -0
  388. data/lib/vapid/vendor/trix/test/src/test_helpers/assertions.coffee +38 -0
  389. data/lib/vapid/vendor/trix/test/src/test_helpers/editor_helpers.coffee +37 -0
  390. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_empty.jst.eco +1 -0
  391. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_html.jst.eco +2 -0
  392. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_in_table.jst.eco +7 -0
  393. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_block_styles.jst.eco +6 -0
  394. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_bold_styles.jst.eco +7 -0
  395. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_image.jst.eco +2 -0
  396. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_styled_content.jst.eco +7 -0
  397. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_toolbar_and_input.jst.eco +5 -0
  398. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/fixtures.coffee +536 -0
  399. data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/logo.png +0 -0
  400. data/lib/vapid/vendor/trix/test/src/test_helpers/index.coffee +18 -0
  401. data/lib/vapid/vendor/trix/test/src/test_helpers/input_helpers.coffee +183 -0
  402. data/lib/vapid/vendor/trix/test/src/test_helpers/selection_helpers.coffee +91 -0
  403. data/lib/vapid/vendor/trix/test/src/test_helpers/test_helpers.coffee +72 -0
  404. data/lib/vapid/vendor/trix/test/src/test_helpers/test_stubs.coffee +31 -0
  405. data/lib/vapid/vendor/trix/test/src/test_helpers/toolbar_helpers.coffee +45 -0
  406. data/lib/vapid/vendor/trix/test/src/unit/attachment_test.coffee +23 -0
  407. data/lib/vapid/vendor/trix/test/src/unit/block_test.coffee +22 -0
  408. data/lib/vapid/vendor/trix/test/src/unit/composition_test.coffee +13 -0
  409. data/lib/vapid/vendor/trix/test/src/unit/document_test.coffee +11 -0
  410. data/lib/vapid/vendor/trix/test/src/unit/document_view_test.coffee +6 -0
  411. data/lib/vapid/vendor/trix/test/src/unit/html_parser_test.coffee +162 -0
  412. data/lib/vapid/vendor/trix/test/src/unit/location_mapper_test.coffee +185 -0
  413. data/lib/vapid/vendor/trix/test/src/unit/mutation_observer_test.coffee +84 -0
  414. data/lib/vapid/vendor/trix/test/src/unit/serialization_test.coffee +7 -0
  415. data/lib/vapid/vendor/trix/test/src/unit/string_change_summary_test.coffee +57 -0
  416. data/lib/vapid/vendor/trix/test/src/unit/text_test.coffee +19 -0
  417. data/lib/vapid/vendor/trix/test/vendor/rangy-core.js +3845 -0
  418. data/lib/vapid/vendor/trix/test/vendor/rangy-textrange.js +1930 -0
  419. data/lib/vapid/version.rb +4 -0
  420. data/lib/vapid/views/admin/install.html.erb +19 -0
  421. data/lib/vapid/views/admin/login.html.erb +11 -0
  422. data/lib/vapid/views/admin/overview/index.html.erb +1 -0
  423. data/lib/vapid/views/admin/records/_form.erb +9 -0
  424. data/lib/vapid/views/admin/records/edit.html.erb +5 -0
  425. data/lib/vapid/views/admin/records/index.html.erb +38 -0
  426. data/lib/vapid/views/admin/records/new.html.erb +3 -0
  427. data/lib/vapid/views/errors/404.html.erb +1 -0
  428. data/lib/vapid/views/errors/500.html.erb +1 -0
  429. data/lib/vapid/views/layouts/admin.html.erb +41 -0
  430. data/lib/vapid/views/layouts/admin_form.html.erb +22 -0
  431. data/lib/vapid/views/layouts/error.html.erb +11 -0
  432. data/vapid.gemspec +48 -0
  433. metadata +811 -0
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * # Semantic UI 2.0.0 - 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
+ */.ui.video{background-color:#ddd;position:relative;max-width:100%;padding-bottom:56.25%;height:0;overflow:hidden}.ui.video .placeholder{background-color:#333}.ui.video .play{cursor:pointer;position:absolute;top:0;left:0;z-index:10;width:100%;height:100%;background:0 0;-webkit-transition:background .2s ease;transition:background .2s ease}.ui.video .play.icon:before{position:absolute;top:50%;left:50%;z-index:11;-webkit-transform:translateX(-50%)translateY(-50%);-ms-transform:translateX(-50%)translateY(-50%);transform:translateX(-50%)translateY(-50%);color:rgba(255,255,255,.7);font-size:7rem;text-shadow:2px 2px 0 rgba(0,0,0,.15);-webkit-transition:color .2s ease;transition:color .2s ease}.ui.video .placeholder{position:absolute;top:0;left:0;display:block;width:100%;height:100%}.ui.video .embed embed,.ui.video .embed iframe,.ui.video .embed object{position:absolute;border:none;width:100%;height:100%;top:0;left:0;margin:0;padding:0}.ui.video .play:hover{background:0 0}.ui.video .play:hover:before{color:#fff}.ui.active.video .placeholder,.ui.active.video .play{display:none}.ui.active.video .embed{display:inline}
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * # Semantic UI 2.0.0 - Video
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Copyright 2014 Contributorss
7
+ * Released under the MIT license
8
+ * http://opensource.org/licenses/MIT
9
+ *
10
+ */
11
+ !function(e,o,t,n){"use strict";e.fn.video=function(t){{var a,i=e(this),r=i.selector||"",l=(new Date).getTime(),c=[],u=arguments[0],s="string"==typeof u,m=[].slice.call(arguments,1);o.requestAnimationFrame||o.mozRequestAnimationFrame||o.webkitRequestAnimationFrame||o.msRequestAnimationFrame||function(e){setTimeout(e,0)}}return i.each(function(){var d,p=e.isPlainObject(t)?e.extend(!0,{},e.fn.video.settings,t):e.extend({},e.fn.video.settings),f=p.selector,g=p.className,h=p.error,v=p.metadata,b=p.namespace,y=p.templates,w="."+b,x="module-"+b,F=(e(o),e(this)),C=F.find(f.placeholder),E=F.find(f.playButton),T=F.find(f.embed),A=this,P=F.data(x);d={initialize:function(){d.debug("Initializing video"),d.create(),F.on("click"+w,f.placeholder,d.play).on("click"+w,f.playButton,d.play),d.instantiate()},instantiate:function(){d.verbose("Storing instance of module",d),P=d,F.data(x,d)},create:function(){var e=F.data(v.image),o=y.video(e);F.html(o),d.refresh(),e||d.play(),d.debug("Creating html for video element",o)},destroy:function(){d.verbose("Destroying previous instance of video"),d.reset(),F.removeData(x).off(w)},refresh:function(){d.verbose("Refreshing selector cache"),C=F.find(f.placeholder),E=F.find(f.playButton),T=F.find(f.embed)},change:function(e,o,t){d.debug("Changing video to ",e,o,t),F.data(v.source,e).data(v.id,o).data(v.url,t),p.onChange()},reset:function(){d.debug("Clearing video embed and showing placeholder"),F.removeClass(g.active),T.html(" "),C.show(),p.onReset()},play:function(){d.debug("Playing video");var e=F.data(v.source)||!1,o=F.data(v.url)||!1,t=F.data(v.id)||!1;T.html(d.generate.html(e,t,o)),F.addClass(g.active),p.onPlay()},get:{source:function(e){return"string"!=typeof e?!1:-1!==e.search("youtube.com")?"youtube":-1!==e.search("vimeo.com")?"vimeo":!1},id:function(e){return e.match(p.regExp.youtube)?e.match(p.regExp.youtube)[1]:e.match(p.regExp.vimeo)?e.match(p.regExp.vimeo)[2]:!1}},generate:{html:function(e,o,t){d.debug("Generating embed html");var n;return e=e||p.source,o=o||p.id,e&&o||t?(e&&o||(e=d.get.source(t),o=d.get.id(t)),"vimeo"==e?n='<iframe src="//player.vimeo.com/video/'+o+"?="+d.generate.url(e)+'" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>':"youtube"==e&&(n='<iframe src="//www.youtube.com/embed/'+o+"?="+d.generate.url(e)+'" width="100%" height="100%" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>')):d.error(h.noVideo),n},url:function(e){var o=p.api?1:0,t="auto"===p.autoplay?F.data("image")!==n:p.autoplay,a=p.hd?1:0,i=p.showUI?1:0,r=p.showUI?0:1,l="";return"vimeo"==e&&(l="api="+o+"&amp;title="+i+"&amp;byline="+i+"&amp;portrait="+i+"&amp;autoplay="+t,p.color&&(l+="&amp;color="+p.color)),"ustream"==e?(l="autoplay="+t,p.color&&(l+="&amp;color="+p.color)):"youtube"==e&&(l="enablejsapi="+o+"&amp;autoplay="+t+"&amp;autohide="+r+"&amp;hq="+a+"&amp;modestbranding=1",p.color&&(l+="&amp;color="+p.color)),l}},setting:function(o,t){if(d.debug("Changing setting",o,t),e.isPlainObject(o))e.extend(!0,p,o);else{if(t===n)return p[o];p[o]=t}},internal:function(o,t){if(e.isPlainObject(o))e.extend(!0,d,o);else{if(t===n)return d[o];d[o]=t}},debug:function(){p.debug&&(p.performance?d.performance.log(arguments):(d.debug=Function.prototype.bind.call(console.info,console,p.name+":"),d.debug.apply(console,arguments)))},verbose:function(){p.verbose&&p.debug&&(p.performance?d.performance.log(arguments):(d.verbose=Function.prototype.bind.call(console.info,console,p.name+":"),d.verbose.apply(console,arguments)))},error:function(){d.error=Function.prototype.bind.call(console.error,console,p.name+":"),d.error.apply(console,arguments)},performance:{log:function(e){var o,t,n;p.performance&&(o=(new Date).getTime(),n=l||o,t=o-n,l=o,c.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:A,"Execution Time":t})),clearTimeout(d.performance.timer),d.performance.timer=setTimeout(d.performance.display,500)},display:function(){var o=p.name+":",t=0;l=!1,clearTimeout(d.performance.timer),e.each(c,function(e,o){t+=o["Execution Time"]}),o+=" "+t+"ms",r&&(o+=" '"+r+"'"),i.length>1&&(o+=" ("+i.length+")"),(console.group!==n||console.table!==n)&&c.length>0&&(console.groupCollapsed(o),console.table?console.table(c):e.each(c,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),c=[]}},invoke:function(o,t,i){var r,l,c,u=P;return t=t||m,i=A||i,"string"==typeof o&&u!==n&&(o=o.split(/[\. ]/),r=o.length-1,e.each(o,function(t,a){var i=t!=r?a+o[t+1].charAt(0).toUpperCase()+o[t+1].slice(1):o;if(e.isPlainObject(u[i])&&t!=r)u=u[i];else{if(u[i]!==n)return l=u[i],!1;if(!e.isPlainObject(u[a])||t==r)return u[a]!==n?(l=u[a],!1):(d.error(h.method,o),!1);u=u[a]}})),e.isFunction(l)?c=l.apply(i,t):l!==n&&(c=l),e.isArray(a)?a.push(c):a!==n?a=[a,c]:c!==n&&(a=c),l}},s?(P===n&&d.initialize(),d.invoke(u)):(P!==n&&P.invoke("destroy"),d.initialize())}),a!==n?a:this},e.fn.video.settings={name:"Video",namespace:"video",debug:!1,verbose:!1,performance:!0,metadata:{id:"id",image:"image",source:"source",url:"url"},source:!1,url:!1,id:!1,aspectRatio:16/9,onPlay:function(){},onReset:function(){},onChange:function(){},onPause:function(){},onStop:function(){},width:"auto",height:"auto",autoplay:"auto",color:"#442359",hd:!0,showUI:!1,api:!0,regExp:{youtube:/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/,vimeo:/http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/},error:{noVideo:"No video specified",method:"The method you called is not defined"},className:{active:"active"},selector:{embed:".embed",placeholder:".placeholder",playButton:".play"}},e.fn.video.settings.templates={video:function(e){var o="";return e&&(o+='<i class="video play icon"></i><img class="placeholder" src="'+e+'">'),o+='<div class="embed"></div>'}}}(jQuery,window,document);
@@ -0,0 +1,1288 @@
1
+ /*!
2
+ * # Semantic UI 2.2.9 - Visibility
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Released under the MIT license
7
+ * http://opensource.org/licenses/MIT
8
+ *
9
+ */
10
+
11
+ ;(function ($, window, document, undefined) {
12
+
13
+ "use strict";
14
+
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
21
+
22
+ $.fn.visibility = function(parameters) {
23
+ var
24
+ $allModules = $(this),
25
+ moduleSelector = $allModules.selector || '',
26
+
27
+ time = new Date().getTime(),
28
+ performance = [],
29
+
30
+ query = arguments[0],
31
+ methodInvoked = (typeof query == 'string'),
32
+ queryArguments = [].slice.call(arguments, 1),
33
+ returnedValue,
34
+
35
+ moduleCount = $allModules.length,
36
+ loadedCount = 0
37
+ ;
38
+
39
+ $allModules
40
+ .each(function() {
41
+ var
42
+ settings = ( $.isPlainObject(parameters) )
43
+ ? $.extend(true, {}, $.fn.visibility.settings, parameters)
44
+ : $.extend({}, $.fn.visibility.settings),
45
+
46
+ className = settings.className,
47
+ namespace = settings.namespace,
48
+ error = settings.error,
49
+ metadata = settings.metadata,
50
+
51
+ eventNamespace = '.' + namespace,
52
+ moduleNamespace = 'module-' + namespace,
53
+
54
+ $window = $(window),
55
+
56
+ $module = $(this),
57
+ $context = $(settings.context),
58
+
59
+ $placeholder,
60
+
61
+ selector = $module.selector || '',
62
+ instance = $module.data(moduleNamespace),
63
+
64
+ requestAnimationFrame = window.requestAnimationFrame
65
+ || window.mozRequestAnimationFrame
66
+ || window.webkitRequestAnimationFrame
67
+ || window.msRequestAnimationFrame
68
+ || function(callback) { setTimeout(callback, 0); },
69
+
70
+ element = this,
71
+ disabled = false,
72
+
73
+ contextObserver,
74
+ observer,
75
+ module
76
+ ;
77
+
78
+ module = {
79
+
80
+ initialize: function() {
81
+ module.debug('Initializing', settings);
82
+
83
+ module.setup.cache();
84
+
85
+ if( module.should.trackChanges() ) {
86
+
87
+ if(settings.type == 'image') {
88
+ module.setup.image();
89
+ }
90
+ if(settings.type == 'fixed') {
91
+ module.setup.fixed();
92
+ }
93
+
94
+ if(settings.observeChanges) {
95
+ module.observeChanges();
96
+ }
97
+ module.bind.events();
98
+ }
99
+
100
+ module.save.position();
101
+ if( !module.is.visible() ) {
102
+ module.error(error.visible, $module);
103
+ }
104
+
105
+ if(settings.initialCheck) {
106
+ module.checkVisibility();
107
+ }
108
+ module.instantiate();
109
+ },
110
+
111
+ instantiate: function() {
112
+ module.debug('Storing instance', module);
113
+ $module
114
+ .data(moduleNamespace, module)
115
+ ;
116
+ instance = module;
117
+ },
118
+
119
+ destroy: function() {
120
+ module.verbose('Destroying previous module');
121
+ if(observer) {
122
+ observer.disconnect();
123
+ }
124
+ if(contextObserver) {
125
+ contextObserver.disconnect();
126
+ }
127
+ $window
128
+ .off('load' + eventNamespace, module.event.load)
129
+ .off('resize' + eventNamespace, module.event.resize)
130
+ ;
131
+ $context
132
+ .off('scroll' + eventNamespace, module.event.scroll)
133
+ .off('scrollchange' + eventNamespace, module.event.scrollchange)
134
+ ;
135
+ if(settings.type == 'fixed') {
136
+ module.resetFixed();
137
+ module.remove.placeholder();
138
+ }
139
+ $module
140
+ .off(eventNamespace)
141
+ .removeData(moduleNamespace)
142
+ ;
143
+ },
144
+
145
+ observeChanges: function() {
146
+ if('MutationObserver' in window) {
147
+ contextObserver = new MutationObserver(module.event.contextChanged);
148
+ observer = new MutationObserver(module.event.changed);
149
+ contextObserver.observe(document, {
150
+ childList : true,
151
+ subtree : true
152
+ });
153
+ observer.observe(element, {
154
+ childList : true,
155
+ subtree : true
156
+ });
157
+ module.debug('Setting up mutation observer', observer);
158
+ }
159
+ },
160
+
161
+ bind: {
162
+ events: function() {
163
+ module.verbose('Binding visibility events to scroll and resize');
164
+ if(settings.refreshOnLoad) {
165
+ $window
166
+ .on('load' + eventNamespace, module.event.load)
167
+ ;
168
+ }
169
+ $window
170
+ .on('resize' + eventNamespace, module.event.resize)
171
+ ;
172
+ // pub/sub pattern
173
+ $context
174
+ .off('scroll' + eventNamespace)
175
+ .on('scroll' + eventNamespace, module.event.scroll)
176
+ .on('scrollchange' + eventNamespace, module.event.scrollchange)
177
+ ;
178
+ }
179
+ },
180
+
181
+ event: {
182
+ changed: function(mutations) {
183
+ module.verbose('DOM tree modified, updating visibility calculations');
184
+ module.timer = setTimeout(function() {
185
+ module.verbose('DOM tree modified, updating sticky menu');
186
+ module.refresh();
187
+ }, 100);
188
+ },
189
+ contextChanged: function(mutations) {
190
+ [].forEach.call(mutations, function(mutation) {
191
+ if(mutation.removedNodes) {
192
+ [].forEach.call(mutation.removedNodes, function(node) {
193
+ if(node == element || $(node).find(element).length > 0) {
194
+ module.debug('Element removed from DOM, tearing down events');
195
+ module.destroy();
196
+ }
197
+ });
198
+ }
199
+ });
200
+ },
201
+ resize: function() {
202
+ module.debug('Window resized');
203
+ if(settings.refreshOnResize) {
204
+ requestAnimationFrame(module.refresh);
205
+ }
206
+ },
207
+ load: function() {
208
+ module.debug('Page finished loading');
209
+ requestAnimationFrame(module.refresh);
210
+ },
211
+ // publishes scrollchange event on one scroll
212
+ scroll: function() {
213
+ if(settings.throttle) {
214
+ clearTimeout(module.timer);
215
+ module.timer = setTimeout(function() {
216
+ $context.triggerHandler('scrollchange' + eventNamespace, [ $context.scrollTop() ]);
217
+ }, settings.throttle);
218
+ }
219
+ else {
220
+ requestAnimationFrame(function() {
221
+ $context.triggerHandler('scrollchange' + eventNamespace, [ $context.scrollTop() ]);
222
+ });
223
+ }
224
+ },
225
+ // subscribes to scrollchange
226
+ scrollchange: function(event, scrollPosition) {
227
+ module.checkVisibility(scrollPosition);
228
+ },
229
+ },
230
+
231
+ precache: function(images, callback) {
232
+ if (!(images instanceof Array)) {
233
+ images = [images];
234
+ }
235
+ var
236
+ imagesLength = images.length,
237
+ loadedCounter = 0,
238
+ cache = [],
239
+ cacheImage = document.createElement('img'),
240
+ handleLoad = function() {
241
+ loadedCounter++;
242
+ if (loadedCounter >= images.length) {
243
+ if ($.isFunction(callback)) {
244
+ callback();
245
+ }
246
+ }
247
+ }
248
+ ;
249
+ while (imagesLength--) {
250
+ cacheImage = document.createElement('img');
251
+ cacheImage.onload = handleLoad;
252
+ cacheImage.onerror = handleLoad;
253
+ cacheImage.src = images[imagesLength];
254
+ cache.push(cacheImage);
255
+ }
256
+ },
257
+
258
+ enableCallbacks: function() {
259
+ module.debug('Allowing callbacks to occur');
260
+ disabled = false;
261
+ },
262
+
263
+ disableCallbacks: function() {
264
+ module.debug('Disabling all callbacks temporarily');
265
+ disabled = true;
266
+ },
267
+
268
+ should: {
269
+ trackChanges: function() {
270
+ if(methodInvoked) {
271
+ module.debug('One time query, no need to bind events');
272
+ return false;
273
+ }
274
+ module.debug('Callbacks being attached');
275
+ return true;
276
+ }
277
+ },
278
+
279
+ setup: {
280
+ cache: function() {
281
+ module.cache = {
282
+ occurred : {},
283
+ screen : {},
284
+ element : {},
285
+ };
286
+ },
287
+ image: function() {
288
+ var
289
+ src = $module.data(metadata.src)
290
+ ;
291
+ if(src) {
292
+ module.verbose('Lazy loading image', src);
293
+ settings.once = true;
294
+ settings.observeChanges = false;
295
+
296
+ // show when top visible
297
+ settings.onOnScreen = function() {
298
+ module.debug('Image on screen', element);
299
+ module.precache(src, function() {
300
+ module.set.image(src, function() {
301
+ loadedCount++;
302
+ if(loadedCount == moduleCount) {
303
+ settings.onAllLoaded.call(this);
304
+ }
305
+ settings.onLoad.call(this);
306
+ });
307
+ });
308
+ };
309
+ }
310
+ },
311
+ fixed: function() {
312
+ module.debug('Setting up fixed');
313
+ settings.once = false;
314
+ settings.observeChanges = false;
315
+ settings.initialCheck = true;
316
+ settings.refreshOnLoad = true;
317
+ if(!parameters.transition) {
318
+ settings.transition = false;
319
+ }
320
+ module.create.placeholder();
321
+ module.debug('Added placeholder', $placeholder);
322
+ settings.onTopPassed = function() {
323
+ module.debug('Element passed, adding fixed position', $module);
324
+ module.show.placeholder();
325
+ module.set.fixed();
326
+ if(settings.transition) {
327
+ if($.fn.transition !== undefined) {
328
+ $module.transition(settings.transition, settings.duration);
329
+ }
330
+ }
331
+ };
332
+ settings.onTopPassedReverse = function() {
333
+ module.debug('Element returned to position, removing fixed', $module);
334
+ module.hide.placeholder();
335
+ module.remove.fixed();
336
+ };
337
+ }
338
+ },
339
+
340
+ create: {
341
+ placeholder: function() {
342
+ module.verbose('Creating fixed position placeholder');
343
+ $placeholder = $module
344
+ .clone(false)
345
+ .css('display', 'none')
346
+ .addClass(className.placeholder)
347
+ .insertAfter($module)
348
+ ;
349
+ }
350
+ },
351
+
352
+ show: {
353
+ placeholder: function() {
354
+ module.verbose('Showing placeholder');
355
+ $placeholder
356
+ .css('display', 'block')
357
+ .css('visibility', 'hidden')
358
+ ;
359
+ }
360
+ },
361
+ hide: {
362
+ placeholder: function() {
363
+ module.verbose('Hiding placeholder');
364
+ $placeholder
365
+ .css('display', 'none')
366
+ .css('visibility', '')
367
+ ;
368
+ }
369
+ },
370
+
371
+ set: {
372
+ fixed: function() {
373
+ module.verbose('Setting element to fixed position');
374
+ $module
375
+ .addClass(className.fixed)
376
+ .css({
377
+ position : 'fixed',
378
+ top : settings.offset + 'px',
379
+ left : 'auto',
380
+ zIndex : settings.zIndex
381
+ })
382
+ ;
383
+ settings.onFixed.call(element);
384
+ },
385
+ image: function(src, callback) {
386
+ $module
387
+ .attr('src', src)
388
+ ;
389
+ if(settings.transition) {
390
+ if( $.fn.transition !== undefined) {
391
+ if($module.hasClass(className.visible)) {
392
+ module.debug('Transition already occurred on this image, skipping animation');
393
+ return;
394
+ }
395
+ $module.transition(settings.transition, settings.duration, callback);
396
+ }
397
+ else {
398
+ $module.fadeIn(settings.duration, callback);
399
+ }
400
+ }
401
+ else {
402
+ $module.show();
403
+ }
404
+ }
405
+ },
406
+
407
+ is: {
408
+ onScreen: function() {
409
+ var
410
+ calculations = module.get.elementCalculations()
411
+ ;
412
+ return calculations.onScreen;
413
+ },
414
+ offScreen: function() {
415
+ var
416
+ calculations = module.get.elementCalculations()
417
+ ;
418
+ return calculations.offScreen;
419
+ },
420
+ visible: function() {
421
+ if(module.cache && module.cache.element) {
422
+ return !(module.cache.element.width === 0 && module.cache.element.offset.top === 0);
423
+ }
424
+ return false;
425
+ }
426
+ },
427
+
428
+ refresh: function() {
429
+ module.debug('Refreshing constants (width/height)');
430
+ if(settings.type == 'fixed') {
431
+ module.resetFixed();
432
+ }
433
+ module.reset();
434
+ module.save.position();
435
+ if(settings.checkOnRefresh) {
436
+ module.checkVisibility();
437
+ }
438
+ settings.onRefresh.call(element);
439
+ },
440
+
441
+ resetFixed: function () {
442
+ module.remove.fixed();
443
+ module.remove.occurred();
444
+ },
445
+
446
+ reset: function() {
447
+ module.verbose('Resetting all cached values');
448
+ if( $.isPlainObject(module.cache) ) {
449
+ module.cache.screen = {};
450
+ module.cache.element = {};
451
+ }
452
+ },
453
+
454
+ checkVisibility: function(scroll) {
455
+ module.verbose('Checking visibility of element', module.cache.element);
456
+
457
+ if( !disabled && module.is.visible() ) {
458
+
459
+ // save scroll position
460
+ module.save.scroll(scroll);
461
+
462
+ // update calculations derived from scroll
463
+ module.save.calculations();
464
+
465
+ // percentage
466
+ module.passed();
467
+
468
+ // reverse (must be first)
469
+ module.passingReverse();
470
+ module.topVisibleReverse();
471
+ module.bottomVisibleReverse();
472
+ module.topPassedReverse();
473
+ module.bottomPassedReverse();
474
+
475
+ // one time
476
+ module.onScreen();
477
+ module.offScreen();
478
+ module.passing();
479
+ module.topVisible();
480
+ module.bottomVisible();
481
+ module.topPassed();
482
+ module.bottomPassed();
483
+
484
+ // on update callback
485
+ if(settings.onUpdate) {
486
+ settings.onUpdate.call(element, module.get.elementCalculations());
487
+ }
488
+ }
489
+ },
490
+
491
+ passed: function(amount, newCallback) {
492
+ var
493
+ calculations = module.get.elementCalculations(),
494
+ amountInPixels
495
+ ;
496
+ // assign callback
497
+ if(amount && newCallback) {
498
+ settings.onPassed[amount] = newCallback;
499
+ }
500
+ else if(amount !== undefined) {
501
+ return (module.get.pixelsPassed(amount) > calculations.pixelsPassed);
502
+ }
503
+ else if(calculations.passing) {
504
+ $.each(settings.onPassed, function(amount, callback) {
505
+ if(calculations.bottomVisible || calculations.pixelsPassed > module.get.pixelsPassed(amount)) {
506
+ module.execute(callback, amount);
507
+ }
508
+ else if(!settings.once) {
509
+ module.remove.occurred(callback);
510
+ }
511
+ });
512
+ }
513
+ },
514
+
515
+ onScreen: function(newCallback) {
516
+ var
517
+ calculations = module.get.elementCalculations(),
518
+ callback = newCallback || settings.onOnScreen,
519
+ callbackName = 'onScreen'
520
+ ;
521
+ if(newCallback) {
522
+ module.debug('Adding callback for onScreen', newCallback);
523
+ settings.onOnScreen = newCallback;
524
+ }
525
+ if(calculations.onScreen) {
526
+ module.execute(callback, callbackName);
527
+ }
528
+ else if(!settings.once) {
529
+ module.remove.occurred(callbackName);
530
+ }
531
+ if(newCallback !== undefined) {
532
+ return calculations.onOnScreen;
533
+ }
534
+ },
535
+
536
+ offScreen: function(newCallback) {
537
+ var
538
+ calculations = module.get.elementCalculations(),
539
+ callback = newCallback || settings.onOffScreen,
540
+ callbackName = 'offScreen'
541
+ ;
542
+ if(newCallback) {
543
+ module.debug('Adding callback for offScreen', newCallback);
544
+ settings.onOffScreen = newCallback;
545
+ }
546
+ if(calculations.offScreen) {
547
+ module.execute(callback, callbackName);
548
+ }
549
+ else if(!settings.once) {
550
+ module.remove.occurred(callbackName);
551
+ }
552
+ if(newCallback !== undefined) {
553
+ return calculations.onOffScreen;
554
+ }
555
+ },
556
+
557
+ passing: function(newCallback) {
558
+ var
559
+ calculations = module.get.elementCalculations(),
560
+ callback = newCallback || settings.onPassing,
561
+ callbackName = 'passing'
562
+ ;
563
+ if(newCallback) {
564
+ module.debug('Adding callback for passing', newCallback);
565
+ settings.onPassing = newCallback;
566
+ }
567
+ if(calculations.passing) {
568
+ module.execute(callback, callbackName);
569
+ }
570
+ else if(!settings.once) {
571
+ module.remove.occurred(callbackName);
572
+ }
573
+ if(newCallback !== undefined) {
574
+ return calculations.passing;
575
+ }
576
+ },
577
+
578
+
579
+ topVisible: function(newCallback) {
580
+ var
581
+ calculations = module.get.elementCalculations(),
582
+ callback = newCallback || settings.onTopVisible,
583
+ callbackName = 'topVisible'
584
+ ;
585
+ if(newCallback) {
586
+ module.debug('Adding callback for top visible', newCallback);
587
+ settings.onTopVisible = newCallback;
588
+ }
589
+ if(calculations.topVisible) {
590
+ module.execute(callback, callbackName);
591
+ }
592
+ else if(!settings.once) {
593
+ module.remove.occurred(callbackName);
594
+ }
595
+ if(newCallback === undefined) {
596
+ return calculations.topVisible;
597
+ }
598
+ },
599
+
600
+ bottomVisible: function(newCallback) {
601
+ var
602
+ calculations = module.get.elementCalculations(),
603
+ callback = newCallback || settings.onBottomVisible,
604
+ callbackName = 'bottomVisible'
605
+ ;
606
+ if(newCallback) {
607
+ module.debug('Adding callback for bottom visible', newCallback);
608
+ settings.onBottomVisible = newCallback;
609
+ }
610
+ if(calculations.bottomVisible) {
611
+ module.execute(callback, callbackName);
612
+ }
613
+ else if(!settings.once) {
614
+ module.remove.occurred(callbackName);
615
+ }
616
+ if(newCallback === undefined) {
617
+ return calculations.bottomVisible;
618
+ }
619
+ },
620
+
621
+ topPassed: function(newCallback) {
622
+ var
623
+ calculations = module.get.elementCalculations(),
624
+ callback = newCallback || settings.onTopPassed,
625
+ callbackName = 'topPassed'
626
+ ;
627
+ if(newCallback) {
628
+ module.debug('Adding callback for top passed', newCallback);
629
+ settings.onTopPassed = newCallback;
630
+ }
631
+ if(calculations.topPassed) {
632
+ module.execute(callback, callbackName);
633
+ }
634
+ else if(!settings.once) {
635
+ module.remove.occurred(callbackName);
636
+ }
637
+ if(newCallback === undefined) {
638
+ return calculations.topPassed;
639
+ }
640
+ },
641
+
642
+ bottomPassed: function(newCallback) {
643
+ var
644
+ calculations = module.get.elementCalculations(),
645
+ callback = newCallback || settings.onBottomPassed,
646
+ callbackName = 'bottomPassed'
647
+ ;
648
+ if(newCallback) {
649
+ module.debug('Adding callback for bottom passed', newCallback);
650
+ settings.onBottomPassed = newCallback;
651
+ }
652
+ if(calculations.bottomPassed) {
653
+ module.execute(callback, callbackName);
654
+ }
655
+ else if(!settings.once) {
656
+ module.remove.occurred(callbackName);
657
+ }
658
+ if(newCallback === undefined) {
659
+ return calculations.bottomPassed;
660
+ }
661
+ },
662
+
663
+ passingReverse: function(newCallback) {
664
+ var
665
+ calculations = module.get.elementCalculations(),
666
+ callback = newCallback || settings.onPassingReverse,
667
+ callbackName = 'passingReverse'
668
+ ;
669
+ if(newCallback) {
670
+ module.debug('Adding callback for passing reverse', newCallback);
671
+ settings.onPassingReverse = newCallback;
672
+ }
673
+ if(!calculations.passing) {
674
+ if(module.get.occurred('passing')) {
675
+ module.execute(callback, callbackName);
676
+ }
677
+ }
678
+ else if(!settings.once) {
679
+ module.remove.occurred(callbackName);
680
+ }
681
+ if(newCallback !== undefined) {
682
+ return !calculations.passing;
683
+ }
684
+ },
685
+
686
+
687
+ topVisibleReverse: function(newCallback) {
688
+ var
689
+ calculations = module.get.elementCalculations(),
690
+ callback = newCallback || settings.onTopVisibleReverse,
691
+ callbackName = 'topVisibleReverse'
692
+ ;
693
+ if(newCallback) {
694
+ module.debug('Adding callback for top visible reverse', newCallback);
695
+ settings.onTopVisibleReverse = newCallback;
696
+ }
697
+ if(!calculations.topVisible) {
698
+ if(module.get.occurred('topVisible')) {
699
+ module.execute(callback, callbackName);
700
+ }
701
+ }
702
+ else if(!settings.once) {
703
+ module.remove.occurred(callbackName);
704
+ }
705
+ if(newCallback === undefined) {
706
+ return !calculations.topVisible;
707
+ }
708
+ },
709
+
710
+ bottomVisibleReverse: function(newCallback) {
711
+ var
712
+ calculations = module.get.elementCalculations(),
713
+ callback = newCallback || settings.onBottomVisibleReverse,
714
+ callbackName = 'bottomVisibleReverse'
715
+ ;
716
+ if(newCallback) {
717
+ module.debug('Adding callback for bottom visible reverse', newCallback);
718
+ settings.onBottomVisibleReverse = newCallback;
719
+ }
720
+ if(!calculations.bottomVisible) {
721
+ if(module.get.occurred('bottomVisible')) {
722
+ module.execute(callback, callbackName);
723
+ }
724
+ }
725
+ else if(!settings.once) {
726
+ module.remove.occurred(callbackName);
727
+ }
728
+ if(newCallback === undefined) {
729
+ return !calculations.bottomVisible;
730
+ }
731
+ },
732
+
733
+ topPassedReverse: function(newCallback) {
734
+ var
735
+ calculations = module.get.elementCalculations(),
736
+ callback = newCallback || settings.onTopPassedReverse,
737
+ callbackName = 'topPassedReverse'
738
+ ;
739
+ if(newCallback) {
740
+ module.debug('Adding callback for top passed reverse', newCallback);
741
+ settings.onTopPassedReverse = newCallback;
742
+ }
743
+ if(!calculations.topPassed) {
744
+ if(module.get.occurred('topPassed')) {
745
+ module.execute(callback, callbackName);
746
+ }
747
+ }
748
+ else if(!settings.once) {
749
+ module.remove.occurred(callbackName);
750
+ }
751
+ if(newCallback === undefined) {
752
+ return !calculations.onTopPassed;
753
+ }
754
+ },
755
+
756
+ bottomPassedReverse: function(newCallback) {
757
+ var
758
+ calculations = module.get.elementCalculations(),
759
+ callback = newCallback || settings.onBottomPassedReverse,
760
+ callbackName = 'bottomPassedReverse'
761
+ ;
762
+ if(newCallback) {
763
+ module.debug('Adding callback for bottom passed reverse', newCallback);
764
+ settings.onBottomPassedReverse = newCallback;
765
+ }
766
+ if(!calculations.bottomPassed) {
767
+ if(module.get.occurred('bottomPassed')) {
768
+ module.execute(callback, callbackName);
769
+ }
770
+ }
771
+ else if(!settings.once) {
772
+ module.remove.occurred(callbackName);
773
+ }
774
+ if(newCallback === undefined) {
775
+ return !calculations.bottomPassed;
776
+ }
777
+ },
778
+
779
+ execute: function(callback, callbackName) {
780
+ var
781
+ calculations = module.get.elementCalculations(),
782
+ screen = module.get.screenCalculations()
783
+ ;
784
+ callback = callback || false;
785
+ if(callback) {
786
+ if(settings.continuous) {
787
+ module.debug('Callback being called continuously', callbackName, calculations);
788
+ callback.call(element, calculations, screen);
789
+ }
790
+ else if(!module.get.occurred(callbackName)) {
791
+ module.debug('Conditions met', callbackName, calculations);
792
+ callback.call(element, calculations, screen);
793
+ }
794
+ }
795
+ module.save.occurred(callbackName);
796
+ },
797
+
798
+ remove: {
799
+ fixed: function() {
800
+ module.debug('Removing fixed position');
801
+ $module
802
+ .removeClass(className.fixed)
803
+ .css({
804
+ position : '',
805
+ top : '',
806
+ left : '',
807
+ zIndex : ''
808
+ })
809
+ ;
810
+ settings.onUnfixed.call(element);
811
+ },
812
+ placeholder: function() {
813
+ module.debug('Removing placeholder content');
814
+ if($placeholder) {
815
+ $placeholder.remove();
816
+ }
817
+ },
818
+ occurred: function(callback) {
819
+ if(callback) {
820
+ var
821
+ occurred = module.cache.occurred
822
+ ;
823
+ if(occurred[callback] !== undefined && occurred[callback] === true) {
824
+ module.debug('Callback can now be called again', callback);
825
+ module.cache.occurred[callback] = false;
826
+ }
827
+ }
828
+ else {
829
+ module.cache.occurred = {};
830
+ }
831
+ }
832
+ },
833
+
834
+ save: {
835
+ calculations: function() {
836
+ module.verbose('Saving all calculations necessary to determine positioning');
837
+ module.save.direction();
838
+ module.save.screenCalculations();
839
+ module.save.elementCalculations();
840
+ },
841
+ occurred: function(callback) {
842
+ if(callback) {
843
+ if(module.cache.occurred[callback] === undefined || (module.cache.occurred[callback] !== true)) {
844
+ module.verbose('Saving callback occurred', callback);
845
+ module.cache.occurred[callback] = true;
846
+ }
847
+ }
848
+ },
849
+ scroll: function(scrollPosition) {
850
+ scrollPosition = scrollPosition + settings.offset || $context.scrollTop() + settings.offset;
851
+ module.cache.scroll = scrollPosition;
852
+ },
853
+ direction: function() {
854
+ var
855
+ scroll = module.get.scroll(),
856
+ lastScroll = module.get.lastScroll(),
857
+ direction
858
+ ;
859
+ if(scroll > lastScroll && lastScroll) {
860
+ direction = 'down';
861
+ }
862
+ else if(scroll < lastScroll && lastScroll) {
863
+ direction = 'up';
864
+ }
865
+ else {
866
+ direction = 'static';
867
+ }
868
+ module.cache.direction = direction;
869
+ return module.cache.direction;
870
+ },
871
+ elementPosition: function() {
872
+ var
873
+ element = module.cache.element,
874
+ screen = module.get.screenSize()
875
+ ;
876
+ module.verbose('Saving element position');
877
+ // (quicker than $.extend)
878
+ element.fits = (element.height < screen.height);
879
+ element.offset = $module.offset();
880
+ element.width = $module.outerWidth();
881
+ element.height = $module.outerHeight();
882
+ // store
883
+ module.cache.element = element;
884
+ return element;
885
+ },
886
+ elementCalculations: function() {
887
+ var
888
+ screen = module.get.screenCalculations(),
889
+ element = module.get.elementPosition()
890
+ ;
891
+ // offset
892
+ if(settings.includeMargin) {
893
+ element.margin = {};
894
+ element.margin.top = parseInt($module.css('margin-top'), 10);
895
+ element.margin.bottom = parseInt($module.css('margin-bottom'), 10);
896
+ element.top = element.offset.top - element.margin.top;
897
+ element.bottom = element.offset.top + element.height + element.margin.bottom;
898
+ }
899
+ else {
900
+ element.top = element.offset.top;
901
+ element.bottom = element.offset.top + element.height;
902
+ }
903
+
904
+ // visibility
905
+ element.topVisible = (screen.bottom >= element.top);
906
+ element.topPassed = (screen.top >= element.top);
907
+ element.bottomVisible = (screen.bottom >= element.bottom);
908
+ element.bottomPassed = (screen.top >= element.bottom);
909
+ element.pixelsPassed = 0;
910
+ element.percentagePassed = 0;
911
+
912
+ // meta calculations
913
+ element.onScreen = (element.topVisible && !element.bottomPassed);
914
+ element.passing = (element.topPassed && !element.bottomPassed);
915
+ element.offScreen = (!element.onScreen);
916
+
917
+ // passing calculations
918
+ if(element.passing) {
919
+ element.pixelsPassed = (screen.top - element.top);
920
+ element.percentagePassed = (screen.top - element.top) / element.height;
921
+ }
922
+ module.cache.element = element;
923
+ module.verbose('Updated element calculations', element);
924
+ return element;
925
+ },
926
+ screenCalculations: function() {
927
+ var
928
+ scroll = module.get.scroll()
929
+ ;
930
+ module.save.direction();
931
+ module.cache.screen.top = scroll;
932
+ module.cache.screen.bottom = scroll + module.cache.screen.height;
933
+ return module.cache.screen;
934
+ },
935
+ screenSize: function() {
936
+ module.verbose('Saving window position');
937
+ module.cache.screen = {
938
+ height: $context.height()
939
+ };
940
+ },
941
+ position: function() {
942
+ module.save.screenSize();
943
+ module.save.elementPosition();
944
+ }
945
+ },
946
+
947
+ get: {
948
+ pixelsPassed: function(amount) {
949
+ var
950
+ element = module.get.elementCalculations()
951
+ ;
952
+ if(amount.search('%') > -1) {
953
+ return ( element.height * (parseInt(amount, 10) / 100) );
954
+ }
955
+ return parseInt(amount, 10);
956
+ },
957
+ occurred: function(callback) {
958
+ return (module.cache.occurred !== undefined)
959
+ ? module.cache.occurred[callback] || false
960
+ : false
961
+ ;
962
+ },
963
+ direction: function() {
964
+ if(module.cache.direction === undefined) {
965
+ module.save.direction();
966
+ }
967
+ return module.cache.direction;
968
+ },
969
+ elementPosition: function() {
970
+ if(module.cache.element === undefined) {
971
+ module.save.elementPosition();
972
+ }
973
+ return module.cache.element;
974
+ },
975
+ elementCalculations: function() {
976
+ if(module.cache.element === undefined) {
977
+ module.save.elementCalculations();
978
+ }
979
+ return module.cache.element;
980
+ },
981
+ screenCalculations: function() {
982
+ if(module.cache.screen === undefined) {
983
+ module.save.screenCalculations();
984
+ }
985
+ return module.cache.screen;
986
+ },
987
+ screenSize: function() {
988
+ if(module.cache.screen === undefined) {
989
+ module.save.screenSize();
990
+ }
991
+ return module.cache.screen;
992
+ },
993
+ scroll: function() {
994
+ if(module.cache.scroll === undefined) {
995
+ module.save.scroll();
996
+ }
997
+ return module.cache.scroll;
998
+ },
999
+ lastScroll: function() {
1000
+ if(module.cache.screen === undefined) {
1001
+ module.debug('First scroll event, no last scroll could be found');
1002
+ return false;
1003
+ }
1004
+ return module.cache.screen.top;
1005
+ }
1006
+ },
1007
+
1008
+ setting: function(name, value) {
1009
+ if( $.isPlainObject(name) ) {
1010
+ $.extend(true, settings, name);
1011
+ }
1012
+ else if(value !== undefined) {
1013
+ settings[name] = value;
1014
+ }
1015
+ else {
1016
+ return settings[name];
1017
+ }
1018
+ },
1019
+ internal: function(name, value) {
1020
+ if( $.isPlainObject(name) ) {
1021
+ $.extend(true, module, name);
1022
+ }
1023
+ else if(value !== undefined) {
1024
+ module[name] = value;
1025
+ }
1026
+ else {
1027
+ return module[name];
1028
+ }
1029
+ },
1030
+ debug: function() {
1031
+ if(!settings.silent && settings.debug) {
1032
+ if(settings.performance) {
1033
+ module.performance.log(arguments);
1034
+ }
1035
+ else {
1036
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1037
+ module.debug.apply(console, arguments);
1038
+ }
1039
+ }
1040
+ },
1041
+ verbose: function() {
1042
+ if(!settings.silent && settings.verbose && settings.debug) {
1043
+ if(settings.performance) {
1044
+ module.performance.log(arguments);
1045
+ }
1046
+ else {
1047
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1048
+ module.verbose.apply(console, arguments);
1049
+ }
1050
+ }
1051
+ },
1052
+ error: function() {
1053
+ if(!settings.silent) {
1054
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1055
+ module.error.apply(console, arguments);
1056
+ }
1057
+ },
1058
+ performance: {
1059
+ log: function(message) {
1060
+ var
1061
+ currentTime,
1062
+ executionTime,
1063
+ previousTime
1064
+ ;
1065
+ if(settings.performance) {
1066
+ currentTime = new Date().getTime();
1067
+ previousTime = time || currentTime;
1068
+ executionTime = currentTime - previousTime;
1069
+ time = currentTime;
1070
+ performance.push({
1071
+ 'Name' : message[0],
1072
+ 'Arguments' : [].slice.call(message, 1) || '',
1073
+ 'Element' : element,
1074
+ 'Execution Time' : executionTime
1075
+ });
1076
+ }
1077
+ clearTimeout(module.performance.timer);
1078
+ module.performance.timer = setTimeout(module.performance.display, 500);
1079
+ },
1080
+ display: function() {
1081
+ var
1082
+ title = settings.name + ':',
1083
+ totalTime = 0
1084
+ ;
1085
+ time = false;
1086
+ clearTimeout(module.performance.timer);
1087
+ $.each(performance, function(index, data) {
1088
+ totalTime += data['Execution Time'];
1089
+ });
1090
+ title += ' ' + totalTime + 'ms';
1091
+ if(moduleSelector) {
1092
+ title += ' \'' + moduleSelector + '\'';
1093
+ }
1094
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
1095
+ console.groupCollapsed(title);
1096
+ if(console.table) {
1097
+ console.table(performance);
1098
+ }
1099
+ else {
1100
+ $.each(performance, function(index, data) {
1101
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1102
+ });
1103
+ }
1104
+ console.groupEnd();
1105
+ }
1106
+ performance = [];
1107
+ }
1108
+ },
1109
+ invoke: function(query, passedArguments, context) {
1110
+ var
1111
+ object = instance,
1112
+ maxDepth,
1113
+ found,
1114
+ response
1115
+ ;
1116
+ passedArguments = passedArguments || queryArguments;
1117
+ context = element || context;
1118
+ if(typeof query == 'string' && object !== undefined) {
1119
+ query = query.split(/[\. ]/);
1120
+ maxDepth = query.length - 1;
1121
+ $.each(query, function(depth, value) {
1122
+ var camelCaseValue = (depth != maxDepth)
1123
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1124
+ : query
1125
+ ;
1126
+ if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
1127
+ object = object[camelCaseValue];
1128
+ }
1129
+ else if( object[camelCaseValue] !== undefined ) {
1130
+ found = object[camelCaseValue];
1131
+ return false;
1132
+ }
1133
+ else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
1134
+ object = object[value];
1135
+ }
1136
+ else if( object[value] !== undefined ) {
1137
+ found = object[value];
1138
+ return false;
1139
+ }
1140
+ else {
1141
+ module.error(error.method, query);
1142
+ return false;
1143
+ }
1144
+ });
1145
+ }
1146
+ if ( $.isFunction( found ) ) {
1147
+ response = found.apply(context, passedArguments);
1148
+ }
1149
+ else if(found !== undefined) {
1150
+ response = found;
1151
+ }
1152
+ if($.isArray(returnedValue)) {
1153
+ returnedValue.push(response);
1154
+ }
1155
+ else if(returnedValue !== undefined) {
1156
+ returnedValue = [returnedValue, response];
1157
+ }
1158
+ else if(response !== undefined) {
1159
+ returnedValue = response;
1160
+ }
1161
+ return found;
1162
+ }
1163
+ };
1164
+
1165
+ if(methodInvoked) {
1166
+ if(instance === undefined) {
1167
+ module.initialize();
1168
+ }
1169
+ instance.save.scroll();
1170
+ instance.save.calculations();
1171
+ module.invoke(query);
1172
+ }
1173
+ else {
1174
+ if(instance !== undefined) {
1175
+ instance.invoke('destroy');
1176
+ }
1177
+ module.initialize();
1178
+ }
1179
+ })
1180
+ ;
1181
+
1182
+ return (returnedValue !== undefined)
1183
+ ? returnedValue
1184
+ : this
1185
+ ;
1186
+ };
1187
+
1188
+ $.fn.visibility.settings = {
1189
+
1190
+ name : 'Visibility',
1191
+ namespace : 'visibility',
1192
+
1193
+ debug : false,
1194
+ verbose : false,
1195
+ performance : true,
1196
+
1197
+ // whether to use mutation observers to follow changes
1198
+ observeChanges : true,
1199
+
1200
+ // check position immediately on init
1201
+ initialCheck : true,
1202
+
1203
+ // whether to refresh calculations after all page images load
1204
+ refreshOnLoad : true,
1205
+
1206
+ // whether to refresh calculations after page resize event
1207
+ refreshOnResize : true,
1208
+
1209
+ // should call callbacks on refresh event (resize, etc)
1210
+ checkOnRefresh : true,
1211
+
1212
+ // callback should only occur one time
1213
+ once : true,
1214
+
1215
+ // callback should fire continuously whe evaluates to true
1216
+ continuous : false,
1217
+
1218
+ // offset to use with scroll top
1219
+ offset : 0,
1220
+
1221
+ // whether to include margin in elements position
1222
+ includeMargin : false,
1223
+
1224
+ // scroll context for visibility checks
1225
+ context : window,
1226
+
1227
+ // visibility check delay in ms (defaults to animationFrame)
1228
+ throttle : false,
1229
+
1230
+ // special visibility type (image, fixed)
1231
+ type : false,
1232
+
1233
+ // z-index to use with visibility 'fixed'
1234
+ zIndex : '10',
1235
+
1236
+ // image only animation settings
1237
+ transition : 'fade in',
1238
+ duration : 1000,
1239
+
1240
+ // array of callbacks for percentage
1241
+ onPassed : {},
1242
+
1243
+ // standard callbacks
1244
+ onOnScreen : false,
1245
+ onOffScreen : false,
1246
+ onPassing : false,
1247
+ onTopVisible : false,
1248
+ onBottomVisible : false,
1249
+ onTopPassed : false,
1250
+ onBottomPassed : false,
1251
+
1252
+ // reverse callbacks
1253
+ onPassingReverse : false,
1254
+ onTopVisibleReverse : false,
1255
+ onBottomVisibleReverse : false,
1256
+ onTopPassedReverse : false,
1257
+ onBottomPassedReverse : false,
1258
+
1259
+ // special callbacks for image
1260
+ onLoad : function() {},
1261
+ onAllLoaded : function() {},
1262
+
1263
+ // special callbacks for fixed position
1264
+ onFixed : function() {},
1265
+ onUnfixed : function() {},
1266
+
1267
+ // utility callbacks
1268
+ onUpdate : false, // disabled by default for performance
1269
+ onRefresh : function(){},
1270
+
1271
+ metadata : {
1272
+ src: 'src'
1273
+ },
1274
+
1275
+ className: {
1276
+ fixed : 'fixed',
1277
+ placeholder : 'placeholder',
1278
+ visible : 'visible'
1279
+ },
1280
+
1281
+ error : {
1282
+ method : 'The method you called is not defined.',
1283
+ visible : 'Element is hidden, you must call refresh after element becomes visible'
1284
+ }
1285
+
1286
+ };
1287
+
1288
+ })( jQuery, window, document );