MediaWiki: Common.js

From ShareRice Wiki (AFN)
Jump to: navigation, search
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
// Provide easy access to default values, neatly hidden in a "namespace" that SHOULDN'T conflict with any other environmental variables.
 
 
var _asianfuse = {
 
var _asianfuse = {
video_panels: {
 
add: function(key, val) {
 
if ( this.has_key(key) || val == undefined ) { return; }
 
this[key] = val;
 
},
 
has_key: function(key) { return(this[key] != undefined); }
 
},
 
 
 
maxWidth: 425,
 
maxWidth: 425,
minWidth: 150,
 
 
 
maxHeight: 350,
 
maxHeight: 350,
minHeight: 124
+
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 do_resize (rand, dir) {
+
function setDefaults() {
key = '#af-video-restore_' + rand
+
jQuery('.afv').each(function(i, el) {
 
+
id_num = this.id.split('_', 2)[1]
if ( dir == 'max') {
 
_asianfuse.video_panels.add(key, jQuery(key).parent().height());
 
 
 
jQuery('.af-video-embed_' + rand).width(_asianfuse.maxWidth + 'px');
 
jQuery('.af-video-embed_' + rand).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
 
jQuery('#af-video-restore_' + rand).width(_asianfuse.maxWidth * 0.98 + 'px');
 
jQuery('#af-video-restore_' + rand).show();
 
 
 
} else if ( dir == 'min' ) {
 
jQuery('#af-video-restore_' + rand).hide();
 
jQuery('.af-video-embed_' + rand).width(_asianfuse.minWidth + 'px')
 
jQuery('.af-video-embed_' + rand).height(_asianfuse.minHeight + 'px');
 
 
 
jQuery(key).parent().width('150px')
 
  
if( _asianfuse.video_panels.has_key(key) ) {
+
_asianfuse.cache[id_num] = {
jQuery(key).parent().height(_asianfuse.video_panels[key] + 'px');
+
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()
 
}
 
}
}
+
});
 
}
 
}
  
addOnloadHook( do_resize );
+
function setMouseDownEvents() {
 
+
jQuery('.afv').mousedown(function(e) {
video_panel = function(id, cfg) {
+
id_num = this.id.split('_', 2)[1];
this.config      = cfg
 
this.container    = jQuery('#af-video-embed-container_' + id)
 
this.embedded    = jQuery('#af-video-embed_' + id)
 
this.restorer    = jQuery('#af-media-restore_' + id)
 
this.widths      = { container: this.container.width(), embedded: this.embedded.width() }
 
this.heights      = { container: this.container.height(), embedded: this.embedded.height() }
 
  
this.maximize    = function() {
+
if( e.which != 1 || _asianfuse.is_maximized(id_num) ) { return; }
if( this.is_maximized() ) { return; }
+
_asianfuse.container(id_num).width(_asianfuse.maxWidth + 'px');
this.container.width(this.config.maxWidth + 40 + 'px');
+
_asianfuse.container(id_num).height((_asianfuse.maxHeight * _asianfuse.cache[id_num].container_ratio) + 'px');
this.container.height(this.config.maxHeight + 40 + 'px');
 
  
this.embedded.width(this.config.maxWidth + 'px');
+
_asianfuse.embed(id_num).width(_asianfuse.maxWidth + 'px');
this.embedded.height(this.config.maxHeight + 'px');
+
_asianfuse.embed(id_num).height(_asianfuse.maxHeight + 'px');
  
 
// Reset the width relative to the width of the embedded video,  
 
// 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
 
// because we cannot count on it's parent element's calculated width to cause this to display as expected
this.restorer.width((this.config.maxWidth * 0.98) + 'px');
+
_asianfuse.restore(id_num).width((_asianfuse.maxWidth * 0.98) + 'px');
this.restorer.show();
+
_asianfuse.restore(id_num).show();
}
+
if ( _asianfuse.flowplayers[id_num] != undefined ) {
this.minimize    = function() {
+
_asianfuse.flowplayers[id_num].load();
this.restorer.hide();
+
}
this.embedded.width(this.widths.embedded + 'px')
+
});
this.embedded.height(this.heights.embedded + 'px');
+
}
 +
 
 +
function setRestoreEvents() {
 +
jQuery('div.restore').click(function(e) {
 +
id_num = this.id.split('_', 2)[1]
  
this.container.width(this.widths.container)
+
if( _asianfuse.is_maximized(id_num) ) {
this.container.height(this.heights.container)
+
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');
  
this.is_maximized = function() {
+
_asianfuse.container(id_num).width(_asianfuse.cache[id_num].container_width + 'px');
return parseInt(this.container.height()) == parseInt(this.config.maxHeight) &&
+
_asianfuse.container(id_num).height(_asianfuse.cache[id_num].container_height + 'px');
      parseInt(this.container.width()) == parseInt(this.config.maxWidth);
+
}
}
+
});
 
}
 
}
  
var _asianfuse2 = {
+
function initAsianFuseVideoPanels() {
maxWidth: 425,
+
setDefaults();
maxHeight: 350,
+
setMouseDownEvents();
video_panels: [],
+
setRestoreEvents();
add: function(id, config) {
 
this.video_panels[id] = new video_panel(id, config);
 
}
 
 
}
 
}
 +
 +
 +
addOnloadHook( initAsianFuseVideoPanels );

Latest revision as of 23: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 );