Browse files

Merge commit 'rick/t487' into 0.5

  • Loading branch information...
2 parents dc1c887 + e5fc341 commit b7b3509b58ef7b53ac46b97b79fb40c1160017bb @annasob annasob committed Apr 21, 2011
Showing with 49 additions and 49 deletions.
  1. +36 −33 popcorn.js
  2. +13 −16 test/popcorn.unit.js
View
69 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
View
29 test/popcorn.unit.js
@@ -51,7 +51,7 @@ test("API", function () {
test("Utility", function () {
- expect(7);
+ expect(8);
// TODO: comprehensive tests for these utilities
equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function");
@@ -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 );
});

0 comments on commit b7b3509

Please sign in to comment.