From e5fc341c22feed021ba2777316a7fe6f19d45bab Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 21 Apr 2011 17:37:04 -0400 Subject: [PATCH] [#487] Adds unit test --- popcorn.js | 69 +++++++++++++++++++++++--------------------- test/popcorn.unit.js | 27 ++++++++--------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/popcorn.js b/popcorn.js index 3050b66..4118f0e 100644 --- a/popcorn.js +++ b/popcorn.js @@ -327,7 +327,36 @@ isArray: Array.isArray || function( array ) { return toString.call( array ) === "[object Array]"; }, - nop: function () {} + + nop: function () {}, + + position: function( elem ) { + + var clientRect = elem.getBoundingClientRect(), + bounds = {}, + doc = elem.ownerDocument, + docElem = document.documentElement, + body = document.body, + clientTop, clientLeft, scrollTop, scrollLeft, top, left; + + // Determine correct clientTop/Left + clientTop = docElem.clientTop || body.clientTop || 0; + clientLeft = docElem.clientLeft || body.clientLeft || 0; + + // Determine correct scrollTop/Left + scrollTop = ( global.pageYOffset && docElem.scrollTop || body.scrollTop ); + scrollLeft = ( global.pageXOffset && docElem.scrollLeft || body.scrollLeft ); + + // Temp top/left + top = Math.ceil( clientRect.top + scrollTop - clientTop ); + left = Math.ceil( clientRect.left + scrollLeft - clientLeft ); + + for ( var p in clientRect ) { + bounds[ p ] = Math.round( clientRect[ p ] ); + } + + return Popcorn.extend({}, bounds, { top: top, left: left }); + } }); // Memoized GUID Counter @@ -394,34 +423,8 @@ return this; }, - - // Popcorn Object Element Utils position: function() { - var media = this.media, - clientRect = media.getBoundingClientRect(), - bounds = {}, - doc = media.ownerDocument, - docElem = document.documentElement, - body = document.body, - clientTop, clientLeft, scrollTop, scrollLeft, top, left; - - // Determine correct clientTop/Left - clientTop = docElem.clientTop || body.clientTop || 0; - clientLeft = docElem.clientLeft || body.clientLeft || 0; - - // Determine correct scrollTop/Left - scrollTop = ( global.pageYOffset && docElem.scrollTop || body.scrollTop ); - scrollLeft = ( global.pageXOffset && docElem.scrollLeft || body.scrollLeft ); - - // Temp top/left - top = Math.ceil( clientRect.top + scrollTop - clientTop ); - left = Math.ceil( clientRect.left + scrollLeft - clientLeft ); - - for ( var p in clientRect ) { - bounds[ p ] = Math.round( clientRect[ p ] ); - } - - return Popcorn.extend({}, bounds, { top: top, left: left }); + return Popcorn.position( this.media ); } }); @@ -856,8 +859,8 @@ return plugin; }; - // Popcorn Plugin Inheritance Helper Methods - // Internal use only + // Popcorn Plugin Inheritance Helper Methods + // Internal use only Popcorn.plugin.getDefinition = function( name ) { var registry = Popcorn.registryByName; @@ -869,7 +872,7 @@ Popcorn.error( "Cannot inherit from "+ name +"; Object does not exist" ); }; - // Internal use only + // Internal use only Popcorn.plugin.delegate = function( instance, name, plugins ) { return function() { @@ -882,7 +885,7 @@ }; }; - // Plugin inheritance + // Plugin inheritance Popcorn.plugin.inherit = function( name, parents, definition, manifest ) { @@ -939,7 +942,7 @@ return pluginFn; }; - // Augment Popcorn; + // Augment Popcorn; Popcorn.inherit = Popcorn.plugin.inherit; // stores parsers keyed on filetype diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 15a2f82..b29df6e 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -61,10 +61,7 @@ test("Utility", function () { equals( typeof Popcorn.sizeOf, "function" , "Popcorn.sizeOf is a provided utility function"); equals( typeof Popcorn.nop, "function" , "Popcorn.nop is a provided utility function"); equals( typeof Popcorn.addTrackEvent, "function" , "Popcorn.addTrackEvent is a provided utility function"); - - - - + equals( typeof Popcorn.position, "function" , "Popcorn.position is a provided utility function"); }); test("Standard Time Strings" , function () { @@ -465,15 +462,15 @@ test("exec", function () { module("Popcorn Position"); test("position", function () { - expect(25); - + expect(25); + var $absolute = $(".absolute"), $relative = $(".relative"), $fixed = $(".fixed"), $static = $(".static"), tests; - $("#position-tests").show(); + $("#position-tests").show(); // console.log( $absolute ); // console.log( $fixed ); // console.log( $relative ); @@ -529,7 +526,7 @@ test("position", function () { ok( false, e ); } - $("#position-tests").hide(); + $("#position-tests").hide(); }); test("position called from plugin", function () { @@ -2372,14 +2369,14 @@ test("Last Check", function () { } catch (e) {}; - // Trigger follow-up tests to run in iframes - (function( $ ) { + // Trigger follow-up tests to run in iframes + (function( $ ) { - $("iframe[data-src]").attr( "src", function() { - return $(this).data("src"); - }); - - })( jQuery ); + $("iframe[data-src]").attr( "src", function() { + return $(this).data("src"); + }); + + })( jQuery ); }); -- 2.43.0