Skip to content

Commit

Permalink
replace $j with $ added function wrap to vastAdParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dale committed Jul 5, 2012
1 parent f3a05cc commit c435e86
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 56 deletions.
88 changes: 46 additions & 42 deletions modules/AdSupport/resources/mw.VastAdParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* VAST ad parser ( presently just works with VAST once there are more ad formats
* we could abstract common parts of this parser process.
*/
( function( mw, $ ) { "use strict";

mw.VastAdParser = {
/**
* VAST support
Expand All @@ -10,15 +12,15 @@ mw.VastAdParser = {
parse: function( xmlObject ){
var _this = this;
var adConf = {};
var $vast = $j( xmlObject );
var $vast = $( xmlObject );
// Get the basic set of sequences
adConf.ads = [];
$vast.find( 'Ad' ).each( function( inx, node ){
mw.log( 'VastAdParser:: getVastAdDisplayConf: ' + node );
var $ad = $j( node );
var $ad = $( node );

// Set a local pointer to the current sequence:
var currentAd = { 'id' : $j( node ).attr('id') };
var currentAd = { 'id' : $( node ).attr('id') };

// Set duration
if( $ad.find('duration') ){
Expand All @@ -29,11 +31,11 @@ mw.VastAdParser = {
currentAd.impressions = [];
$ad.find( 'Impression' ).each( function(na, node){
// Check if there is lots of impressions or just one:
if( $j(node).find('URL').length ){
if( $(node).find('URL').length ){
$ad.find('URL').each( function( na, urlNode ){
currentAd.impressions.push({
'beaconUrl' : _this.getURLFromNode( urlNode ),
'idtype' : $j( urlNode ).attr('id')
'idtype' : $( urlNode ).attr('id')
});
});
} else {
Expand Down Expand Up @@ -62,7 +64,7 @@ mw.VastAdParser = {
}
$ad.find( selector ).each( function( na, trackingNode ){
currentAd.trackingEvents.push({
'eventName' : $j( trackingNode ).attr('event'),
'eventName' : $( trackingNode ).attr('event'),
'beaconUrl' : _this.getURLFromNode( trackingNode )
});
});
Expand All @@ -71,7 +73,7 @@ mw.VastAdParser = {
// Set the media file:
$ad.find('MediaFiles MediaFile').each( function( na, mediaFile ){
// Add the video source ( if an html5 compatible type )
var type = $j( mediaFile ).attr('type');
var type = $( mediaFile ).attr('type');
// Normalize mp4 into h264 format:
if( type == 'video/x-mp4' || type == 'video/mp4' ){
type = 'video/h264';
Expand Down Expand Up @@ -128,20 +130,20 @@ mw.VastAdParser = {
var resourceObj = {};
var companionAttr = [ 'width', 'height', 'id', 'expandedWidth', 'expandedHeight' ];
$j.each( companionAttr, function(na, attr){
if( $j( resourceNode ).attr( attr ) ){
resourceObj[ attr ] = $j( resourceNode ).attr( attr );
if( $( resourceNode ).attr( attr ) ){
resourceObj[ attr ] = $( resourceNode ).attr( attr );
}
});

// Check for attribute based static resource:
if( $j( resourceNode ).attr('creativeType') && $j( resourceNode ).attr('resourceType') == 'static' ){
var link = _this.getURLFromNode ( $j( resourceNode ).find('NonLinearClickThrough') );
resourceObj.$html = $j('<a />')
if( $( resourceNode ).attr('creativeType') && $( resourceNode ).attr('resourceType') == 'static' ){
var link = _this.getURLFromNode ( $( resourceNode ).find('NonLinearClickThrough') );
resourceObj.$html = $('<a />')
.attr({
'href' : link,
'target' : '_new'
}).append(
$j( '<img/>').attr({
$( '<img/>').attr({
'src': _this.getURLFromNode ( resourceNode ),
'width' : resourceObj['width'],
'height' : resourceObj['height']
Expand All @@ -150,37 +152,37 @@ mw.VastAdParser = {
};

// Check for companion type:
if( $j( resourceNode ).find( 'StaticResource' ).length ) {
if( $j( resourceNode ).find( 'StaticResource' ).attr('creativeType') ) {
if( $( resourceNode ).find( 'StaticResource' ).length ) {
if( $( resourceNode ).find( 'StaticResource' ).attr('creativeType') ) {
resourceObj.$html = _this.getStaticResourceHtml( resourceNode, resourceObj );
mw.log("VastAdParser::getResourceObject: StaticResource \n" + $j('<div />').append( resourceObj.$html ).html() );
mw.log("VastAdParser::getResourceObject: StaticResource \n" + $('<div />').append( resourceObj.$html ).html() );
}
}

// Check for iframe type
if( $j( resourceNode ).find('IFrameResource').length ){
mw.log("VastAdParser::getResourceObject: IFrameResource \n" + _this.getURLFromNode ( $j( resourceNode ).find('IFrameResource') ) );
if( $( resourceNode ).find('IFrameResource').length ){
mw.log("VastAdParser::getResourceObject: IFrameResource \n" + _this.getURLFromNode ( $( resourceNode ).find('IFrameResource') ) );
resourceObj.$html =
$j('<iframe />').attr({
'src' : _this.getURLFromNode ( $j( resourceNode ).find('IFrameResource') ),
$('<iframe />').attr({
'src' : _this.getURLFromNode ( $( resourceNode ).find('IFrameResource') ),
'width' : resourceObj['width'],
'height' : resourceObj['height'],
'border' : '0px'
});
}

// Check for html type
if( $j( resourceNode ).find('HTMLResource').length ){
mw.log("VastAdParser::getResourceObject: HTMLResource \n" + _this.getURLFromNode ( $j( resourceNode ).find('HTMLResource') ) );
if( $( resourceNode ).find('HTMLResource').length ){
mw.log("VastAdParser::getResourceObject: HTMLResource \n" + _this.getURLFromNode ( $( resourceNode ).find('HTMLResource') ) );
// Wrap the HTMLResource in a jQuery call:
resourceObj.$html = $j( _this.getURLFromNode ( $j( resourceNode ).find('HTMLResource') ) );
resourceObj.$html = $( _this.getURLFromNode ( $( resourceNode ).find('HTMLResource') ) );
}
// If no resource html was built out return false
if( !resourceObj.$html){
return false;
}
// Export the html to static representation:
resourceObj.html = $j('<div />').html( resourceObj.$html ).html();
resourceObj.html = $('<div />').html( resourceObj.$html ).html();

return resourceObj;
},
Expand All @@ -193,68 +195,68 @@ mw.VastAdParser = {
*/
getStaticResourceHtml: function( companionNode, companionObj ){
var _this = this;
companionObj['contentType'] = $j( companionNode ).find( 'StaticResource' ).attr('creativeType');
companionObj['contentType'] = $( companionNode ).find( 'StaticResource' ).attr('creativeType');
companionObj['resourceUri'] = _this.getURLFromNode(
$j( companionNode ).find( 'StaticResource' )
$( companionNode ).find( 'StaticResource' )
);

// Build companionObj html
$companionHtml = $j('<div />');
$companionHtml = $('<div />');
switch( companionObj['contentType'] ){
case 'image/gif':
case 'image/jpeg':
case 'image/png':
var $img = $j('<img />').attr({
var $img = $('<img />').attr({
'src' : companionObj['resourceUri']
})
.css({
'width' : companionObj['width'] + 'px',
'height' : companionObj['height'] + 'px'
});

if( $j( companionNode ).find('AltText').text() != '' ){
if( $( companionNode ).find('AltText').text() != '' ){
$img.attr('alt', _this.getURLFromNode(
$j( companionNode ).find('AltText')
$( companionNode ).find('AltText')
)
);
}
// Add the image to the $companionHtml
if( $j( companionNode ).find('CompanionClickThrough').text() != '' ){
$companionHtml = $j('<a />')
if( $( companionNode ).find('CompanionClickThrough').text() != '' ){
$companionHtml = $('<a />')
.attr({
'href' : _this.getURLFromNode(
$j( companionNode ).find('CompanionClickThrough,NonLinearClickThrough')[0]
$( companionNode ).find('CompanionClickThrough,NonLinearClickThrough')[0]
)
}).append( $img );
} else {
$companionHtml = $img;
}
break;
case 'application/x-shockwave-flash':
var flashObjectId = $j( companionNode ).attr('id') + '_flash';
var flashObjectId = $( companionNode ).attr('id') + '_flash';
// @@FIXME we have to A) load this via a proxy
// and B) use smokescreen.js or equivalent to "try" and render on iPad
$companionHtml = $j('<OBJECT />').attr({
$companionHtml = $('<OBJECT />').attr({
'classid' : "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
'codebase' : "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0",
'WIDTH' : companionObj['width'] ,
"HEIGHT" : companionObj['height'],
"id" : flashObjectId
})
.append(
$j('<PARAM />').attr({
$('<PARAM />').attr({
'NAME' : 'movie',
'VALUE' : companionObj['resourceUri']
}),
$j('<PARAM />').attr({
$('<PARAM />').attr({
'NAME' : 'quality',
'VALUE' : 'high'
}),
$j('<PARAM />').attr({
$('<PARAM />').attr({
'NAME' : 'bgcolor',
'VALUE' : '#FFFFFF'
}),
$j('<EMBED />').attr({
$('<EMBED />').attr({
'href' : companionObj['resourceUri'],
'quality' : 'high',
'bgcolor' : '#FFFFFF',
Expand All @@ -275,12 +277,14 @@ mw.VastAdParser = {
* return the text value
*/
getURLFromNode: function ( node ){
if( $j( node ).find('URL').length ){
if( $( node ).find('URL').length ){
// use the first url we find:
node = $j( node ).find( 'URL' )[0];
node = $( node ).find( 'URL' )[0];
}
return $j.trim( decodeURIComponent( $j( node ).text() ) )
return $j.trim( decodeURIComponent( $( node ).text() ) )
.replace( /^\<\!\-?\-?\[CDATA\[/, '' )
.replace(/\]\]\-?\-?\>/, '');
}
};

} )( window.mw, window.jQuery );
2 changes: 1 addition & 1 deletion modules/EmbedPlayer/tests/Player_DynamicEmbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

mw.load('EmbedPlayer', function(){
// seems to trip a bug in IE8/win7
$j('#mwplayer').embedPlayer({
$('#mwplayer').embedPlayer({
'poster' : "http://cdn.kaltura.org/apis/html5lib/kplayer-examples/media/bbb480.jpg",
'sources':[{
'src':'http://cdn.kaltura.org/apis/html5lib/kplayer-examples/media/bbb_trailer_iphone.m4v',
Expand Down
3 changes: 3 additions & 0 deletions modules/KalturaSupport/KalturaSupport.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@

// Make sure kWidget is part of EmbedPlayer dependencies if we have a uiConf id
$( mw ).bind( 'EmbedPlayerUpdateDependencies', function( event, playerElement, dependencySet ){
if( mw.getConfig( 'KalturaSupport.DepModuleList') ){
$.merge( dependencySet, mw.getConfig( 'KalturaSupport.DepModuleList') );
}
if( $( playerElement ).attr( 'kwidgetid' ) && $( playerElement ).attr( 'kuiconfid' ) ){
dependencySet.push( 'mw.KWidgetSupport' );
}
Expand Down
14 changes: 11 additions & 3 deletions modules/KalturaSupport/kalturaIframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ function getPath() {
* Get all the kaltura defined modules from player config
* */
function outputKalturaModules(){
$o='';
// Init modules array, always include MwEmbedSupport
$moduleList = array( 'mw.MwEmbedSupport' );

Expand All @@ -596,14 +597,21 @@ function outputKalturaModules(){
}
}
}
// Have all the kaltura related plugins listed in a configuration var for
// implicte dependency mapping before embedding embedPlayer
$o.= ResourceLoader::makeConfigSetScript( array(
'KalturaSupport.DepModuleList' => $moduleList
));

// Special cases: handle plugins that have more complex conditional load calls
// always include mw.EmbedPlayer
$moduleList[] = 'mw.EmbedPlayer';

// Load all the known required libraries:
return ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.load', array( $moduleList ) )
);
$o.= ResourceLoader::makeLoaderConditionalScript(
Xml::encodeJsCall( 'mw.loader.load', array( $moduleList ) )
);
return $o;
}

function outputIFrame( ){
Expand Down
12 changes: 6 additions & 6 deletions modules/MwEmbedSupport/mediawiki/mediawiki.language.parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

( function( mw, $j ) {
( function( mw, $ ) {

/**
* Helper for functions that want to accept variadic arguments after a certain argument offset, to have it
Expand All @@ -30,7 +30,7 @@
* Returns a function suitable for use as a global, to construct strings from the message key (and optional replacements).
* e.g.
* window.gM = mediaWiki.parser.getMessageFunction( options );
* $j( 'p#headline' ).html( gM( 'hello-user', username ) );
* $( 'p#headline' ).html( gM( 'hello-user', username ) );
*
* Like the old gM() function this returns only strings, so it destroys any bindings. If you want to preserve bindings use the
* jQuery plugin version instead. This is only included for backwards compatibility with gM().
Expand All @@ -57,8 +57,8 @@
* the current selector. Bindings to passed-in jquery elements are preserved. Functions become click handlers for [$1 linktext] links.
* e.g.
* $j.fn.msg = mediaWiki.parser.getJqueryPlugin( options );
* var userlink = $j( '<a>' ).click( function() { alert( "hello!!") } );
* $j( 'p#headline' ).msg( 'hello-user', userlink );
* var userlink = $( '<a>' ).click( function() { alert( "hello!!") } );
* $( 'p#headline' ).msg( 'hello-user', userlink );
*
* @param {Array} parser options
* @return {Function} function suitable for assigning to jQuery plugin, such as $j.fn.msg
Expand Down Expand Up @@ -534,7 +534,7 @@
* @return {jQuery}
*/
concat: function( nodes ) {
var span = $j( '<span>' ).addClass( 'mediaWiki_htmlEmitter' );
var span = $( '<span>' ).addClass( 'mediaWiki_htmlEmitter' );
$j.each( nodes, function( i, node ) {
if ( node instanceof jQuery && node.hasClass( 'mediaWiki_htmlEmitter' ) ) {
$j.each( node.contents(), function( j, childNode ) {
Expand Down Expand Up @@ -586,7 +586,7 @@
if ( arg instanceof jQuery ) {
$el = arg;
} else {
$el = $j( '<a>' );
$el = $( '<a>' );
if ( typeof arg === 'function' ) {
$el.click( arg ).attr( 'href', '#' );
} else {
Expand Down
8 changes: 4 additions & 4 deletions mwEmbedFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ function outputIFrame( ){

mw.ready(function(){
// Bind window resize to reize the player:
$j(window).resize(function(){
$j( '#<?php echo htmlspecialchars( $this->playerIframeId )?>' )
$(window).resize(function(){
$( '#<?php echo htmlspecialchars( $this->playerIframeId )?>' )
[0].resizePlayer({
'width' : $j(window).width(),
'height' : $j(window).height()
'width' : $(window).width(),
'height' : $(window).height()
});
});
});
Expand Down

0 comments on commit c435e86

Please sign in to comment.