uikit-rails 0.0.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -3
  3. data/Gemfile +2 -1
  4. data/LICENSE.txt +21 -0
  5. data/README.md +65 -0
  6. data/Rakefile +0 -1
  7. data/assets/fonts/FontAwesome.otf +0 -0
  8. data/assets/fonts/fontawesome-webfont.ttf +0 -0
  9. data/assets/fonts/fontawesome-webfont.woff +0 -0
  10. data/assets/fonts/fontawesome-webfont.woff2 +0 -0
  11. data/assets/javascripts/components/accordion.js +174 -0
  12. data/assets/javascripts/components/accordion.min.js +2 -0
  13. data/assets/javascripts/components/autocomplete.js +334 -0
  14. data/assets/javascripts/components/autocomplete.min.js +2 -0
  15. data/assets/javascripts/components/datepicker.js +3166 -0
  16. data/assets/javascripts/components/datepicker.min.js +3 -0
  17. data/assets/javascripts/components/form-password.js +67 -0
  18. data/assets/javascripts/components/form-password.min.js +2 -0
  19. data/assets/javascripts/components/form-select.js +70 -0
  20. data/assets/javascripts/components/form-select.min.js +2 -0
  21. data/assets/javascripts/components/grid.js +527 -0
  22. data/assets/javascripts/components/grid.min.js +2 -0
  23. data/assets/javascripts/components/htmleditor.js +623 -0
  24. data/assets/javascripts/components/htmleditor.min.js +2 -0
  25. data/assets/javascripts/components/lightbox.js +555 -0
  26. data/assets/javascripts/components/lightbox.min.js +2 -0
  27. data/assets/javascripts/components/nestable.js +638 -0
  28. data/assets/javascripts/components/nestable.min.js +2 -0
  29. data/assets/javascripts/components/notify.js +189 -0
  30. data/assets/javascripts/components/notify.min.js +2 -0
  31. data/assets/javascripts/components/pagination.js +147 -0
  32. data/assets/javascripts/components/pagination.min.js +2 -0
  33. data/assets/javascripts/components/parallax.js +435 -0
  34. data/assets/javascripts/components/parallax.min.js +2 -0
  35. data/assets/javascripts/components/search.js +92 -0
  36. data/assets/javascripts/components/search.min.js +2 -0
  37. data/assets/javascripts/components/slider.js +531 -0
  38. data/assets/javascripts/components/slider.min.js +2 -0
  39. data/assets/javascripts/components/slideset.js +506 -0
  40. data/assets/javascripts/components/slideset.min.js +2 -0
  41. data/assets/javascripts/components/slideshow-fx.js +375 -0
  42. data/assets/javascripts/components/slideshow-fx.min.js +2 -0
  43. data/assets/javascripts/components/slideshow.js +562 -0
  44. data/assets/javascripts/components/slideshow.min.js +2 -0
  45. data/assets/javascripts/components/sortable.js +688 -0
  46. data/assets/javascripts/components/sortable.min.js +2 -0
  47. data/assets/javascripts/components/sticky.js +359 -0
  48. data/assets/javascripts/components/sticky.min.js +2 -0
  49. data/assets/javascripts/components/timepicker.js +192 -0
  50. data/assets/javascripts/components/timepicker.min.js +2 -0
  51. data/assets/javascripts/components/tooltip.js +234 -0
  52. data/assets/javascripts/components/tooltip.min.js +2 -0
  53. data/assets/javascripts/components/upload.js +260 -0
  54. data/assets/javascripts/components/upload.min.js +2 -0
  55. data/assets/javascripts/core/alert.js +66 -0
  56. data/assets/javascripts/core/alert.min.js +2 -0
  57. data/assets/javascripts/core/button.js +157 -0
  58. data/assets/javascripts/core/button.min.js +2 -0
  59. data/assets/javascripts/core/core.js +730 -0
  60. data/assets/javascripts/core/core.min.js +2 -0
  61. data/assets/javascripts/core/cover.js +95 -0
  62. data/assets/javascripts/core/cover.min.js +2 -0
  63. data/assets/javascripts/core/dropdown.js +514 -0
  64. data/assets/javascripts/core/dropdown.min.js +2 -0
  65. data/assets/javascripts/core/grid.js +114 -0
  66. data/assets/javascripts/core/grid.min.js +2 -0
  67. data/assets/javascripts/core/modal.js +384 -0
  68. data/assets/javascripts/core/modal.min.js +2 -0
  69. data/assets/javascripts/core/nav.js +136 -0
  70. data/assets/javascripts/core/nav.min.js +2 -0
  71. data/assets/javascripts/core/offcanvas.js +180 -0
  72. data/assets/javascripts/core/offcanvas.min.js +2 -0
  73. data/assets/javascripts/core/scrollspy.js +208 -0
  74. data/assets/javascripts/core/scrollspy.min.js +2 -0
  75. data/assets/javascripts/core/smooth-scroll.js +62 -0
  76. data/assets/javascripts/core/smooth-scroll.min.js +2 -0
  77. data/assets/javascripts/core/switcher.js +309 -0
  78. data/assets/javascripts/core/switcher.min.js +2 -0
  79. data/assets/javascripts/core/tab.js +167 -0
  80. data/assets/javascripts/core/tab.min.js +2 -0
  81. data/assets/javascripts/core/toggle.js +120 -0
  82. data/assets/javascripts/core/toggle.min.js +2 -0
  83. data/assets/javascripts/core/touch.js +175 -0
  84. data/assets/javascripts/core/touch.min.js +2 -0
  85. data/assets/javascripts/core/utility.js +289 -0
  86. data/assets/javascripts/core/utility.min.js +2 -0
  87. data/assets/javascripts/uikit-components.js +23 -0
  88. data/assets/javascripts/uikit.js +3706 -0
  89. data/assets/javascripts/uikit.min.js +3 -0
  90. data/assets/stylesheets/components/accordion.scss +94 -0
  91. data/assets/stylesheets/components/autocomplete.scss +102 -0
  92. data/assets/stylesheets/components/datepicker.scss +197 -0
  93. data/assets/stylesheets/components/dotnav.scss +212 -0
  94. data/assets/stylesheets/components/form-advanced.scss +128 -0
  95. data/assets/stylesheets/components/form-file.scss +63 -0
  96. data/assets/stylesheets/components/form-password.scss +74 -0
  97. data/assets/stylesheets/components/form-select.scss +66 -0
  98. data/assets/stylesheets/components/htmleditor.scss +269 -0
  99. data/assets/stylesheets/components/nestable.scss +229 -0
  100. data/assets/stylesheets/components/notify.scss +190 -0
  101. data/assets/stylesheets/components/placeholder.scss +66 -0
  102. data/assets/stylesheets/components/progress.scss +173 -0
  103. data/assets/stylesheets/components/search.scss +309 -0
  104. data/assets/stylesheets/components/slidenav.scss +183 -0
  105. data/assets/stylesheets/components/slider.scss +131 -0
  106. data/assets/stylesheets/components/slideshow.scss +208 -0
  107. data/assets/stylesheets/components/sortable.scss +122 -0
  108. data/assets/stylesheets/components/sticky.scss +64 -0
  109. data/assets/stylesheets/components/tooltip.scss +177 -0
  110. data/assets/stylesheets/components/upload.scss +34 -0
  111. data/assets/stylesheets/core/alert.scss +141 -0
  112. data/assets/stylesheets/core/animation.scss +599 -0
  113. data/assets/stylesheets/core/article.scss +139 -0
  114. data/assets/stylesheets/core/badge.scss +110 -0
  115. data/assets/stylesheets/core/base-noconflict.scss +397 -0
  116. data/assets/stylesheets/core/base.scss +541 -0
  117. data/assets/stylesheets/core/block.scss +153 -0
  118. data/assets/stylesheets/core/breadcrumb.scss +86 -0
  119. data/assets/stylesheets/core/button.scss +406 -0
  120. data/assets/stylesheets/core/close.scss +132 -0
  121. data/assets/stylesheets/core/column.scss +209 -0
  122. data/assets/stylesheets/core/comment.scss +172 -0
  123. data/assets/stylesheets/core/contrast.scss +493 -0
  124. data/assets/stylesheets/core/cover.scss +70 -0
  125. data/assets/stylesheets/core/description-list.scss +71 -0
  126. data/assets/stylesheets/core/dropdown.scss +280 -0
  127. data/assets/stylesheets/core/flex.scss +320 -0
  128. data/assets/stylesheets/core/form.scss +627 -0
  129. data/assets/stylesheets/core/grid.scss +688 -0
  130. data/assets/stylesheets/core/icon.scss +897 -0
  131. data/assets/stylesheets/core/list.scss +102 -0
  132. data/assets/stylesheets/core/modal.scss +341 -0
  133. data/assets/stylesheets/core/nav.scss +468 -0
  134. data/assets/stylesheets/core/navbar.scss +325 -0
  135. data/assets/stylesheets/core/offcanvas.scss +168 -0
  136. data/assets/stylesheets/core/overlay.scss +534 -0
  137. data/assets/stylesheets/core/pagination.scss +197 -0
  138. data/assets/stylesheets/core/panel.scss +332 -0
  139. data/assets/stylesheets/core/print.scss +59 -0
  140. data/assets/stylesheets/core/subnav.scss +213 -0
  141. data/assets/stylesheets/core/switcher.scss +38 -0
  142. data/assets/stylesheets/core/tab.scss +368 -0
  143. data/assets/stylesheets/core/table.scss +147 -0
  144. data/assets/stylesheets/core/text.scss +128 -0
  145. data/assets/stylesheets/core/thumbnail.scss +122 -0
  146. data/assets/stylesheets/core/thumbnav.scss +122 -0
  147. data/assets/stylesheets/core/utility.scss +606 -0
  148. data/assets/stylesheets/core/variables.scss +23 -0
  149. data/assets/stylesheets/uikit-components.scss +22 -0
  150. data/assets/stylesheets/uikit-mixins.scss +327 -0
  151. data/assets/stylesheets/uikit-variables.scss +817 -0
  152. data/assets/stylesheets/uikit.scss +56 -0
  153. data/lib/uikit-rails.rb +2 -2
  154. data/lib/uikit-rails/engine.rb +11 -1
  155. data/lib/uikit-rails/version.rb +1 -3
  156. data/uikit-rails.gemspec +15 -16
  157. metadata +169 -44
  158. data/README.rb +0 -1
  159. data/vendor/assets/javascripts/ui.card.js +0 -115
  160. data/vendor/assets/javascripts/ui.color-picker.js +0 -351
  161. data/vendor/assets/javascripts/ui.confirmation.js +0 -133
  162. data/vendor/assets/javascripts/ui.dialog.js +0 -252
  163. data/vendor/assets/javascripts/ui.emitter.js +0 -99
  164. data/vendor/assets/javascripts/ui.js +0 -1641
  165. data/vendor/assets/javascripts/ui.menu.js +0 -238
  166. data/vendor/assets/javascripts/ui.notification.js +0 -240
  167. data/vendor/assets/javascripts/ui.overlay.js +0 -79
  168. data/vendor/assets/javascripts/ui.split-button.js +0 -108
  169. data/vendor/assets/stylesheets/ui.card.css +0 -55
  170. data/vendor/assets/stylesheets/ui.color-picker.css +0 -6
  171. data/vendor/assets/stylesheets/ui.confirmation.css +0 -7
  172. data/vendor/assets/stylesheets/ui.css +0 -337
  173. data/vendor/assets/stylesheets/ui.dialog.css +0 -92
  174. data/vendor/assets/stylesheets/ui.menu.css +0 -32
  175. data/vendor/assets/stylesheets/ui.notification.css +0 -107
  176. data/vendor/assets/stylesheets/ui.overlay.css +0 -16
  177. data/vendor/assets/stylesheets/ui.split-button.css +0 -27
