From 71c7ba37d730aca1d66de355b0fb0b74b7cc3d09 Mon Sep 17 00:00:00 2001 From: Dav Glass Date: Wed, 12 Dec 2012 15:13:04 -0600 Subject: [PATCH] gallery-2012.12.12-21-11 benjamind gallery-scrollfix --- .../gallery-scrollfix-coverage.js | 6 + .../gallery-scrollfix-debug.js | 84 ++ .../gallery-scrollfix-min.js | 1 + build/gallery-scrollfix/gallery-scrollfix.js | 84 ++ src/gallery-scrollfix/HISTORY.md | 3 + src/gallery-scrollfix/README.md | 3 + src/gallery-scrollfix/build.json | 10 + .../docs/basic-example.mustache | 53 ++ src/gallery-scrollfix/docs/component.json | 19 + src/gallery-scrollfix/docs/index.mustache | 39 + .../partials/basic-example-source.mustache | 17 + src/gallery-scrollfix/js/gallery-scrollfix.js | 80 ++ src/gallery-scrollfix/logs/shifter.stderr.log | 0 src/gallery-scrollfix/logs/shifter.stdout.log | 18 + src/gallery-scrollfix/logs/tests.json | 865 ++++++++++++++++++ src/gallery-scrollfix/logs/yogi.stderr.log | 0 src/gallery-scrollfix/logs/yogi.stdout.log | 32 + .../meta/gallery-scrollfix.json | 7 + src/gallery-scrollfix/tests/unit/index.html | 51 ++ src/gallery-scrollfix/tests/unit/js/tests.js | 51 ++ 20 files changed, 1423 insertions(+) create mode 100644 build/gallery-scrollfix/gallery-scrollfix-coverage.js create mode 100644 build/gallery-scrollfix/gallery-scrollfix-debug.js create mode 100644 build/gallery-scrollfix/gallery-scrollfix-min.js create mode 100644 build/gallery-scrollfix/gallery-scrollfix.js create mode 100644 src/gallery-scrollfix/HISTORY.md create mode 100644 src/gallery-scrollfix/README.md create mode 100644 src/gallery-scrollfix/build.json create mode 100644 src/gallery-scrollfix/docs/basic-example.mustache create mode 100644 src/gallery-scrollfix/docs/component.json create mode 100644 src/gallery-scrollfix/docs/index.mustache create mode 100644 src/gallery-scrollfix/docs/partials/basic-example-source.mustache create mode 100644 src/gallery-scrollfix/js/gallery-scrollfix.js create mode 100644 src/gallery-scrollfix/logs/shifter.stderr.log create mode 100644 src/gallery-scrollfix/logs/shifter.stdout.log create mode 100644 src/gallery-scrollfix/logs/tests.json create mode 100644 src/gallery-scrollfix/logs/yogi.stderr.log create mode 100644 src/gallery-scrollfix/logs/yogi.stdout.log create mode 100644 src/gallery-scrollfix/meta/gallery-scrollfix.json create mode 100644 src/gallery-scrollfix/tests/unit/index.html create mode 100644 src/gallery-scrollfix/tests/unit/js/tests.js diff --git a/build/gallery-scrollfix/gallery-scrollfix-coverage.js b/build/gallery-scrollfix/gallery-scrollfix-coverage.js new file mode 100644 index 0000000000..15f13e04f2 --- /dev/null +++ b/build/gallery-scrollfix/gallery-scrollfix-coverage.js @@ -0,0 +1,6 @@ +if (typeof __coverage__ === 'undefined') { __coverage__ = {}; } +if (!__coverage__['build/gallery-scrollfix/gallery-scrollfix.js']) { + __coverage__['build/gallery-scrollfix/gallery-scrollfix.js'] = {"path":"build/gallery-scrollfix/gallery-scrollfix.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":48}}},"2":{"name":"NodeScrollFix","line":20,"loc":{"start":{"line":20,"column":0},"end":{"line":20,"column":35}}},"3":{"name":"(anonymous_3)","line":37,"loc":{"start":{"line":37,"column":10},"end":{"line":37,"column":26}}},"4":{"name":"(anonymous_4)","line":48,"loc":{"start":{"line":48,"column":17},"end":{"line":48,"column":38}}},"5":{"name":"(anonymous_5)","line":51,"loc":{"start":{"line":51,"column":23},"end":{"line":51,"column":40}}},"6":{"name":"(anonymous_6)","line":53,"loc":{"start":{"line":53,"column":52},"end":{"line":53,"column":65}}},"7":{"name":"(anonymous_7)","line":70,"loc":{"start":{"line":70,"column":23},"end":{"line":70,"column":40}}},"8":{"name":"(anonymous_8)","line":75,"loc":{"start":{"line":75,"column":13},"end":{"line":75,"column":24}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":84,"column":62}},"2":{"start":{"line":20,"column":0},"end":{"line":22,"column":1}},"3":{"start":{"line":21,"column":1},"end":{"line":21,"column":61}},"4":{"start":{"line":23,"column":0},"end":{"line":23,"column":41}},"5":{"start":{"line":24,"column":0},"end":{"line":24,"column":31}},"6":{"start":{"line":25,"column":0},"end":{"line":46,"column":2}},"7":{"start":{"line":38,"column":3},"end":{"line":42,"column":4}},"8":{"start":{"line":39,"column":4},"end":{"line":39,"column":24}},"9":{"start":{"line":40,"column":10},"end":{"line":42,"column":4}},"10":{"start":{"line":41,"column":4},"end":{"line":41,"column":17}},"11":{"start":{"line":43,"column":3},"end":{"line":43,"column":36}},"12":{"start":{"line":47,"column":0},"end":{"line":81,"column":3}},"13":{"start":{"line":49,"column":2},"end":{"line":49,"column":30}},"14":{"start":{"line":51,"column":2},"end":{"line":69,"column":10}},"15":{"start":{"line":52,"column":3},"end":{"line":52,"column":35}},"16":{"start":{"line":53,"column":3},"end":{"line":68,"column":6}},"17":{"start":{"line":54,"column":4},"end":{"line":56,"column":44}},"18":{"start":{"line":58,"column":4},"end":{"line":67,"column":5}},"19":{"start":{"line":60,"column":5},"end":{"line":66,"column":6}},"20":{"start":{"line":62,"column":6},"end":{"line":62,"column":26}},"21":{"start":{"line":63,"column":12},"end":{"line":66,"column":6}},"22":{"start":{"line":65,"column":6},"end":{"line":65,"column":26}},"23":{"start":{"line":70,"column":2},"end":{"line":73,"column":10}},"24":{"start":{"line":71,"column":3},"end":{"line":71,"column":36}},"25":{"start":{"line":72,"column":3},"end":{"line":72,"column":34}},"26":{"start":{"line":76,"column":2},"end":{"line":79,"column":3}},"27":{"start":{"line":77,"column":3},"end":{"line":77,"column":36}},"28":{"start":{"line":78,"column":3},"end":{"line":78,"column":34}},"29":{"start":{"line":82,"column":0},"end":{"line":82,"column":52}}},"branchMap":{"1":{"line":38,"type":"if","locations":[{"start":{"line":38,"column":3},"end":{"line":38,"column":3}},{"start":{"line":38,"column":3},"end":{"line":38,"column":3}}]},"2":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":10},"end":{"line":40,"column":10}},{"start":{"line":40,"column":10},"end":{"line":40,"column":10}}]},"3":{"line":58,"type":"if","locations":[{"start":{"line":58,"column":4},"end":{"line":58,"column":4}},{"start":{"line":58,"column":4},"end":{"line":58,"column":4}}]},"4":{"line":60,"type":"if","locations":[{"start":{"line":60,"column":5},"end":{"line":60,"column":5}},{"start":{"line":60,"column":5},"end":{"line":60,"column":5}}]},"5":{"line":60,"type":"binary-expr","locations":[{"start":{"line":60,"column":9},"end":{"line":60,"column":26}},{"start":{"line":60,"column":30},"end":{"line":60,"column":55}}]},"6":{"line":63,"type":"if","locations":[{"start":{"line":63,"column":12},"end":{"line":63,"column":12}},{"start":{"line":63,"column":12},"end":{"line":63,"column":12}}]},"7":{"line":63,"type":"binary-expr","locations":[{"start":{"line":63,"column":16},"end":{"line":63,"column":33}},{"start":{"line":63,"column":37},"end":{"line":63,"column":70}}]},"8":{"line":76,"type":"if","locations":[{"start":{"line":76,"column":2},"end":{"line":76,"column":2}},{"start":{"line":76,"column":2},"end":{"line":76,"column":2}}]}},"code":["(function () { YUI.add('gallery-scrollfix', function (Y, NAME) {","","/**"," * ScrollFix is a simple Node plugin that prevents mousewheel events inside"," * the host node from bubbling up to parent nodes if the scroll has reached the"," * bottom of the host node. This fixes an issue commonly seen in websites where"," * the user scrolls an inner-scroll area but then the whole page moves as the"," * scroll reaches the bottom of the inner-scroll area."," *"," * @module gallery-scrollfix"," **/","","/**"," *

"," * ScrollFix is a Node plugin that can be used to stop scroll events from"," * escaping an inner scroll area when the scroll reaches the bottom of the area."," *

"," * @class NodeScrollFix"," */","function NodeScrollFix(/*config*/) {","\tNodeScrollFix.superclass.constructor.apply(this, arguments);","}","NodeScrollFix.NAME = 'gallery-scrollfix';","NodeScrollFix.NS = 'scrollfix';","NodeScrollFix.ATTRS = {","\t/**","\t * Defines a node or CSS selector to listen to for the mousewheel","\t * events. This defaults to the body element of the page and probably","\t * should not be altered in most cases.","\t *","\t * @attribute target","\t * @default Y.one('body')","\t * @type string | Y.Node","\t */","\ttarget: {","\t\tvalue: Y.one('body'),","\t\tsetter: function(value) {","\t\t\tif (typeof value === 'string') {","\t\t\t\treturn Y.one(value);","\t\t\t} else if (value instanceof Y.Node) {","\t\t\t\treturn value;","\t\t\t}","\t\t\treturn Y.Attribute.INVALID_VALUE;","\t\t}","\t}","};","Y.extend(NodeScrollFix, Y.Plugin.Base, {"," initializer: function(/*config*/) {","\t\tvar host = this.get('host');","","\t\thost.on('mouseenter',function(/*ev*/) {","\t\t\tvar target = this.get('target');","\t\t\tthis.mouseWheelListener = target.on('mousewheel',function(ev) {","\t\t\t\tvar scrollNode = host.getDOMNode(),","\t\t\t\t\tremainingHeight = scrollNode.scrollHeight - scrollNode.scrollTop,","\t\t\t\t\tclientHeight = scrollNode.clientHeight;","\t\t\t\t// decide if we should prevent scrolling or not","\t\t\t\tif (scrollNode.scrollHeight > clientHeight) {","\t\t\t\t\t// scrollbars are visible","\t\t\t\t\tif (ev.wheelDelta > 0 && scrollNode.scrollTop <= 0) {","\t\t\t\t\t\t// scrolling up, and already at top","\t\t\t\t\t\tev.preventDefault();","\t\t\t\t\t} else if (ev.wheelDelta < 0 && remainingHeight <= clientHeight+1) {","\t\t\t\t\t\t// scrolling down and near enough the bottom already","\t\t\t\t\t\tev.preventDefault();","\t\t\t\t\t}","\t\t\t\t}","\t\t\t});","\t\t},this);","\t\thost.on('mouseleave',function(/*ev*/) {","\t\t\tthis.mouseWheelListener.detach();","\t\t\tthis.mouseWheelListener = null;","\t\t},this);","\t},","\tdestructor: function() {","\t\tif (this.mouseWheelListener) {","\t\t\tthis.mouseWheelListener.detach();","\t\t\tthis.mouseWheelListener = null;","\t\t}","\t}","});","Y.namespace('Plugin').NodeScrollFix = NodeScrollFix;","","}, 'gallery-2012.12.12-21-11', {\"requires\": [\"event-mouseenter\", \"plugin\"]});","","}());"]}; +} +var __cov_LK_7J$1zP8pfDBkWhMSV4g = __coverage__['build/gallery-scrollfix/gallery-scrollfix.js']; +__cov_LK_7J$1zP8pfDBkWhMSV4g.s['1']++;YUI.add('gallery-scrollfix',function(Y,NAME){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['1']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['2']++;function NodeScrollFix(){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['2']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['3']++;NodeScrollFix.superclass.constructor.apply(this,arguments);}__cov_LK_7J$1zP8pfDBkWhMSV4g.s['4']++;NodeScrollFix.NAME='gallery-scrollfix';__cov_LK_7J$1zP8pfDBkWhMSV4g.s['5']++;NodeScrollFix.NS='scrollfix';__cov_LK_7J$1zP8pfDBkWhMSV4g.s['6']++;NodeScrollFix.ATTRS={target:{value:Y.one('body'),setter:function(value){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['3']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['7']++;if(typeof value==='string'){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['1'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['8']++;return Y.one(value);}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['1'][1]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['9']++;if(value instanceof Y.Node){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['2'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['10']++;return value;}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['2'][1]++;}}__cov_LK_7J$1zP8pfDBkWhMSV4g.s['11']++;return Y.Attribute.INVALID_VALUE;}}};__cov_LK_7J$1zP8pfDBkWhMSV4g.s['12']++;Y.extend(NodeScrollFix,Y.Plugin.Base,{initializer:function(){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['4']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['13']++;var host=this.get('host');__cov_LK_7J$1zP8pfDBkWhMSV4g.s['14']++;host.on('mouseenter',function(){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['5']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['15']++;var target=this.get('target');__cov_LK_7J$1zP8pfDBkWhMSV4g.s['16']++;this.mouseWheelListener=target.on('mousewheel',function(ev){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['6']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['17']++;var scrollNode=host.getDOMNode(),remainingHeight=scrollNode.scrollHeight-scrollNode.scrollTop,clientHeight=scrollNode.clientHeight;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['18']++;if(scrollNode.scrollHeight>clientHeight){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['3'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['19']++;if((__cov_LK_7J$1zP8pfDBkWhMSV4g.b['5'][0]++,ev.wheelDelta>0)&&(__cov_LK_7J$1zP8pfDBkWhMSV4g.b['5'][1]++,scrollNode.scrollTop<=0)){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['4'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['20']++;ev.preventDefault();}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['4'][1]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['21']++;if((__cov_LK_7J$1zP8pfDBkWhMSV4g.b['7'][0]++,ev.wheelDelta<0)&&(__cov_LK_7J$1zP8pfDBkWhMSV4g.b['7'][1]++,remainingHeight<=clientHeight+1)){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['6'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['22']++;ev.preventDefault();}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['6'][1]++;}}}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['3'][1]++;}});},this);__cov_LK_7J$1zP8pfDBkWhMSV4g.s['23']++;host.on('mouseleave',function(){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['7']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['24']++;this.mouseWheelListener.detach();__cov_LK_7J$1zP8pfDBkWhMSV4g.s['25']++;this.mouseWheelListener=null;},this);},destructor:function(){__cov_LK_7J$1zP8pfDBkWhMSV4g.f['8']++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['26']++;if(this.mouseWheelListener){__cov_LK_7J$1zP8pfDBkWhMSV4g.b['8'][0]++;__cov_LK_7J$1zP8pfDBkWhMSV4g.s['27']++;this.mouseWheelListener.detach();__cov_LK_7J$1zP8pfDBkWhMSV4g.s['28']++;this.mouseWheelListener=null;}else{__cov_LK_7J$1zP8pfDBkWhMSV4g.b['8'][1]++;}}});__cov_LK_7J$1zP8pfDBkWhMSV4g.s['29']++;Y.namespace('Plugin').NodeScrollFix=NodeScrollFix;},'gallery-2012.12.12-21-11',{'requires':['event-mouseenter','plugin']}); diff --git a/build/gallery-scrollfix/gallery-scrollfix-debug.js b/build/gallery-scrollfix/gallery-scrollfix-debug.js new file mode 100644 index 0000000000..e007dc10e1 --- /dev/null +++ b/build/gallery-scrollfix/gallery-scrollfix-debug.js @@ -0,0 +1,84 @@ +YUI.add('gallery-scrollfix', function (Y, NAME) { + +/** + * ScrollFix is a simple Node plugin that prevents mousewheel events inside + * the host node from bubbling up to parent nodes if the scroll has reached the + * bottom of the host node. This fixes an issue commonly seen in websites where + * the user scrolls an inner-scroll area but then the whole page moves as the + * scroll reaches the bottom of the inner-scroll area. + * + * @module gallery-scrollfix + **/ + +/** + *

+ * ScrollFix is a Node plugin that can be used to stop scroll events from + * escaping an inner scroll area when the scroll reaches the bottom of the area. + *

+ * @class NodeScrollFix + */ +function NodeScrollFix(/*config*/) { + NodeScrollFix.superclass.constructor.apply(this, arguments); +} +NodeScrollFix.NAME = 'gallery-scrollfix'; +NodeScrollFix.NS = 'scrollfix'; +NodeScrollFix.ATTRS = { + /** + * Defines a node or CSS selector to listen to for the mousewheel + * events. This defaults to the body element of the page and probably + * should not be altered in most cases. + * + * @attribute target + * @default Y.one('body') + * @type string | Y.Node + */ + target: { + value: Y.one('body'), + setter: function(value) { + if (typeof value === 'string') { + return Y.one(value); + } else if (value instanceof Y.Node) { + return value; + } + return Y.Attribute.INVALID_VALUE; + } + } +}; +Y.extend(NodeScrollFix, Y.Plugin.Base, { + initializer: function(/*config*/) { + var host = this.get('host'); + + host.on('mouseenter',function(/*ev*/) { + var target = this.get('target'); + this.mouseWheelListener = target.on('mousewheel',function(ev) { + var scrollNode = host.getDOMNode(), + remainingHeight = scrollNode.scrollHeight - scrollNode.scrollTop, + clientHeight = scrollNode.clientHeight; + // decide if we should prevent scrolling or not + if (scrollNode.scrollHeight > clientHeight) { + // scrollbars are visible + if (ev.wheelDelta > 0 && scrollNode.scrollTop <= 0) { + // scrolling up, and already at top + ev.preventDefault(); + } else if (ev.wheelDelta < 0 && remainingHeight <= clientHeight+1) { + // scrolling down and near enough the bottom already + ev.preventDefault(); + } + } + }); + },this); + host.on('mouseleave',function(/*ev*/) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + },this); + }, + destructor: function() { + if (this.mouseWheelListener) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + } + } +}); +Y.namespace('Plugin').NodeScrollFix = NodeScrollFix; + +}, 'gallery-2012.12.12-21-11', {"requires": ["event-mouseenter", "plugin"]}); diff --git a/build/gallery-scrollfix/gallery-scrollfix-min.js b/build/gallery-scrollfix/gallery-scrollfix-min.js new file mode 100644 index 0000000000..fbe109cb9d --- /dev/null +++ b/build/gallery-scrollfix/gallery-scrollfix-min.js @@ -0,0 +1 @@ +YUI.add("gallery-scrollfix",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}n.NAME="gallery-scrollfix",n.NS="scrollfix",n.ATTRS={target:{value:e.one("body"),setter:function(t){return typeof t=="string"?e.one(t):t instanceof e.Node?t:e.Attribute.INVALID_VALUE}}},e.extend(n,e.Plugin.Base,{initializer:function(){var e=this.get("host");e.on("mouseenter",function(){var t=this.get("target");this.mouseWheelListener=t.on("mousewheel",function(t){var n=e.getDOMNode(),r=n.scrollHeight-n.scrollTop,i=n.clientHeight;n.scrollHeight>i&&(t.wheelDelta>0&&n.scrollTop<=0?t.preventDefault():t.wheelDelta<0&&r<=i+1&&t.preventDefault())})},this),e.on("mouseleave",function(){this.mouseWheelListener.detach(),this.mouseWheelListener=null},this)},destructor:function(){this.mouseWheelListener&&(this.mouseWheelListener.detach(),this.mouseWheelListener=null)}}),e.namespace("Plugin").NodeScrollFix=n},"gallery-2012.12.12-21-11",{requires:["event-mouseenter","plugin"]}); diff --git a/build/gallery-scrollfix/gallery-scrollfix.js b/build/gallery-scrollfix/gallery-scrollfix.js new file mode 100644 index 0000000000..e007dc10e1 --- /dev/null +++ b/build/gallery-scrollfix/gallery-scrollfix.js @@ -0,0 +1,84 @@ +YUI.add('gallery-scrollfix', function (Y, NAME) { + +/** + * ScrollFix is a simple Node plugin that prevents mousewheel events inside + * the host node from bubbling up to parent nodes if the scroll has reached the + * bottom of the host node. This fixes an issue commonly seen in websites where + * the user scrolls an inner-scroll area but then the whole page moves as the + * scroll reaches the bottom of the inner-scroll area. + * + * @module gallery-scrollfix + **/ + +/** + *

+ * ScrollFix is a Node plugin that can be used to stop scroll events from + * escaping an inner scroll area when the scroll reaches the bottom of the area. + *

+ * @class NodeScrollFix + */ +function NodeScrollFix(/*config*/) { + NodeScrollFix.superclass.constructor.apply(this, arguments); +} +NodeScrollFix.NAME = 'gallery-scrollfix'; +NodeScrollFix.NS = 'scrollfix'; +NodeScrollFix.ATTRS = { + /** + * Defines a node or CSS selector to listen to for the mousewheel + * events. This defaults to the body element of the page and probably + * should not be altered in most cases. + * + * @attribute target + * @default Y.one('body') + * @type string | Y.Node + */ + target: { + value: Y.one('body'), + setter: function(value) { + if (typeof value === 'string') { + return Y.one(value); + } else if (value instanceof Y.Node) { + return value; + } + return Y.Attribute.INVALID_VALUE; + } + } +}; +Y.extend(NodeScrollFix, Y.Plugin.Base, { + initializer: function(/*config*/) { + var host = this.get('host'); + + host.on('mouseenter',function(/*ev*/) { + var target = this.get('target'); + this.mouseWheelListener = target.on('mousewheel',function(ev) { + var scrollNode = host.getDOMNode(), + remainingHeight = scrollNode.scrollHeight - scrollNode.scrollTop, + clientHeight = scrollNode.clientHeight; + // decide if we should prevent scrolling or not + if (scrollNode.scrollHeight > clientHeight) { + // scrollbars are visible + if (ev.wheelDelta > 0 && scrollNode.scrollTop <= 0) { + // scrolling up, and already at top + ev.preventDefault(); + } else if (ev.wheelDelta < 0 && remainingHeight <= clientHeight+1) { + // scrolling down and near enough the bottom already + ev.preventDefault(); + } + } + }); + },this); + host.on('mouseleave',function(/*ev*/) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + },this); + }, + destructor: function() { + if (this.mouseWheelListener) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + } + } +}); +Y.namespace('Plugin').NodeScrollFix = NodeScrollFix; + +}, 'gallery-2012.12.12-21-11', {"requires": ["event-mouseenter", "plugin"]}); diff --git a/src/gallery-scrollfix/HISTORY.md b/src/gallery-scrollfix/HISTORY.md new file mode 100644 index 0000000000..b5f3863f36 --- /dev/null +++ b/src/gallery-scrollfix/HISTORY.md @@ -0,0 +1,3 @@ +gallery-scrollfix +======== +First commit. Implemented basic suite of tests and the plugin itself. \ No newline at end of file diff --git a/src/gallery-scrollfix/README.md b/src/gallery-scrollfix/README.md new file mode 100644 index 0000000000..721ba5f370 --- /dev/null +++ b/src/gallery-scrollfix/README.md @@ -0,0 +1,3 @@ +gallery-scrollfix +======== +A basic Node plugin to help prevent accidental scrolling of the document when inside an inner-scroll area. \ No newline at end of file diff --git a/src/gallery-scrollfix/build.json b/src/gallery-scrollfix/build.json new file mode 100644 index 0000000000..f54363ea53 --- /dev/null +++ b/src/gallery-scrollfix/build.json @@ -0,0 +1,10 @@ +{ + "name": "gallery-scrollfix", + "builds": { + "gallery-scrollfix": { + "jsfiles": [ + "js/gallery-scrollfix.js" + ] + } + } +} diff --git a/src/gallery-scrollfix/docs/basic-example.mustache b/src/gallery-scrollfix/docs/basic-example.mustache new file mode 100644 index 0000000000..b7fa88d090 --- /dev/null +++ b/src/gallery-scrollfix/docs/basic-example.mustache @@ -0,0 +1,53 @@ + + +
+

The ScrollFix plugin prevents mousewheel events inside an inner-scrollable node from scrolling the parent document.

+
+ +
+ {{>basic-example-source}} +
+ +

Basic Usage

+

In this example we just attach a ScrollFix plugin to our scrollable node. Note there are two scrollable divs in the example above, the first does not have the ScrollFix plugin attached, the second does using the code below:

+``` + +``` diff --git a/src/gallery-scrollfix/docs/component.json b/src/gallery-scrollfix/docs/component.json new file mode 100644 index 0000000000..e931284907 --- /dev/null +++ b/src/gallery-scrollfix/docs/component.json @@ -0,0 +1,19 @@ +{ + "name" : "gallery-scrollfix", + "displayName": "Node ScrollFix", + "description": "ScrollFix is a Node plugin that can be used to stop scroll events from escaping an inner scroll area when the scroll reaches the bottom of the area", + "author" : [ "benjamind" ], + + "tags": [ "gallery", "node", "plugin", "scrolling" ], + "use": "'gallery-scrollfix','node'", + "examples": [ + { + "name": "basic-example", + "displayName": "Node ScrollFix Basic Example", + "modules": ["gallery-scrollfix"], + "description": "This example illustrates the use of the Node ScrollFix module.", + "useModules": ["gallery-scrollfix","node"], + "hideTableOfContents": true + } + ] +} diff --git a/src/gallery-scrollfix/docs/index.mustache b/src/gallery-scrollfix/docs/index.mustache new file mode 100644 index 0000000000..b7380e0ba3 --- /dev/null +++ b/src/gallery-scrollfix/docs/index.mustache @@ -0,0 +1,39 @@ +
+

+ ScrollFix is a Node plugin that can be used to stop scroll events from + escaping an inner scroll area when the scroll reaches the bottom of the area +

+
+ +

Description

+ +

ScrollFix is a simple Node plugin that prevents mousewheel events inside +the host node from bubbling up to parent nodes if the scroll has reached the +bottom of the host node. This fixes an issue commonly seen in websites where +the user scrolls an inner-scroll area but then the whole page moves as the +scroll reaches the bottom of the inner-scroll area.

+ +{{>getting-started}} + +

Basic Setup

+

To use the module simply plug it onto a node that will show scrollbars:

+ +``` + +``` + +

Advanced Usage

+

ScrollFix works by attaching a MouseWheel event listener to the document.body by default. It does this whenever your mouse enters the host node. If you wish to have ScrollFix listen on a different element than the document body then you can use the `target` attribute. It is unlikely you'll need to do this, but just in case here's how:

+``` + +``` diff --git a/src/gallery-scrollfix/docs/partials/basic-example-source.mustache b/src/gallery-scrollfix/docs/partials/basic-example-source.mustache new file mode 100644 index 0000000000..5a3891b085 --- /dev/null +++ b/src/gallery-scrollfix/docs/partials/basic-example-source.mustache @@ -0,0 +1,17 @@ +
+
+

This div will scroll the parent when using the mousewheel to scroll to the bottom.

+
+
+
+
+

This div uses ScrollFix and will not.

+
+
+ + \ No newline at end of file diff --git a/src/gallery-scrollfix/js/gallery-scrollfix.js b/src/gallery-scrollfix/js/gallery-scrollfix.js new file mode 100644 index 0000000000..bc37f5a70c --- /dev/null +++ b/src/gallery-scrollfix/js/gallery-scrollfix.js @@ -0,0 +1,80 @@ +/** + * ScrollFix is a simple Node plugin that prevents mousewheel events inside + * the host node from bubbling up to parent nodes if the scroll has reached the + * bottom of the host node. This fixes an issue commonly seen in websites where + * the user scrolls an inner-scroll area but then the whole page moves as the + * scroll reaches the bottom of the inner-scroll area. + * + * @module gallery-scrollfix + **/ + +/** + *

+ * ScrollFix is a Node plugin that can be used to stop scroll events from + * escaping an inner scroll area when the scroll reaches the bottom of the area. + *

+ * @class NodeScrollFix + */ +function NodeScrollFix(/*config*/) { + NodeScrollFix.superclass.constructor.apply(this, arguments); +} +NodeScrollFix.NAME = 'gallery-scrollfix'; +NodeScrollFix.NS = 'scrollfix'; +NodeScrollFix.ATTRS = { + /** + * Defines a node or CSS selector to listen to for the mousewheel + * events. This defaults to the body element of the page and probably + * should not be altered in most cases. + * + * @attribute target + * @default Y.one('body') + * @type string | Y.Node + */ + target: { + value: Y.one('body'), + setter: function(value) { + if (typeof value === 'string') { + return Y.one(value); + } else if (value instanceof Y.Node) { + return value; + } + return Y.Attribute.INVALID_VALUE; + } + } +}; +Y.extend(NodeScrollFix, Y.Plugin.Base, { + initializer: function(/*config*/) { + var host = this.get('host'); + + host.on('mouseenter',function(/*ev*/) { + var target = this.get('target'); + this.mouseWheelListener = target.on('mousewheel',function(ev) { + var scrollNode = host.getDOMNode(), + remainingHeight = scrollNode.scrollHeight - scrollNode.scrollTop, + clientHeight = scrollNode.clientHeight; + // decide if we should prevent scrolling or not + if (scrollNode.scrollHeight > clientHeight) { + // scrollbars are visible + if (ev.wheelDelta > 0 && scrollNode.scrollTop <= 0) { + // scrolling up, and already at top + ev.preventDefault(); + } else if (ev.wheelDelta < 0 && remainingHeight <= clientHeight+1) { + // scrolling down and near enough the bottom already + ev.preventDefault(); + } + } + }); + },this); + host.on('mouseleave',function(/*ev*/) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + },this); + }, + destructor: function() { + if (this.mouseWheelListener) { + this.mouseWheelListener.detach(); + this.mouseWheelListener = null; + } + } +}); +Y.namespace('Plugin').NodeScrollFix = NodeScrollFix; \ No newline at end of file diff --git a/src/gallery-scrollfix/logs/shifter.stderr.log b/src/gallery-scrollfix/logs/shifter.stderr.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/gallery-scrollfix/logs/shifter.stdout.log b/src/gallery-scrollfix/logs/shifter.stdout.log new file mode 100644 index 0000000000..dac79f1b11 --- /dev/null +++ b/src/gallery-scrollfix/logs/shifter.stdout.log @@ -0,0 +1,18 @@ +shifter [info] revving up +shifter [info] looking for build.json file +shifter [info] found build.json file, shifting +shifter [info] putting the hammer down, let's build this thing! +shifter [info] munging in loader meta data into build.json +shifter [info] putting the hammer down +shifter [info] shifting into gear for gallery-scrollfix +shifter [info] deleting build dir: /build/gallery-scrollfix +shifter [queu] writing RAW file +shifter [queu] compressing gallery-scrollfix/gallery-scrollfix.js with UglifyJS +shifter [queu] writing -min file +shifter [info] shifting for coverage +shifter [queu] coverage file read, starting coverage for: gallery-scrollfix/gallery-scrollfix.js +shifter [info] istanbul providing coverage +shifter [queu] instrumenting with istanbul +shifter [queu] writing coverage file to gallery-scrollfix/gallery-scrollfix-coverage.js +shifter [info] done racing, the gears are toast +shifter [info] finished in 0.232 seconds, pretty fast huh? diff --git a/src/gallery-scrollfix/logs/tests.json b/src/gallery-scrollfix/logs/tests.json new file mode 100644 index 0000000000..d15e2bccbd --- /dev/null +++ b/src/gallery-scrollfix/logs/tests.json @@ -0,0 +1,865 @@ +{ + "name": "gallery-scrollfix", + "passed": 4, + "failed": 0, + "errors": 0, + "ignored": 0, + "total": 4, + "duration": 43, + "type": "report", + "Automated Tests": { + "name": "Automated Tests", + "passed": 4, + "failed": 0, + "errors": 0, + "ignored": 0, + "total": 4, + "duration": 42, + "type": "testcase", + "test: plug namespace": { + "result": "pass", + "message": "Test passed", + "type": "test", + "name": "test: plug namespace", + "duration": 2 + }, + "test: mouseenter attaches mousewheelListener": { + "result": "pass", + "message": "Test passed", + "type": "test", + "name": "test: mouseenter attaches mousewheelListener", + "duration": 3 + }, + "test: mouseleave detaches mousewheelListener": { + "result": "pass", + "message": "Test passed", + "type": "test", + "name": "test: mouseleave detaches mousewheelListener", + "duration": 2 + }, + "test: destructor detaches mousewheelListener": { + "result": "pass", + "message": "Test passed", + "type": "test", + "name": "test: destructor detaches mousewheelListener", + "duration": 1 + } + }, + "timestamp": "Wed 12 Dec 2012 03:12:57 PM CST", + "coverage": { + "build/cdn_gallery-2012.12.12-21-11/": { + "path": "build/cdn_gallery-2012.12.12-21-11/", + "s": { + "1": 1, + "2": 1, + "3": 4, + "4": 1, + "5": 1, + "6": 1, + "7": 4, + "8": 0, + "9": 4, + "10": 4, + "11": 0, + "12": 1, + "13": 4, + "14": 4, + "15": 9, + "16": 9, + "17": 0, + "18": 0, + "19": 0, + "20": 0, + "21": 0, + "22": 0, + "23": 4, + "24": 3, + "25": 3, + "26": 4, + "27": 2, + "28": 2, + "29": 1 + }, + "b": { + "1": [ + 0, + 4 + ], + "2": [ + 4, + 0 + ], + "3": [ + 0, + 0 + ], + "4": [ + 0, + 0 + ], + "5": [ + 0, + 0 + ], + "6": [ + 0, + 0 + ], + "7": [ + 0, + 0 + ], + "8": [ + 2, + 2 + ] + }, + "f": { + "1": 1, + "2": 4, + "3": 4, + "4": 4, + "5": 9, + "6": 0, + "7": 3, + "8": 4 + }, + "fnMap": { + "1": { + "name": "(anonymous_1)", + "line": 1, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 48 + } + } + }, + "2": { + "name": "NodeScrollFix", + "line": 20, + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "3": { + "name": "(anonymous_3)", + "line": 37, + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 26 + } + } + }, + "4": { + "name": "(anonymous_4)", + "line": 48, + "loc": { + "start": { + "line": 48, + "column": 17 + }, + "end": { + "line": 48, + "column": 38 + } + } + }, + "5": { + "name": "(anonymous_5)", + "line": 51, + "loc": { + "start": { + "line": 51, + "column": 23 + }, + "end": { + "line": 51, + "column": 40 + } + } + }, + "6": { + "name": "(anonymous_6)", + "line": 53, + "loc": { + "start": { + "line": 53, + "column": 52 + }, + "end": { + "line": 53, + "column": 65 + } + } + }, + "7": { + "name": "(anonymous_7)", + "line": 70, + "loc": { + "start": { + "line": 70, + "column": 23 + }, + "end": { + "line": 70, + "column": 40 + } + } + }, + "8": { + "name": "(anonymous_8)", + "line": 75, + "loc": { + "start": { + "line": 75, + "column": 13 + }, + "end": { + "line": 75, + "column": 24 + } + } + } + }, + "statementMap": { + "1": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 84, + "column": 62 + } + }, + "2": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 22, + "column": 1 + } + }, + "3": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 61 + } + }, + "4": { + "start": { + "line": 23, + "column": 0 + }, + "end": { + "line": 23, + "column": 41 + } + }, + "5": { + "start": { + "line": 24, + "column": 0 + }, + "end": { + "line": 24, + "column": 31 + } + }, + "6": { + "start": { + "line": 25, + "column": 0 + }, + "end": { + "line": 46, + "column": 2 + } + }, + "7": { + "start": { + "line": 38, + "column": 3 + }, + "end": { + "line": 42, + "column": 4 + } + }, + "8": { + "start": { + "line": 39, + "column": 4 + }, + "end": { + "line": 39, + "column": 24 + } + }, + "9": { + "start": { + "line": 40, + "column": 10 + }, + "end": { + "line": 42, + "column": 4 + } + }, + "10": { + "start": { + "line": 41, + "column": 4 + }, + "end": { + "line": 41, + "column": 17 + } + }, + "11": { + "start": { + "line": 43, + "column": 3 + }, + "end": { + "line": 43, + "column": 36 + } + }, + "12": { + "start": { + "line": 47, + "column": 0 + }, + "end": { + "line": 81, + "column": 3 + } + }, + "13": { + "start": { + "line": 49, + "column": 2 + }, + "end": { + "line": 49, + "column": 30 + } + }, + "14": { + "start": { + "line": 51, + "column": 2 + }, + "end": { + "line": 69, + "column": 10 + } + }, + "15": { + "start": { + "line": 52, + "column": 3 + }, + "end": { + "line": 52, + "column": 35 + } + }, + "16": { + "start": { + "line": 53, + "column": 3 + }, + "end": { + "line": 68, + "column": 6 + } + }, + "17": { + "start": { + "line": 54, + "column": 4 + }, + "end": { + "line": 56, + "column": 44 + } + }, + "18": { + "start": { + "line": 58, + "column": 4 + }, + "end": { + "line": 67, + "column": 5 + } + }, + "19": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 66, + "column": 6 + } + }, + "20": { + "start": { + "line": 62, + "column": 6 + }, + "end": { + "line": 62, + "column": 26 + } + }, + "21": { + "start": { + "line": 63, + "column": 12 + }, + "end": { + "line": 66, + "column": 6 + } + }, + "22": { + "start": { + "line": 65, + "column": 6 + }, + "end": { + "line": 65, + "column": 26 + } + }, + "23": { + "start": { + "line": 70, + "column": 2 + }, + "end": { + "line": 73, + "column": 10 + } + }, + "24": { + "start": { + "line": 71, + "column": 3 + }, + "end": { + "line": 71, + "column": 36 + } + }, + "25": { + "start": { + "line": 72, + "column": 3 + }, + "end": { + "line": 72, + "column": 34 + } + }, + "26": { + "start": { + "line": 76, + "column": 2 + }, + "end": { + "line": 79, + "column": 3 + } + }, + "27": { + "start": { + "line": 77, + "column": 3 + }, + "end": { + "line": 77, + "column": 36 + } + }, + "28": { + "start": { + "line": 78, + "column": 3 + }, + "end": { + "line": 78, + "column": 34 + } + }, + "29": { + "start": { + "line": 82, + "column": 0 + }, + "end": { + "line": 82, + "column": 52 + } + } + }, + "branchMap": { + "1": { + "line": 38, + "type": "if", + "locations": [ + { + "start": { + "line": 38, + "column": 3 + }, + "end": { + "line": 38, + "column": 3 + } + }, + { + "start": { + "line": 38, + "column": 3 + }, + "end": { + "line": 38, + "column": 3 + } + } + ] + }, + "2": { + "line": 40, + "type": "if", + "locations": [ + { + "start": { + "line": 40, + "column": 10 + }, + "end": { + "line": 40, + "column": 10 + } + }, + { + "start": { + "line": 40, + "column": 10 + }, + "end": { + "line": 40, + "column": 10 + } + } + ] + }, + "3": { + "line": 58, + "type": "if", + "locations": [ + { + "start": { + "line": 58, + "column": 4 + }, + "end": { + "line": 58, + "column": 4 + } + }, + { + "start": { + "line": 58, + "column": 4 + }, + "end": { + "line": 58, + "column": 4 + } + } + ] + }, + "4": { + "line": 60, + "type": "if", + "locations": [ + { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 5 + } + }, + { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 5 + } + } + ] + }, + "5": { + "line": 60, + "type": "binary-expr", + "locations": [ + { + "start": { + "line": 60, + "column": 9 + }, + "end": { + "line": 60, + "column": 26 + } + }, + { + "start": { + "line": 60, + "column": 30 + }, + "end": { + "line": 60, + "column": 55 + } + } + ] + }, + "6": { + "line": 63, + "type": "if", + "locations": [ + { + "start": { + "line": 63, + "column": 12 + }, + "end": { + "line": 63, + "column": 12 + } + }, + { + "start": { + "line": 63, + "column": 12 + }, + "end": { + "line": 63, + "column": 12 + } + } + ] + }, + "7": { + "line": 63, + "type": "binary-expr", + "locations": [ + { + "start": { + "line": 63, + "column": 16 + }, + "end": { + "line": 63, + "column": 33 + } + }, + { + "start": { + "line": 63, + "column": 37 + }, + "end": { + "line": 63, + "column": 70 + } + } + ] + }, + "8": { + "line": 76, + "type": "if", + "locations": [ + { + "start": { + "line": 76, + "column": 2 + }, + "end": { + "line": 76, + "column": 2 + } + }, + { + "start": { + "line": 76, + "column": 2 + }, + "end": { + "line": 76, + "column": 2 + } + } + ] + } + }, + "code": [ + "(function () { YUI.add('gallery-scrollfix', function (Y, NAME) {", + "", + "/**", + " * ScrollFix is a simple Node plugin that prevents mousewheel events inside", + " * the host node from bubbling up to parent nodes if the scroll has reached the", + " * bottom of the host node. This fixes an issue commonly seen in websites where", + " * the user scrolls an inner-scroll area but then the whole page moves as the", + " * scroll reaches the bottom of the inner-scroll area.", + " *", + " * @module gallery-scrollfix", + " **/", + "", + "/**", + " *

", + " * ScrollFix is a Node plugin that can be used to stop scroll events from", + " * escaping an inner scroll area when the scroll reaches the bottom of the area.", + " *

", + " * @class NodeScrollFix", + " */", + "function NodeScrollFix(/*config*/) {", + "\tNodeScrollFix.superclass.constructor.apply(this, arguments);", + "}", + "NodeScrollFix.NAME = 'gallery-scrollfix';", + "NodeScrollFix.NS = 'scrollfix';", + "NodeScrollFix.ATTRS = {", + "\t/**", + "\t * Defines a node or CSS selector to listen to for the mousewheel", + "\t * events. This defaults to the body element of the page and probably", + "\t * should not be altered in most cases.", + "\t *", + "\t * @attribute target", + "\t * @default Y.one('body')", + "\t * @type string | Y.Node", + "\t */", + "\ttarget: {", + "\t\tvalue: Y.one('body'),", + "\t\tsetter: function(value) {", + "\t\t\tif (typeof value === 'string') {", + "\t\t\t\treturn Y.one(value);", + "\t\t\t} else if (value instanceof Y.Node) {", + "\t\t\t\treturn value;", + "\t\t\t}", + "\t\t\treturn Y.Attribute.INVALID_VALUE;", + "\t\t}", + "\t}", + "};", + "Y.extend(NodeScrollFix, Y.Plugin.Base, {", + " initializer: function(/*config*/) {", + "\t\tvar host = this.get('host');", + "", + "\t\thost.on('mouseenter',function(/*ev*/) {", + "\t\t\tvar target = this.get('target');", + "\t\t\tthis.mouseWheelListener = target.on('mousewheel',function(ev) {", + "\t\t\t\tvar scrollNode = host.getDOMNode(),", + "\t\t\t\t\tremainingHeight = scrollNode.scrollHeight - scrollNode.scrollTop,", + "\t\t\t\t\tclientHeight = scrollNode.clientHeight;", + "\t\t\t\t// decide if we should prevent scrolling or not", + "\t\t\t\tif (scrollNode.scrollHeight > clientHeight) {", + "\t\t\t\t\t// scrollbars are visible", + "\t\t\t\t\tif (ev.wheelDelta > 0 && scrollNode.scrollTop <= 0) {", + "\t\t\t\t\t\t// scrolling up, and already at top", + "\t\t\t\t\t\tev.preventDefault();", + "\t\t\t\t\t} else if (ev.wheelDelta < 0 && remainingHeight <= clientHeight+1) {", + "\t\t\t\t\t\t// scrolling down and near enough the bottom already", + "\t\t\t\t\t\tev.preventDefault();", + "\t\t\t\t\t}", + "\t\t\t\t}", + "\t\t\t});", + "\t\t},this);", + "\t\thost.on('mouseleave',function(/*ev*/) {", + "\t\t\tthis.mouseWheelListener.detach();", + "\t\t\tthis.mouseWheelListener = null;", + "\t\t},this);", + "\t},", + "\tdestructor: function() {", + "\t\tif (this.mouseWheelListener) {", + "\t\t\tthis.mouseWheelListener.detach();", + "\t\t\tthis.mouseWheelListener = null;", + "\t\t}", + "\t}", + "});", + "Y.namespace('Plugin').NodeScrollFix = NodeScrollFix;", + "", + "}, '@VERSION@', {\"requires\": [\"event-mouseenter\", \"plugin\"]});", + "", + "}());" + ], + "l": { + "1": 1, + "20": 1, + "21": 4, + "23": 1, + "24": 1, + "25": 1, + "38": 4, + "39": 0, + "40": 4, + "41": 4, + "43": 0, + "47": 1, + "49": 4, + "51": 4, + "52": 9, + "53": 9, + "54": 0, + "58": 0, + "60": 0, + "62": 0, + "63": 0, + "65": 0, + "70": 4, + "71": 3, + "72": 3, + "76": 4, + "77": 2, + "78": 2, + "82": 1 + } + } + }, + "coverageType": "istanbul" +} diff --git a/src/gallery-scrollfix/logs/yogi.stderr.log b/src/gallery-scrollfix/logs/yogi.stderr.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/gallery-scrollfix/logs/yogi.stdout.log b/src/gallery-scrollfix/logs/yogi.stdout.log new file mode 100644 index 0000000000..94bb900bfa --- /dev/null +++ b/src/gallery-scrollfix/logs/yogi.stdout.log @@ -0,0 +1,32 @@ +yogi [info] using yogi@0.0.52 on node@0.8.15 +yogi [info] using module: gallery-scrollfix +yogi [info] prepping grover tests +yogi [info] adding tests route +yogi [info] listening on: http://127.0.0.1:5008 +yogi [info] turning on coverage support in grover +Starting Grover on 1 files with PhantomJS@1.7.0 + Running 15 concurrent tests at a time. + Using a 120 second timeout per test. +✔ [gallery-scrollfix]: Passed: 4 Failed: 0 Total: 4 (ignored 0) (0.043 seconds) 72% +Writing files in JSON format to: /src/gallery-scrollfix/logs/tests.json + +----------------+-----------+-----------+-----------+-----------+ +File | % Stmts |% Branches | % Funcs | % Lines | +----------------+-----------+-----------+-----------+-----------+ + build/ | 72.41 | 25 | 87.5 | 72.41 | + All files | 72.41 | 25 | 87.5 | 72.41 | +----------------+-----------+-----------+-----------+-----------+ +All files | 72.41 | 25 | 87.5 | 72.41 | +----------------+-----------+-----------+-----------+-----------+ + + +=============================== Coverage summary =============================== +Statements : 72.41% ( 21/29 ) +Branches : 25% ( 4/16 ) +Functions : 87.5% ( 7/8 ) +Lines : 72.41% ( 21/29 ) +================================================================================ +---------------------------------------------------------------- +✔ [Total]: Passed: 4 Failed: 0 Total: 4 (ignored 0) (0.043 seconds) + [Grover Execution Timer] 1.129 seconds +yogi [info] grover tests complete diff --git a/src/gallery-scrollfix/meta/gallery-scrollfix.json b/src/gallery-scrollfix/meta/gallery-scrollfix.json new file mode 100644 index 0000000000..0dbb70ccaf --- /dev/null +++ b/src/gallery-scrollfix/meta/gallery-scrollfix.json @@ -0,0 +1,7 @@ +{ + "gallery-scrollfix": { + "requires": [ + "event-mouseenter","plugin" + ] + } +} diff --git a/src/gallery-scrollfix/tests/unit/index.html b/src/gallery-scrollfix/tests/unit/index.html new file mode 100644 index 0000000000..52f13223fd --- /dev/null +++ b/src/gallery-scrollfix/tests/unit/index.html @@ -0,0 +1,51 @@ + + + + gallery-scrollfix + + + + + +
+
+
+
+
+ + + diff --git a/src/gallery-scrollfix/tests/unit/js/tests.js b/src/gallery-scrollfix/tests/unit/js/tests.js new file mode 100644 index 0000000000..9285bfa992 --- /dev/null +++ b/src/gallery-scrollfix/tests/unit/js/tests.js @@ -0,0 +1,51 @@ +YUI.add('module-tests', function(Y) { + + var suite = new Y.Test.Suite('gallery-scrollfix'); + + suite.add(new Y.Test.Case({ + name: 'Automated Tests', + setUp: function() { + var innerScroll = Y.one('.inner-scroll'); + innerScroll.plug(Y.Plugin.NodeScrollFix); + this.innerScroll = innerScroll; + }, + tearDown: function() { + this.innerScroll.unplug(Y.Plugin.NodeScrollFix); + this.innerScroll = null; + }, + 'test: plug namespace': function() { + Y.Assert.isNotUndefined(this.innerScroll.scrollfix,'Scrollfix namespace was not created'); + }, + 'test: mouseenter attaches mousewheelListener': function() { + var innerScroll = this.innerScroll; + + innerScroll.simulate('mouseover',{relatedTarget: document.body}); + Y.Assert.isNotNull(innerScroll.scrollfix.mouseWheelListener,'mouseWheelListener did not attach'); + }, + 'test: mouseleave detaches mousewheelListener': function() { + var innerScroll = this.innerScroll; + + innerScroll.simulate('mouseover',{relatedTarget: document.body}); + Y.Assert.isNotNull(innerScroll.scrollfix.mouseWheelListener,'mouseWheelListener did not attach'); + + innerScroll.simulate('mouseout',{relatedTarget: document.body}); + Y.Assert.isNull(innerScroll.scrollfix.mouseWheelListener,'mouseWheelListener did not detach'); + }, + 'test: destructor detaches mousewheelListener': function() { + var innerScroll = this.innerScroll; + + innerScroll.simulate('mouseover',{relatedTarget: document.body}); + Y.Assert.isNotNull(innerScroll.scrollfix.mouseWheelListener,'mouseWheelListener did not attach'); + var mouseWheelListener = innerScroll.scrollfix.mouseWheelListener; + + this.innerScroll.unplug(Y.Plugin.NodeScrollFix); + Y.Assert.isTrue(mouseWheelListener.sub.deleted,'mouseWheelListener did not detach'); + + Y.Assert.isUndefined(innerScroll.scrollfix,'unplug did not remove namespace'); + } + })); + + Y.Test.Runner.add(suite); + + +},'', { requires: [ 'test', 'node', 'node-event-simulate', 'gallery-scrollfix' ] });