plumes
Version:
Flying-fast Metro future vision components
3 lines (2 loc) • 2.94 kB
JavaScript
!function(){"use strict";window.Ractive.controller("pl-scrolls",function(e,o,t,n,l){function r(){var e=R.container.prop("scrollHeight"),o=R.vertical.outerHeight(),t=100*o/e;y.set("active",e>o),y.set("height",t),i()}function i(){var e=R.container.prop("scrollHeight"),o=R.container.scrollTop(),t=100*o/e;y.set("top",t)}function c(){return R.verticalTicker.offset().top-R.vertical.offset().top}function s(e){f={scrollTop:R.container.scrollTop(),pageY:e.pageY},y.set("inDrag",!0),e.preventDefault(),e.stopPropagation()}function a(e){if(f){var o=R.container.prop("scrollHeight"),t=R.vertical.outerHeight(),n=f.scrollTop+(e.pageY-f.pageY)*o/t;R.container.scrollTop(n),e.preventDefault(),e.stopPropagation()}}function u(){f=!1,y.set("inDrag",!1)}function p(){r(),y.set("enter",!0)}function v(){y.set("enter",!1)}var d=268,f=!1,h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"];if("undefined"==typeof window.Ractive.plScrollsWidth){var g=$("<div/>").css({"overflow-y":"auto","overflow-x":"hidden",visibility:"hidden",height:50,width:100}).html('<div style="height: 200px; width: 100%"></div>');$("body").append(g);var m=Math.ceil(100-g.find("div").width());g.remove();var w=window.document.styleSheets[0];0===m?w.insertRule?(w.insertRule(".pl-scrolls-vertical { display: none !important; }",w.cssRules.length),w.insertRule(".pl-scrolls { overflow: scroll !important; -webkit-overflow-scrolling: touch; }",w.cssRules.length)):(w.addRule(".pl-scrolls-vertical","display: none !important;",-1),w.addRule(".pl-scrolls","overflow: scroll !important;",-1)):w.insertRule?w.insertRule(".pl-scrolls { margin-right: -"+m+"px; }",w.cssRules.length):w.addRule(".pl-scrolls","margin-right: -"+m+"px;",-1),window.Ractive.plScrollsWidth=m}var y=e({plName:"pl-scrolls",data:$.extend(!0,{top:0,height:0,active:!1,hover:!1,inDrag:!1,enter:!1},o),update:r}),R={body:$("body"),scrolls:$(y.el),vertical:$(y.el).find(".pl-scrolls-vertical"),verticalTicker:$(y.el).find(".pl-scrolls-vertical-ticker"),container:$(y.el).next(".pl-scrolls")};y.on("teardown",function(){R.container.off("scroll",i),R.body.off("mousemove",a),R.body.off("mouseup",u),R.container.off("mouseenter",p),R.container.off("mouseenter",v),R=null,y=null}),R.container.scroll(i),R.vertical.mouseenter(function(){y.set("hover",!0)}),R.vertical.mouseleave(function(){y.set("hover",!1)}),R.vertical.click(function(e){if(e.target==R.vertical[0]){var t=c(),n=R.container.scrollTop();R.container.stop().animate({scrollTop:n+(t>e.offsetY?-d:d)},150,o.easing||"swing")}}),h.forEach(function(e){R.vertical.on(e,function(o){var t=new window.WheelEvent(e,o.originalEvent);document.createEvent?R.container[0].dispatchEvent(t):R.container[0].fireEvent("on"+t.eventType,t)})}),R.verticalTicker.mousedown(s),R.body.mousemove(a),R.body.mouseup(u),R.container.mouseenter(p),R.container.mouseleave(v),r(),l()})}();
//# sourceMappingURL=pl-scrolls.min.js.map