]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#487] Adds unit test
authorrwldrn <waldron.rick@gmail.com>
Thu, 21 Apr 2011 21:37:04 +0000 (17:37 -0400)
committerrwldrn <waldron.rick@gmail.com>
Thu, 21 Apr 2011 21:37:04 +0000 (17:37 -0400)
popcorn.js
test/popcorn.unit.js

index 3050b66205950ef4d3516b6fc7f1e32142b07663..4118f0e4388a50663066f9ed60da5d5d4d134774 100644 (file)
     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
 
       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 );
     }
   });
 
     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;
     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() {
     };
   };
 
-       //      Plugin inheritance
+  //  Plugin inheritance
   Popcorn.plugin.inherit = function( name, parents, definition, manifest ) {
 
 
     return pluginFn;
   };
 
-       // Augment Popcorn; 
+  // Augment Popcorn; 
   Popcorn.inherit = Popcorn.plugin.inherit;
 
   // stores parsers keyed on filetype
index 15a2f820ff76eb5336a775523603e39d6bb8d552..b29df6e1865853af258e9a28b0841df3b974bff3 100644 (file)
@@ -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 );
 
 });