<commit_before>/**
 * @package     hubzero-cms
 * @file        components/com_resources/resources.js
 * @copyright   Copyright 2005-2011 Purdue University. All rights reserved.
 * @license     http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

//-----------------------------------------------------------
//  Ensure we have our namespace
//-----------------------------------------------------------
if (!HUB) {
	var HUB = {};
}

//----------------------------------------------------------
// Resource Ranking pop-ups
//----------------------------------------------------------

HUB.Resources = {

	initialize: function() {
		if (typeof(SqueezeBoxHub) != "undefined") {
			if (!SqueezeBoxHub) {
				SqueezeBoxHub.initialize({ size: {x: 750, y: 500} });
			}
			
			// Modal boxes for presentations
			$$('a.play').each(function(el) {
				if (el.href.indexOf('?') == -1) {
					el.href = el.href + '?no_html=1';
				} else {
					el.href = el.href + '&no_html=1';
				}
				el.addEvent('click', function(e) {
					new Event(e).stop();

					w = 750;
					h = 500;
					if (this.className) {
						var sizeString = this.className.split(' ').pop();
						if (sizeString && sizeString != 'play') {
							var sizeTokens = sizeString.split('x');
							w = parseInt(sizeTokens[0]);
							h = parseInt(sizeTokens[1]);
						}
					}

					SqueezeBoxHub.fromElement(el,{handler: 'url', size: {x: w, y: h}, ajaxOptions: {method: 'get',evalScripts:true}});
				});
			});
			
			var win = new Element('a', {
				id: 'sbox-newwindow',
				href: '#',
				title: 'Open in a new window',
				events: {
					'click': function(event) {
						OpenWindow = window.open('', "newwin", "height=500,width=700,toolbar=no,scrollbars=yes,menubar=no,resizable=yes,location=no,scrollbars=no,directories=no,status=no");
						OpenWindow.document.write('<html>');
						OpenWindow.document.write('<title>Presentation</title>');
						OpenWindow.document.write('<body style="margin:0;padding:0;border:0;">');
						OpenWindow.document.write( $('sbox-window').innerHTML );
						OpenWindow.document.write('</body>');
						OpenWindow.document.write('</html>');
						OpenWindow.document.close();
						self.name = 'main';
						SqueezeBoxHub.close();
					}
				}
			});
			var res = new Element('div', {
				id: 'sbox-resizehandle',
				alt: 'Resize'
			})
			$('sbox-window').adopt(win, res);
			
			// Init the resizing capabilities
			$('sbox-window').makeResizable({
				handle:$('sbox-resizehandle'),
				onComplete: function(el) {
					var size = el.getCoordinates();
					SqueezeBoxHub.resize({x:size.width,y:size.height},false)
				}
			});
		}
		
		// Fixed resource tooltips
		var rTTips = new MooTips($$('.fixedResourceTip'), {
			showDelay: 500,
			maxTitleChars: 100,
			className: 'resource',
			fixed: true,
			offsets: {'x':20,'y':5}
		});
		
		// Ranking info pop-up
		var metadata = $$('.metadata');
		if (metadata) {
			/*
			metadata.each(function(meta) {
				meta.addEvent('mouseover', function(e) {
					var el = this.getElement('.rankinfo');
					el.addClass('active');
				});
				meta.addEvent('mouseout', function(e) {
					var el = this.getElement('.rankinfo');
					el.removeClass('active');
				});
			});
			*/
			metadata.each(function(meta) {
				$$('.rankinfo').addEvent('mouseover', function(e) {
						this.addClass('active');
					});
				$$('.rankinfo').addEvent('mouseout', function(e) {
						this.removeClass('active');
				});
			});
		}
		
		// Audience info pop-up
		var explainscale = $$('.explainscale');
		if (explainscale) {
			var ex = metadata.getElement('.explainscale');		
			$$('.usagescale').each(function(item) {
					
					item.addEvent('mouseover', function() {					
						ex.addClass('active');
					});
			});
			$$('.usagescale').each(function(item) {
				
					item.addEvent('mouseout', function() {					
						ex.removeClass('active');
					});
			});
		}
		
		// Primary-document info pop-up
		var primarydoc = $('primary-document');
		var primarydocpop = $('primary-document_pop');
		if (primarydoc && primarydocpop) {
			primarydoc.addEvent('mouseover', function(e) {
				//new Event(e).stop();
				primarydocpop.style.display = "block";
			});
			
			primarydoc.addEvent('mouseout', function(e) {
				primarydocpop.style.display = "none";
			});
		} 
		
		
		//Hubpresenter
		$$(".hubpresenter, .video").each(function(el) {
			if (el.href.indexOf('?') == -1) {
				el.href = el.href + '?tmpl=component';
			} else {
				el.href = el.href + '&tmpl=component';
			}
		});
		
		//HUBpresenter open window
		$$(".hubpresenter").addEvent("click", function(e) {
			mobile = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
			if(!mobile) {
				new Event(e).stop();
		 		HUBpresenter_window = window.open(this.href,'name','height=650,width=1100');
			}
		});
		
		$$(".video").addEvent("click", function(e) {
			mobile = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
			if(!mobile) {
				new Event(e).stop();
				var w = 0,<commit_msg>Fixed cases of trying to access non-existent attribute<commit_after>/**
 * @package     hubzero-cms
 * @file        components/com_resources/resources.js
 * @copyright   Copyright 2005-2011 Purdue University. All rights reserved.
 * @license     http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

//-----------------------------------------------------------
//  Ensure we have our namespace
//-----------------------------------------------------------
if (!HUB) {
	var HUB = {};
}

//----------------------------------------------------------
// Resource Ranking pop-ups
//----------------------------------------------------------

HUB.Resources = {

	initialize: function() {
		if (typeof(SqueezeBoxHub) != "undefined") {
			if (!SqueezeBoxHub) {
				SqueezeBoxHub.initialize({ size: {x: 750, y: 500} });
			}
			
			// Modal boxes for presentations
			$$('a.play').each(function(el) {
				if (el.href.indexOf('?') == -1) {
					el.href = el.href + '?no_html=1';
				} else {
					el.href = el.href + '&no_html=1';
				}
				el.addEvent('click', function(e) {
					new Event(e).stop();

					w = 750;
					h = 500;
					if (this.className) {
						var sizeString = this.className.split(' ').pop();
						if (sizeString && sizeString != 'play') {
							var sizeTokens = sizeString.split('x');
							w = parseInt(sizeTokens[0]);
							h = parseInt(sizeTokens[1]);
						}
					}

					SqueezeBoxHub.fromElement(el,{handler: 'url', size: {x: w, y: h}, ajaxOptions: {method: 'get',evalScripts:true}});
				});
			});
			
			var win = new Element('a', {
				id: 'sbox-newwindow',
				href: '#',
				title: 'Open in a new window',
				events: {
					'click': function(event) {
						OpenWindow = window.open('', "newwin", "height=500,width=700,toolbar=no,scrollbars=yes,menubar=no,resizable=yes,location=no,scrollbars=no,directories=no,status=no");
						OpenWindow.document.write('<html>');
						OpenWindow.document.write('<title>Presentation</title>');
						OpenWindow.document.write('<body style="margin:0;padding:0;border:0;">');
						OpenWindow.document.write( $('sbox-window').innerHTML );
						OpenWindow.document.write('</body>');
						OpenWindow.document.write('</html>');
						OpenWindow.document.close();
						self.name = 'main';
						SqueezeBoxHub.close();
					}
				}
			});
			var res = new Element('div', {
				id: 'sbox-resizehandle',
				alt: 'Resize'
			})
			$('sbox-window').adopt(win, res);
			
			// Init the resizing capabilities
			$('sbox-window').makeResizable({
				handle:$('sbox-resizehandle'),
				onComplete: function(el) {
					var size = el.getCoordinates();
					SqueezeBoxHub.resize({x:size.width,y:size.height},false)
				}
			});
		}
		
		// Fixed resource tooltips
		var rTTips = new MooTips($$('.fixedResourceTip'), {
			showDelay: 500,
			maxTitleChars: 100,
			className: 'resource',
			fixed: true,
			offsets: {'x':20,'y':5}
		});
		
		// Ranking info pop-up
		var metadata = $$('.metadata');
		if (metadata) {
			/*
			metadata.each(function(meta) {
				meta.addEvent('mouseover', function(e) {
					var el = this.getElement('.rankinfo');
					el.addClass('active');
				});
				meta.addEvent('mouseout', function(e) {
					var el = this.getElement('.rankinfo');
					el.removeClass('active');
				});
			});
			*/
			metadata.each(function(meta) {
				$$('.rankinfo').addEvent('mouseover', function(e) {
						this.addClass('active');
					});
				$$('.rankinfo').addEvent('mouseout', function(e) {
						this.removeClass('active');
				});
			});
		}
		
		// Audience info pop-up
		var explainscale = $$('.explainscale');
		if (explainscale) {
			var ex = metadata.getElement('.explainscale');		
			$$('.usagescale').each(function(item) {
					
					item.addEvent('mouseover', function() {					
						ex.addClass('active');
					});
			});
			$$('.usagescale').each(function(item) {
				
					item.addEvent('mouseout', function() {					
						ex.removeClass('active');
					});
			});
		}
		
		// Primary-document info pop-up
		var primarydoc = $('primary-document');
		var primarydocpop = $('primary-document_pop');
		if (primarydoc && primarydocpop) {
			primarydoc.addEvent('mouseover', function(e) {
				//new Event(e).stop();
				primarydocpop.style.display = "block";
			});
			
			primarydoc.addEvent('mouseout', function(e) {
				primarydocpop.style.display = "none";
			});
		} 
		
		
		//Hubpresenter
		$$(".hubpresenter, .video").each(function(el) {
			if (el.href && el.href.indexOf('?') == -1) {
				el.href = el.href + '?tmpl=component';
			} else {
				el.href = el.href + '&tmpl=component';
			}
		});
		
		//HUBpresenter open window
		$$(".hubpresenter").addEvent("click", function(e) {
			mobile = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
			if(!mobile) {
				new Event(e).stop();
		 		HUBpresenter_window = window.open(this.href,'name','height=650,width=1100');
			}
		});
		
		$$(".video").addEvent("click", function(e) {
			mobile = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
			if(!mobile) {
				new Event(e).stop();
				var w = 0,
{'fraction_non_alphanumeric': 0.23180914512922465, 'fraction_numerical': 0.010934393638170975, 'mean_word_length': 2.4813148788927335, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350520', 'n_tokens_mistral': 4241, 'n_tokens_neox': 3269, 'n_words': 545}