Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #12 from dseif/t978
Browse files Browse the repository at this point in the history
[#978] fixed issue where Popcorn no longer accepted a HTML video or audio element in it's constructor
  • Loading branch information
dseif committed Mar 22, 2012
2 parents 3bd49b6 + 61cd6aa commit 8f7f564
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 7 additions & 13 deletions popcorn.js
Expand Up @@ -30,9 +30,6 @@
// Copy global Popcorn (may not exist)
_Popcorn = global.Popcorn,

// ID string matching
rIdExp = /^(#([\w\-\_\.]+))$/,

// Ready fn cache
readyStack = [],
readyBound = false,
Expand Down Expand Up @@ -199,19 +196,16 @@
return;
}

// Check if entity is a valid string id
matches = rIdExp.exec( entity );

try {
document.querySelector( entity );
} catch(e) {
throw new Error( "Popcorn.js Error: Invalid media element selector: " + entity );
if ( typeof entity === "string" ) {
try {
matches = document.querySelector( entity );
} catch( e ) {
throw new Error( "Popcorn.js Error: Invalid media element selector: " + entity );
}
}

// Get media element by id or object reference
this.media = matches && matches.length && matches[ 2 ] ?
document.getElementById( matches[ 2 ] ) :
entity;
this.media = matches || entity;

// Create an audio or video element property reference
this[ ( this.media.nodeName && this.media.nodeName.toLowerCase() ) || "video" ] = this.media;
Expand Down
10 changes: 9 additions & 1 deletion test/popcorn.unit.js
Expand Up @@ -703,14 +703,22 @@ test( "Instance", function() {

});

test( "Bogus Selector", 1, function() {
test( "Bogus Selector", 2, function() {
try {
Popcorn( "#[object HTMLDivElement]" );

ok(false, "Should not fail silently" );
} catch(e) {
ok( true, "Exception raised on bogus selector: " + e.message );
}

try {
Popcorn( document.getElementById( "video" ) );

ok( true, "No error is raised for using the media element itself" );
} catch( e ) {
ok( false, "Exception thrown for using a valid media element" );
}
});

module( "Popcorn Static" );
Expand Down

0 comments on commit 8f7f564

Please sign in to comment.