MediaWiki: Common.js

From ShareRice Wiki (AFN)
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
maxWidth: 425,
 
maxWidth: 425,
 
maxHeight: 350,
 
maxHeight: 350,
containers: [],
+
cache: {},
embeds: [],
+
flowplayers: {},
 
restores: [],
 
restores: [],
 
container:  function(id){ return(jQuery('#af-media-embed-container_' + id)); },
 
container:  function(id){ return(jQuery('#af-media-embed-container_' + id)); },
embed:      function(id){ return(jQuery('#af-media-embed_' + id));           },
+
embed:      function(id){ return(jQuery('#af-media-href_' + id).length ? jQuery('#af-media-href_' + id) : jQuery('#af-media-embed_' + id)); },
 
restore:    function(id){ return(jQuery('#af-media-restore_' + id));        },
 
restore:    function(id){ return(jQuery('#af-media-restore_' + id));        },
 
ratio:      function(id) { return(_asianfuse.container(id_num).height() / _asianfuse.embed(id_num).height()); },
 
ratio:      function(id) { return(_asianfuse.container(id_num).height() / _asianfuse.embed(id_num).height()); },
 
is_maximized: function(id) {
 
is_maximized: function(id) {
return parseInt(this.container(id).height()) == (this.maxHeight * this.ratio(id)) && parseInt(this.container(id).width()) == parseInt(_asianfuse.maxWidth);
+
return parseInt(this.container(id).height()) == parseInt(this.maxHeight * this.ratio(id)) && parseInt(this.container(id).width()) == parseInt(_asianfuse.maxWidth);
 
}
 
}
 
}
 
}
Line 20: Line 20:
 
id_num = this.id.split('_', 2)[1]
 
id_num = this.id.split('_', 2)[1]
  
_asianfuse.containers[id_num] = { height: _asianfuse.container(id_num).height(), width: _asianfuse.container(id_num).width(), ratio: _asianfuse.ratio(id_num) }
+
_asianfuse.cache[id_num] = {  
_asianfuse.embeds[id_num]    = { height: _asianfuse.embed(id_num).height(),     width: _asianfuse.embed(id_num).width()     }
+
container_height: _asianfuse.container(id_num).height(),
 +
container_width: _asianfuse.container(id_num).width(),
 +
container_ratio: _asianfuse.ratio(id_num),
 +
embed_height: _asianfuse.embed(id_num).height(),
 +
embed_width: _asianfuse.embed(id_num).width()
 +
}
 
});
 
});
 
 
}
 
}
  
Line 31: Line 35:
  
 
if( e.which != 1 || _asianfuse.is_maximized(id_num) ) { return; }
 
if( e.which != 1 || _asianfuse.is_maximized(id_num) ) { return; }
 
 
_asianfuse.container(id_num).width(_asianfuse.maxWidth + 'px');
 
_asianfuse.container(id_num).width(_asianfuse.maxWidth + 'px');
_asianfuse.container(id_num).height((_asianfuse.maxHeight * _asianfuse.containers[id_num].ratio) + 'px');
+
_asianfuse.container(id_num).height((_asianfuse.maxHeight * _asianfuse.cache[id_num].container_ratio) + 'px');
  
 
_asianfuse.embed(id_num).width(_asianfuse.maxWidth + 'px');
 
_asianfuse.embed(id_num).width(_asianfuse.maxWidth + 'px');
Line 42: Line 45:
 
_asianfuse.restore(id_num).width((_asianfuse.maxWidth * 0.98) + 'px');
 
_asianfuse.restore(id_num).width((_asianfuse.maxWidth * 0.98) + 'px');
 
_asianfuse.restore(id_num).show();
 
_asianfuse.restore(id_num).show();
 +