@@ -0,0 +1,2 @@
1
+ /*! UIkit 2.24.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
+ !function(i){var t;window.UIkit&&(t=i(UIkit)),"function"==typeof define&&define.amd&&define("uikit-lightbox",["uikit"],function(){return t||i(UIkit)})}(function(i){"use strict";function t(t){return e?(e.lightbox=t,e):(e=i.$(['<div class="uk-modal">','<div class="uk-modal-dialog uk-modal-dialog-lightbox uk-slidenav-position" style="margin-left:auto;margin-right:auto;width:200px;height:200px;top:'+Math.abs(window.innerHeight/2-200)+'px;">','<a href="#" class="uk-modal-close uk-close uk-close-alt"></a>','<div class="uk-lightbox-content"></div>','<div class="uk-modal-spinner uk-hidden"></div>',"</div>","</div>"].join("")).appendTo("body"),e.dialog=e.find(".uk-modal-dialog:first"),e.content=e.find(".uk-lightbox-content:first"),e.loader=e.find(".uk-modal-spinner:first"),e.closer=e.find(".uk-close.uk-close-alt"),e.modal=i.modal(e,{modal:!1}),e.on("swipeRight swipeLeft",function(i){e.lightbox["swipeLeft"==i.type?"next":"previous"]()}).on("click","[data-lightbox-previous], [data-lightbox-next]",function(t){t.preventDefault(),e.lightbox[i.$(this).is("[data-lightbox-next]")?"next":"previous"]()}),e.on("hide.uk.modal",function(){e.content.html("")}),i.$win.on("load resize orientationchange",i.Utils.debounce(function(){e.is(":visible")&&!i.Utils.isFullscreen()&&e.lightbox.fitSize()}.bind(this),100)),e.lightbox=t,e)}var e,o={};return i.component("lightbox",{defaults:{group:!1,duration:400,keyboard:!0},index:0,items:!1,boot:function(){i.$html.on("click","[data-uk-lightbox]",function(t){t.preventDefault();var e=i.$(this);e.data("lightbox")||i.lightbox(e,i.Utils.options(e.attr("data-uk-lightbox"))),e.data("lightbox").show(e)}),i.$doc.on("keyup",function(i){if(e&&e.is(":visible")&&e.lightbox.options.keyboard)switch(i.preventDefault(),i.keyCode){case 37:e.lightbox.previous();break;case 39:e.lightbox.next()}})},init:function(){var t=[];if(this.index=0,this.siblings=[],this.element&&this.element.length){var e=this.options.group?i.$(['[data-uk-lightbox*="'+this.options.group+'"]',"[data-uk-lightbox*='"+this.options.group+"']"].join(",")):this.element;e.each(function(){var e=i.$(this);t.push({source:e.attr("href"),title:e.attr("title"),type:e.attr("data-lightbox-type")||"auto",link:e})}),this.index=e.index(this.element),this.siblings=t}else this.options.group&&this.options.group.length&&(this.siblings=this.options.group);this.trigger("lightbox-init",[this])},show:function(e){this.modal=t(this),this.modal.dialog.stop(),this.modal.content.stop();var o,n,s=this,h=i.$.Deferred();e=e||0,"object"==typeof e&&this.siblings.forEach(function(i,t){e[0]===i.link[0]&&(e=t)}),0>e?e=this.siblings.length-e:this.siblings[e]||(e=0),n=this.siblings[e],o={lightbox:s,source:n.source,type:n.type,index:e,promise:h,title:n.title,item:n,meta:{content:"",width:null,height:null}},this.index=e,this.modal.content.empty(),this.modal.is(":visible")||(this.modal.content.css({width:"",height:""}).empty(),this.modal.modal.show()),this.modal.loader.removeClass("uk-hidden"),h.promise().done(function(){s.data=o,s.fitSize(o)}).fail(function(){o.meta.content='<div class="uk-position-cover uk-flex uk-flex-middle uk-flex-center"><strong>Loading resource failed!</strong></div>',o.meta.width=400,o.meta.height=300,s.data=o,s.fitSize(o)}),s.trigger("showitem.uk.lightbox",[o])},fitSize:function(){var t=this,e=this.data,o=this.modal.dialog.outerWidth()-this.modal.dialog.width(),n=parseInt(this.modal.dialog.css("margin-top"),10),s=parseInt(this.modal.dialog.css("margin-bottom"),10),h=n+s,a=e.meta.content,d=t.options.duration;this.siblings.length>1&&(a=[a,'<a href="#" class="uk-slidenav uk-slidenav-contrast uk-slidenav-previous uk-hidden-touch" data-lightbox-previous></a>','<a href="#" class="uk-slidenav uk-slidenav-contrast uk-slidenav-next uk-hidden-touch" data-lightbox-next></a>'].join(""));var l,r,u=i.$("<div>&nbsp;</div>").css({opacity:0,position:"absolute",top:0,left:0,width:"100%","max-width":t.modal.dialog.css("max-width"),padding:t.modal.dialog.css("padding"),margin:t.modal.dialog.css("margin")}),c=e.meta.width,g=e.meta.height;u.appendTo("body").width(),l=u.width(),r=window.innerHeight-h,u.remove(),this.modal.dialog.find(".uk-modal-caption").remove(),e.title&&(this.modal.dialog.append('<div class="uk-modal-caption">'+e.title+"</div>"),r-=this.modal.dialog.find(".uk-modal-caption").outerHeight()),l<e.meta.width&&(g=Math.floor(g*(l/c)),c=l),g>r&&(g=Math.floor(r),c=Math.ceil(e.meta.width*(r/e.meta.height))),this.modal.content.css("opacity",0).width(c).html(a),"iframe"==e.type&&this.modal.content.find("iframe:first").height(g);var m=g+o,p=Math.floor(window.innerHeight/2-m/2)-h;0>p&&(p=0),this.modal.closer.addClass("uk-hidden"),t.modal.data("mwidth")==c&&t.modal.data("mheight")==g&&(d=0),this.modal.dialog.animate({width:c+o,height:g+o,top:p},d,"swing",function(){t.modal.loader.addClass("uk-hidden"),t.modal.content.css({width:""}).animate({opacity:1},function(){t.modal.closer.removeClass("uk-hidden")}),t.modal.data({mwidth:c,mheight:g})})},next:function(){this.show(this.siblings[this.index+1]?this.index+1:0)},previous:function(){this.show(this.siblings[this.index-1]?this.index-1:this.siblings.length-1)}}),i.plugin("lightbox","image",{init:function(i){i.on("showitem.uk.lightbox",function(i,t){if("image"==t.type||t.source&&t.source.match(/\.(jpg|jpeg|png|gif|svg)$/i)){var e=function(i,e,o){t.meta={content:'<img class="uk-responsive-width" width="'+e+'" height="'+o+'" src ="'+i+'">',width:e,height:o},t.type="image",t.promise.resolve()};if(o[t.source])e(t.source,o[t.source].width,o[t.source].height);else{var n=new Image;n.onerror=function(){t.promise.reject("Loading image failed")},n.onload=function(){o[t.source]={width:n.width,height:n.height},e(t.source,o[t.source].width,o[t.source].height)},n.src=t.source}}})}}),i.plugin("lightbox","youtube",{init:function(i){var t=/(\/\/.*?youtube\.[a-z]+)\/watch\?v=([^&]+)&?(.*)/,e=/youtu\.be\/(.*)/;i.on("showitem.uk.lightbox",function(i,n){var s,h,a=function(i,t,e){n.meta={content:'<iframe src="//www.youtube.com/embed/'+i+'" width="'+t+'" height="'+e+'" style="max-width:100%;"></iframe>',width:t,height:e},n.type="iframe",n.promise.resolve()};if((h=n.source.match(t))&&(s=h[2]),(h=n.source.match(e))&&(s=h[1]),s){if(o[s])a(s,o[s].width,o[s].height);else{var d=new Image,l=!1;d.onerror=function(){o[s]={width:640,height:320},a(s,o[s].width,o[s].height)},d.onload=function(){120==d.width&&90==d.height?l?(o[s]={width:640,height:320},a(s,o[s].width,o[s].height)):(l=!0,d.src="//img.youtube.com/vi/"+s+"/0.jpg"):(o[s]={width:d.width,height:d.height},a(s,d.width,d.height))},d.src="//img.youtube.com/vi/"+s+"/maxresdefault.jpg"}i.stopImmediatePropagation()}})}}),i.plugin("lightbox","vimeo",{init:function(t){var e,n=/(\/\/.*?)vimeo\.[a-z]+\/([0-9]+).*?/;t.on("showitem.uk.lightbox",function(t,s){var h,a=function(i,t,e){s.meta={content:'<iframe src="//player.vimeo.com/video/'+i+'" width="'+t+'" height="'+e+'" style="width:100%;box-sizing:border-box;"></iframe>',width:t,height:e},s.type="iframe",s.promise.resolve()};(e=s.source.match(n))&&(h=e[2],o[h]?a(h,o[h].width,o[h].height):i.$.ajax({type:"GET",url:"http://vimeo.com/api/oembed.json?url="+encodeURI(s.source),jsonp:"callback",dataType:"jsonp",success:function(i){o[h]={width:i.width,height:i.height},a(h,o[h].width,o[h].height)}}),t.stopImmediatePropagation())})}}),i.plugin("lightbox","video",{init:function(t){t.on("showitem.uk.lightbox",function(t,e){var n=function(i,t,o){e.meta={content:'<video class="uk-responsive-width" src="'+i+'" width="'+t+'" height="'+o+'" controls></video>',width:t,height:o},e.type="video",e.promise.resolve()};if("video"==e.type||e.source.match(/\.(mp4|webm|ogv)$/i))if(o[e.source])n(e.source,o[e.source].width,o[e.source].height);else var s=i.$('<video style="position:fixed;visibility:hidden;top:-10000px;"></video>').attr("src",e.source).appendTo("body"),h=setInterval(function(){s[0].videoWidth&&(clearInterval(h),o[e.source]={width:s[0].videoWidth,height:s[0].videoHeight},n(e.source,o[e.source].width,o[e.source].height),s.remove())},20)})}}),i.lightbox.create=function(t,e){if(t){var o,n=[];return t.forEach(function(t){n.push(i.$.extend({source:"",title:"",type:"auto",link:!1},"string"==typeof t?{source:t}:t))}),o=i.lightbox(i.$.extend({},e,{group:n}))}},i.lightbox});
@@ -0,0 +1,638 @@
1
+ /*! UIkit 2.24.2 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
+ /*
3
+ * Based on Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
4
+ */
5
+ (function(addon) {
6
+
7
+ var component;
8
+
9
+ if (window.UIkit) {
10
+ component = addon(UIkit);
11
+ }
12
+
13
+ if (typeof define == "function" && define.amd) {
14
+ define("uikit-nestable", ["uikit"], function(){
15
+ return component || addon(UIkit);
16
+ });
17
+ }
18
+
19
+ })(function(UI) {
20
+
21
+ "use strict";
22
+
23
+ var hasTouch = 'ontouchstart' in window,
24
+ html = UI.$html,
25
+ touchedlists = [],
26
+ $win = UI.$win,
27
+ draggingElement;
28
+
29
+ var eStart = hasTouch ? 'touchstart' : 'mousedown',
30
+ eMove = hasTouch ? 'touchmove' : 'mousemove',
31
+ eEnd = hasTouch ? 'touchend' : 'mouseup',
32
+ eCancel = hasTouch ? 'touchcancel' : 'mouseup';
33
+
34
+
35
+ UI.component('nestable', {
36
+
37
+ defaults: {
38
+ listBaseClass : 'uk-nestable',
39
+ listClass : 'uk-nestable-list',
40
+ listItemClass : 'uk-nestable-item',
41
+ dragClass : 'uk-nestable-dragged',
42
+ movingClass : 'uk-nestable-moving',
43
+ emptyClass : 'uk-nestable-empty',
44
+ handleClass : '',
45
+ collapsedClass : 'uk-collapsed',
46
+ placeholderClass: 'uk-nestable-placeholder',
47
+ noDragClass : 'uk-nestable-nodrag',
48
+ group : false,
49
+ maxDepth : 10,
50
+ threshold : 20,
51
+ idlethreshold : 10,
52
+ },
53
+
54
+ boot: function() {
55
+
56
+ // adjust document scrolling
57
+ UI.$html.on('mousemove touchmove', function(e) {
58
+
59
+ if (draggingElement) {
60
+
61
+ var top = draggingElement.offset().top;
62
+
63
+ if (top < UI.$win.scrollTop()) {
64
+ UI.$win.scrollTop(UI.$win.scrollTop() - Math.ceil(draggingElement.height()/2));
65
+ } else if ( (top + draggingElement.height()) > (window.innerHeight + UI.$win.scrollTop()) ) {
66
+ UI.$win.scrollTop(UI.$win.scrollTop() + Math.ceil(draggingElement.height()/2));
67
+ }
68
+ }
69
+ });
70
+
71
+ // init code
72
+ UI.ready(function(context) {
73
+
74
+ UI.$("[data-uk-nestable]", context).each(function(){
75
+
76
+ var ele = UI.$(this);
77
+
78
+ if (!ele.data("nestable")) {
79
+ UI.nestable(ele, UI.Utils.options(ele.attr("data-uk-nestable")));
80
+ }
81
+ });
82
+ });
83
+ },
84
+
85
+ init: function() {
86
+
87
+ var $this = this;
88
+
89
+ Object.keys(this.options).forEach(function(key){
90
+
91
+ if(String(key).indexOf('Class')!=-1) {
92
+ $this.options['_'+key] = '.' + $this.options[key];
93
+ }
94
+ });
95
+
96
+ this.find(this.options._listItemClass).find(">ul").addClass(this.options.listClass);
97
+
98
+ this.checkEmptyList();
99
+
100
+ this.reset();
101
+ this.element.data('nestable-group', this.options.group || UI.Utils.uid('nestable-group'));
102
+
103
+ this.find(this.options._listItemClass).each(function() {
104
+ $this.setParent(UI.$(this));
105
+ });
106
+
107
+ this.on('click', '[data-nestable-action]', function(e) {
108
+
109
+ if ($this.dragEl || (!hasTouch && e.button !== 0)) {
110
+ return;
111
+ }
112
+
113
+ e.preventDefault();
114
+
115
+ var target = UI.$(e.currentTarget),
116
+ action = target.data('nestableAction'),
117
+ item = target.closest($this.options._listItemClass);
118
+
119
+ if (action === 'collapse') {
120
+ $this.collapseItem(item);
121
+ }
122
+ if (action === 'expand') {
123
+ $this.expandItem(item);
124
+ }
125
+ if (action === 'toggle') {
126
+ $this.toggleItem(item);
127
+ }
128
+ });
129
+
130
+ var onStartEvent = function(e) {
131
+
132
+ var handle = UI.$(e.target);
133
+
134
+ if (e.target === $this.element[0]) {
135
+ return;
136
+ }
137
+
138
+ if (handle.is($this.options._noDragClass) || handle.closest($this.options._noDragClass).length) {
139
+ return;
140
+ }
141
+
142
+ if (handle.is('[data-nestable-action]') || handle.closest('[data-nestable-action]').length) {
143
+ return;
144
+ }
145
+
146
+ if ($this.options.handleClass && !handle.hasClass($this.options.handleClass)) {
147
+
148
+ if ($this.options.handleClass) {
149
+ handle = handle.closest($this.options._handleClass);
150
+ }
151
+ }
152
+
153
+ if (!handle.length || $this.dragEl || (!hasTouch && e.button !== 0) || (hasTouch && e.touches.length !== 1)) {
154
+ return;
155
+ }
156
+
157
+ if (e.originalEvent && e.originalEvent.touches) {
158
+ e = evt.originalEvent.touches[0];
159
+ }
160
+
161
+ $this.delayMove = function(evt) {
162
+
163
+ evt.preventDefault();
164
+ $this.dragStart(e);
165
+ $this.trigger('start.uk.nestable', [$this]);
166
+
167
+ $this.delayMove = false;
168
+ };
169
+
170
+ $this.delayMove.x = parseInt(e.pageX, 10);
171
+ $this.delayMove.y = parseInt(e.pageY, 10);
172
+ $this.delayMove.threshold = $this.options.idlethreshold;
173
+
174
+ e.preventDefault();
175
+ };
176
+
177
+ var onMoveEvent = function(e) {
178
+
179
+ if (e.originalEvent && e.originalEvent.touches) {
180
+ e = e.originalEvent.touches[0];
181
+ }
182
+
183
+ if ($this.delayMove && (Math.abs(e.pageX - $this.delayMove.x) > $this.delayMove.threshold || Math.abs(e.pageY - $this.delayMove.y) > $this.delayMove.threshold)) {
184
+
185
+ if (!window.getSelection().toString()) {
186
+ $this.delayMove(e);
187
+ } else {
188
+ $this.delayMove = false;
189
+ }
190
+ }
191
+
192
+ if ($this.dragEl) {
193
+ e.preventDefault();
194
+ $this.dragMove(e);
195
+ $this.trigger('move.uk.nestable', [$this]);
196
+ }
197
+ };
198
+
199
+ var onEndEvent = function(e) {
200
+
201
+ if ($this.dragEl) {
202
+ e.preventDefault();
203
+ $this.dragStop(hasTouch ? e.touches[0] : e);
204
+ }
205
+
206
+ draggingElement = false;
207
+ $this.delayMove = false;
208
+ };
209
+
210
+ if (hasTouch) {
211
+ this.element[0].addEventListener(eStart, onStartEvent, false);
212
+ window.addEventListener(eMove, onMoveEvent, false);
213
+ window.addEventListener(eEnd, onEndEvent, false);
214
+ window.addEventListener(eCancel, onEndEvent, false);
215
+ } else {
216
+ this.on(eStart, onStartEvent);
217
+ $win.on(eMove, onMoveEvent);
218
+ $win.on(eEnd, onEndEvent);
219
+ }
220
+
221
+ },
222
+
223
+ serialize: function() {
224
+
225
+ var data,
226
+ depth = 0,
227
+ list = this,
228
+ step = function(level, depth) {
229
+
230
+ var array = [ ], items = level.children(list.options._listItemClass);
231
+
232
+ items.each(function() {
233
+
234
+ var li = UI.$(this),
235
+ item = {}, attribute,
236
+ sub = li.children(list.options._listClass);
237
+
238
+ for (var i = 0; i < li[0].attributes.length; i++) {
239
+ attribute = li[0].attributes[i];
240
+ if (attribute.name.indexOf('data-') === 0) {
241
+ item[attribute.name.substr(5)] = UI.Utils.str2json(attribute.value);
242
+ }
243
+ }
244
+
245
+ if (sub.length) {
246
+ item.children = step(sub, depth + 1);
247
+ }
248
+
249
+ array.push(item);
250
+
251
+ });
252
+ return array;
253
+ };
254
+
255
+ data = step(list.element, depth);
256
+
257
+ return data;
258
+ },
259
+
260
+ list: function(options) {
261
+
262
+ var data = [],
263
+ list = this,
264
+ depth = 0,
265
+ step = function(level, depth, parent) {
266
+
267
+ var items = level.children(options._listItemClass);
268
+
269
+ items.each(function(index) {
270
+ var li = UI.$(this),
271
+ item = UI.$.extend({parent_id: (parent ? parent : null), depth: depth, order: index}, li.data()),
272
+ sub = li.children(options._listClass);
273
+
274
+ data.push(item);
275
+
276
+ if (sub.length) {
277
+ step(sub, depth + 1, li.data(options.idProperty || 'id'));
278
+ }
279
+ });
280
+ };
281
+
282
+ options = UI.$.extend({}, list.options, options);
283
+
284
+ step(list.element, depth);
285
+
286
+ return data;
287
+ },
288
+
289
+ reset: function() {
290
+
291
+ this.mouse = {
292
+ offsetX : 0,
293
+ offsetY : 0,
294
+ startX : 0,
295
+ startY : 0,
296
+ lastX : 0,
297
+ lastY : 0,
298
+ nowX : 0,
299
+ nowY : 0,
300
+ distX : 0,
301
+ distY : 0,
302
+ dirAx : 0,
303
+ dirX : 0,
304
+ dirY : 0,
305
+ lastDirX : 0,
306
+ lastDirY : 0,
307
+ distAxX : 0,
308
+ distAxY : 0
309
+ };
310
+ this.moving = false;
311
+ this.dragEl = null;
312
+ this.dragRootEl = null;
313
+ this.dragDepth = 0;
314
+ this.hasNewRoot = false;
315
+ this.pointEl = null;
316
+
317
+ for (var i=0; i<touchedlists.length; i++) {
318
+ this.checkEmptyList(touchedlists[i]);
319
+ }
320
+
321
+ touchedlists = [];
322
+ },
323
+
324
+ toggleItem: function(li) {
325
+ this[li.hasClass(this.options.collapsedClass) ? "expandItem":"collapseItem"](li);
326
+ },
327
+
328
+ expandItem: function(li) {
329
+ li.removeClass(this.options.collapsedClass);
330
+ },
331
+
332
+ collapseItem: function(li) {
333
+ var lists = li.children(this.options._listClass);
334
+ if (lists.length) {
335
+ li.addClass(this.options.collapsedClass);
336
+ }
337
+ },
338
+
339
+ expandAll: function() {
340
+ var list = this;
341
+ this.find(list.options._listItemClass).each(function() {
342
+ list.expandItem(UI.$(this));
343
+ });
344
+ },
345
+
346
+ collapseAll: function() {
347
+ var list = this;
348
+ this.find(list.options._listItemClass).each(function() {
349
+ list.collapseItem(UI.$(this));
350
+ });
351
+ },
352
+
353
+ setParent: function(li) {
354
+
355
+ if (li.children(this.options._listClass).length) {
356
+ li.addClass("uk-parent");
357
+ }
358
+ },
359
+
360
+ unsetParent: function(li) {
361
+ li.removeClass('uk-parent '+this.options.collapsedClass);
362
+ li.children(this.options._listClass).remove();
363
+ },
364
+
365
+ dragStart: function(e) {
366
+
367
+ var mouse = this.mouse,
368
+ target = UI.$(e.target),
369
+ dragItem = target.closest(this.options._listItemClass),
370
+ offset = dragItem.offset();
371
+
372
+ this.placeEl = dragItem;
373
+
374
+ mouse.offsetX = e.pageX - offset.left;
375
+ mouse.offsetY = e.pageY - offset.top;
376
+
377
+ mouse.startX = mouse.lastX = offset.left;
378
+ mouse.startY = mouse.lastY = offset.top;
379
+
380
+ this.dragRootEl = this.element;
381
+
382
+ this.dragEl = UI.$('<ul></ul>').addClass(this.options.listClass + ' ' + this.options.dragClass).append(dragItem.clone());
383
+ this.dragEl.css('width', dragItem.width());
384
+ this.placeEl.addClass(this.options.placeholderClass);
385
+
386
+ draggingElement = this.dragEl;
387
+
388
+ this.tmpDragOnSiblings = [dragItem[0].previousSibling, dragItem[0].nextSibling];
389
+
390
+ UI.$body.append(this.dragEl);
391
+
392
+ this.dragEl.css({
393
+ left : offset.left,
394
+ top : offset.top
395
+ });
396
+
397
+ // total depth of dragging item
398
+ var i, depth, items = this.dragEl.find(this.options._listItemClass);
399
+
400
+ for (i = 0; i < items.length; i++) {
401
+ depth = UI.$(items[i]).parents(this.options._listClass+','+this.options._listBaseClass).length;
402
+ if (depth > this.dragDepth) {
403
+ this.dragDepth = depth;
404
+ }
405
+ }
406
+
407
+ html.addClass(this.options.movingClass);
408
+ },
409
+
410
+ dragStop: function(e) {
411
+
412
+ var el = UI.$(this.placeEl),
413
+ root = this.placeEl.parents(this.options._listBaseClass+':first');
414
+
415
+ this.placeEl.removeClass(this.options.placeholderClass);
416
+ this.dragEl.remove();
417
+
418
+ if (this.element[0] !== root[0]) {
419
+
420
+ root.trigger('change.uk.nestable',[root.data('nestable'), el, 'added']);
421
+ this.element.trigger('change.uk.nestable', [this, el, 'removed']);
422
+
423
+ } else {
424
+ this.element.trigger('change.uk.nestable',[this, el, "moved"]);
425
+ }
426
+
427
+ this.trigger('stop.uk.nestable', [this, el]);
428
+
429
+ this.reset();
430
+
431
+ html.removeClass(this.options.movingClass);
432
+ },
433
+
434
+ dragMove: function(e) {
435
+ var list, parent, prev, next, depth,
436
+ opt = this.options,
437
+ mouse = this.mouse,
438
+ maxDepth = this.dragRootEl ? this.dragRootEl.data('nestable').options.maxDepth : opt.maxDepth;
439
+
440
+ this.dragEl.css({
441
+ left : e.pageX - mouse.offsetX,
442
+ top : e.pageY - mouse.offsetY
443
+ });
444
+
445
+ // mouse position last events
446
+ mouse.lastX = mouse.nowX;
447
+ mouse.lastY = mouse.nowY;
448
+ // mouse position this events
449
+ mouse.nowX = e.pageX;
450
+ mouse.nowY = e.pageY;
451
+ // distance mouse moved between events
452
+ mouse.distX = mouse.nowX - mouse.lastX;
453
+ mouse.distY = mouse.nowY - mouse.lastY;
454
+ // direction mouse was moving
455
+ mouse.lastDirX = mouse.dirX;
456
+ mouse.lastDirY = mouse.dirY;
457
+ // direction mouse is now moving (on both axis)
458
+ mouse.dirX = mouse.distX === 0 ? 0 : mouse.distX > 0 ? 1 : -1;
459
+ mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
460
+ // axis mouse is now moving on
461
+ var newAx = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;
462
+
463
+ // do nothing on first move
464
+ if (!mouse.moving) {
465
+ mouse.dirAx = newAx;
466
+ mouse.moving = true;
467
+ return;
468
+ }
469
+
470
+ // calc distance moved on this axis (and direction)
471
+ if (mouse.dirAx !== newAx) {
472
+ mouse.distAxX = 0;
473
+ mouse.distAxY = 0;
474
+ } else {
475
+ mouse.distAxX += Math.abs(mouse.distX);
476
+ if (mouse.dirX !== 0 && mouse.dirX !== mouse.lastDirX) {
477
+ mouse.distAxX = 0;
478
+ }
479
+ mouse.distAxY += Math.abs(mouse.distY);
480
+ if (mouse.dirY !== 0 && mouse.dirY !== mouse.lastDirY) {
481
+ mouse.distAxY = 0;
482
+ }
483
+ }
484
+ mouse.dirAx = newAx;
485
+
486
+ /**
487
+ * move horizontal
488
+ */
489
+ if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
490
+ // reset move distance on x-axis for new phase
491
+ mouse.distAxX = 0;
492
+ prev = this.placeEl.prev('li');
493
+
494
+ // increase horizontal level if previous sibling exists and is not collapsed
495
+ if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass)) {
496
+
497
+ // cannot increase level when item above is collapsed
498
+ list = prev.find(opt._listClass).last();
499
+
500
+ // check if depth limit has reached
501
+ depth = this.placeEl.parents(opt._listClass+','+opt._listBaseClass).length;
502
+
503
+ if (depth + this.dragDepth <= maxDepth) {
504
+
505
+ // create new sub-level if one doesn't exist
506
+ if (!list.length) {
507
+ list = UI.$('<ul/>').addClass(opt.listClass);
508
+ list.append(this.placeEl);
509
+ prev.append(list);
510
+ this.setParent(prev);
511
+ } else {
512
+ // else append to next level up
513
+ list = prev.children(opt._listClass).last();
514
+ list.append(this.placeEl);
515
+ }
516
+ }
517
+ }
518
+
519
+ // decrease horizontal level
520
+ if (mouse.distX < 0) {
521
+
522
+ // we cannot decrease the level if an item precedes the current one
523
+ next = this.placeEl.next(opt._listItemClass);
524
+ if (!next.length) {
525
+
526
+ // get parent ul of the list item
527
+ var parentUl = this.placeEl.closest([opt._listBaseClass, opt._listClass].join(','));
528
+ // try to get the li surrounding the ul
529
+ var surroundingLi = parentUl.closest(opt._listItemClass);
530
+
531
+ // if the ul is inside of a li (meaning it is nested)
532
+ if (surroundingLi.length) {
533
+ // we can decrease the horizontal level
534
+ surroundingLi.after(this.placeEl);
535
+ // if the previous parent ul is now empty
536
+ if (!parentUl.children().length) {
537
+ this.unsetParent(surroundingLi);
538
+ }
539
+ }
540
+ }
541
+ }
542
+ }
543
+
544
+ var isEmpty = false;
545
+
546
+ // find list item under cursor
547
+ var pointX = e.pageX - (window.pageXOffset || document.scrollLeft || 0),
548
+ pointY = e.pageY - (window.pageYOffset || document.documentElement.scrollTop);
549
+ this.pointEl = UI.$(document.elementFromPoint(pointX, pointY));
550
+
551
+ if (opt.handleClass && this.pointEl.hasClass(opt.handleClass)) {
552
+
553
+ this.pointEl = this.pointEl.closest(opt._listItemClass);
554
+
555
+ } else {
556
+
557
+ var nestableitem = this.pointEl.closest(opt._listItemClass);
558
+
559
+ if (nestableitem.length) {
560
+ this.pointEl = nestableitem;
561
+ }
562
+ }
563
+
564
+ if (this.placeEl.find(this.pointEl).length) {
565
+ return;
566
+ }
567
+
568
+ if (this.pointEl.data('nestable') && !this.pointEl.children().length) {
569
+ isEmpty = true;
570
+ this.checkEmptyList(this.pointEl);
571
+ } else if (!this.pointEl.length || !this.pointEl.hasClass(opt.listItemClass)) {
572
+ return;
573
+ }
574
+
575
+ // find parent list of item under cursor
576
+ var pointElRoot = this.element,
577
+ tmpRoot = this.pointEl.closest(this.options._listBaseClass),
578
+ isNewRoot = pointElRoot[0] != tmpRoot[0];
579
+
580
+ /**
581
+ * move vertical
582
+ */
583
+ if (!mouse.dirAx || isNewRoot || isEmpty) {
584
+
585
+ // check if groups match if dragging over new root
586
+ if (isNewRoot && opt.group !== tmpRoot.data('nestable-group')) {
587
+ return;
588
+ } else {
589
+ touchedlists.push(pointElRoot);
590
+ }
591
+
592
+ // check depth limit
593
+ depth = this.dragDepth - 1 + this.pointEl.parents(opt._listClass+','+opt._listBaseClass).length;
594
+
595
+ if (depth > maxDepth) {
596
+ return;
597
+ }
598
+
599
+ var before = e.pageY < (this.pointEl.offset().top + this.pointEl.height() / 2);
600
+
601
+ parent = this.placeEl.parent();
602
+
603
+ if (isEmpty) {
604
+ this.pointEl.append(this.placeEl);
605
+ } else if (before) {
606
+ this.pointEl.before(this.placeEl);
607
+ } else {
608
+ this.pointEl.after(this.placeEl);
609
+ }
610
+
611
+ if (!parent.children().length) {
612
+ if (!parent.data("nestable")) this.unsetParent(parent.parent());
613
+ }
614
+
615
+ this.checkEmptyList(this.dragRootEl);
616
+ this.checkEmptyList(pointElRoot);
617
+
618
+ // parent root list has changed
619
+ if (isNewRoot) {
620
+ this.dragRootEl = tmpRoot;
621
+ this.hasNewRoot = this.element[0] !== this.dragRootEl[0];
622
+ }
623
+ }
624
+ },
625
+
626
+ checkEmptyList: function(list) {
627
+
628
+ list = list ? UI.$(list) : this.element;
629
+
630
+ if (this.options.emptyClass) {
631
+ list[!list.children().length ? 'addClass':'removeClass'](this.options.emptyClass);
632
+ }
633
+ }
634
+
635
+ });
636
+
637
+ return UI.nestable;
638
+ });