if ( _asianfuse.flowplayers[id_num] != undefined ) {
 +
_asianfuse.flowplayers[id_num].load();
 +
}
 
});
 
});
 
}
 
}
Line 50: Line 56:
  
 
if( _asianfuse.is_maximized(id_num) ) {
 
if( _asianfuse.is_maximized(id_num) ) {
 +
if ( _asianfuse.flowplayers[id_num] != undefined ) {
 +
_asianfuse.flowplayers[id_num].stop();
 +
}
 
_asianfuse.restore(id_num).hide();
 
_asianfuse.restore(id_num).hide();
_asianfuse.embed(id_num).width(_asianfuse.embeds[id_num].width + 'px');
+
_asianfuse.embed(id_num).width(_asianfuse.cache[id_num].embed_width + 'px');
_asianfuse.embed(id_num).height(_asianfuse.embeds[id_num].height + 'px');
+
_asianfuse.embed(id_num).height(_asianfuse.cache[id_num].embed_height + 'px');
  
_asianfuse.container(id_num).width(_asianfuse.containers[id_num].width + 'px');
+
_asianfuse.container(id_num).width(_asianfuse.cache[id_num].container_width + 'px');
_asianfuse.container(id_num).height(_asianfuse.containers[id_num].height + 'px');
+
_asianfuse.container(id_num).height(_asianfuse.cache[id_num].container_height + 'px');
 
}
 
}
 
});
 
});
Line 65: Line 74:
 
setRestoreEvents();
 
setRestoreEvents();
 
}
 
}
 +
  
 
addOnloadHook( initAsianFuseVideoPanels );
 
addOnloadHook( initAsianFuseVideoPanels );

Latest revision as of 22:06, 21 September 2011

/* Any JavaScript here will be loaded for all users on every page load. */

var _asianfuse = {
	maxWidth: 425,
	maxHeight: 350,
	cache: {},
	flowplayers: {},
	restores: [],
	container:  function(id){ return(jQuery('#af-media-embed-container_' + id)); },
	embed:      function(id){ return(jQuery('#af-media-href_' + id).length ? jQuery('#af-media-href_' + id) : jQuery('#af-media-embed_' + id)); },
	restore:    function(id){ return(jQuery('#af-media-restore_' + id));         },
	ratio:      function(id) { return(_asianfuse.container(id_num).height() / _asianfuse.embed(id_num).height()); },
	is_maximized: function(id) {
		return parseInt(this.container(id).height()) == parseInt(this.maxHeight * this.ratio(id)) && parseInt(this.container(id).width()) == parseInt(_asianfuse.maxWidth);
	}
}

function setDefaults() {
	jQuery('.afv').each(function(i, el) {
		id_num = this.id.split('_', 2)[1]

		_asianfuse.cache[id_num] = { 
			container_height: _asianfuse.container(id_num).height(),
			container_width: _asianfuse.container(id_num).width(),
			container_ratio: _asianfuse.ratio(id_num), 
			embed_height: _asianfuse.embed(id_num).height(),
			embed_width: _asianfuse.embed(id_num).width()
		}
	});
}

function setMouseDownEvents() {
	jQuery('.afv').mousedown(function(e) {
		id_num = this.id.split('_', 2)[1];

		if( e.which != 1 || _asianfuse.is_maximized(id_num) ) { return; }
		_asianfuse.container(id_num).width(_asianfuse.maxWidth + 'px');
		_asianfuse.container(id_num).height((_asianfuse.maxHeight * _asianfuse.cache[id_num].container_ratio) + 'px');

		_asianfuse.embed(id_num).width(_asianfuse.maxWidth + 'px');
		_asianfuse.embed(id_num).height(_asianfuse.maxHeight + 'px');

		// Reset the width relative to the width of the embedded video, 
		// because we cannot count on it's parent element's calculated width to cause this to display as expected
		_asianfuse.restore(id_num).width((_asianfuse.maxWidth * 0.98) + 'px');
		_asianfuse.restore(id_num).show();
		if ( _asianfuse.flowplayers[id_num] != undefined ) {
			_asianfuse.flowplayers[id_num].load();
		}
	});
}

function setRestoreEvents() {
	jQuery('div.restore').click(function(e) {
		id_num = this.id.split('_', 2)[1]

		if( _asianfuse.is_maximized(id_num) ) {
			if ( _asianfuse.flowplayers[id_num] != undefined ) {
				_asianfuse.flowplayers[id_num].stop();
			}
			_asianfuse.restore(id_num).hide();
			_asianfuse.embed(id_num).width(_asianfuse.cache[id_num].embed_width + 'px');
			_asianfuse.embed(id_num).height(_asianfuse.cache[id_num].embed_height + 'px');

			_asianfuse.container(id_num).width(_asianfuse.cache[id_num].container_width + 'px');
			_asianfuse.container(id_num).height(_asianfuse.cache[id_num].container_height + 'px');
		}
	});
}

function initAsianFuseVideoPanels() {
	setDefaults();
	setMouseDownEvents();
	setRestoreEvents();
}


addOnloadHook( initAsianFuseVideoPanels );