$(document).ready(function() {
topnav();
userLinks();
spectraMenus();
fb_init();
hiddenForm();
hideShow();
autoSelect();
spectraParent();
help();
adminBtns();
adminNav();
logout();
login();
popups();
adminQuizForm();
qq_weights();
// re-do of legacy js
tableHovers();
tableHovers2();
tableHovers3();
procedureSteps();
vidLinks();
vidLinks2();
holdDown();
reports_form();
});
function reports_form(){
if (!document.getElementById('reports-search-form')) return;
var form = $('#reports-search-form');
$('input').click(function(){form.submit();});
}
function qq_add_weight(id,text,i){
var name = 'quiz-question-weight-'+id;
var list = $('#qq-weights-list');
var weight = i == undefined ? list.find('li').length : i;
id = 'qq-weight-'+id;
var item = $('
'+text+' ');
item.draggable({
connectToSortable : list
});
if (!$('#'+id).length) list.append(item);
}
function qq_weights(){
if (!document.getElementById('field-qq-weight') || !document.getElementById('qq-weights-list')) return;
var form = $('form.node-edit-form');
var trigger = $('#field-qq-weight span');
var start_text = trigger.text();
var list = $('#qq-weights-list');
list.sortable();
function make_list(){
var lis = $('.field-quiz-question');
var len = lis.length;
if (!list.find('li').length){
for(var i=0;i highest_num) highest_num = num;
});
}
var id = highest_num ? highest_num+1 : 1;
var question = '';
question += 'Question type ';
question += 'Please select... Text field Multiple choice, one answer Multiple choice, multiple answers ';
question += ' ';
question += 'Question text ';
question += 'Answers (one per line) ';
question += 'Correct answer ';
question += ' Remove this question ';
if (!qq_list){
qq_list = '';
$(qq_list).insertBefore(add_button);
qq_list = $('#qq-list');
}
qq_list.append(question);
tinyMCE.execCommand('mceAddControl',false,'quiz-question-questiontext-'+id);
tinyMCE.execCommand('mceAddControl',false,'quiz-question-answers-'+id);
tinyMCE.execCommand('mceAddControl',false,'quiz-question-correctanswers-'+id);
//alert('quiz-question-answers-'+id);
question = $('#qq-'+id);
question.fadeIn('fast');
question.find('.qq-field-type select').change(function(){
alter_quiz_form(question);
});
var iframe = question.find('iframe').contents();
question.find('textarea').focus(function(){
var text = iframe.find('p:first').text();
qq_add_weight(id,text);
});
}
function popups(){
$('a.new-window').each(function(){
this.onclick=function(){
window.open(this.href,'_blank');
return false;
}
});
}
function login(){
if (!document.getElementById('login-referrer')) return;
document.getElementById('login-referrer').value=document.referrer;
}
function topnav(){
if (!document.getElementById('topnav')) return;
$('#topnav > ul > li').hover(
function(){$(this).find('ul').fadeIn('fast');},
function(){$(this).find('ul').fadeOut('fast');}
);
}
function userLinks(){
if (!document.getElementById('admin-links')) return;
$('#admin-links').hover(
function(){$(this).find('ul').fadeIn('fast');},
function(){$(this).find('ul').fadeOut('fast');}
);
}
function adminNav(){
if (!document.getElementById('admin-menu')) return;
$('#admin-menu > li').hover(
function(){$(this).find('ul').fadeIn('fast');},
function(){$(this).find('ul').fadeOut('fast');}
);
}
function logout(){
if (!document.getElementById('logout')) return;
$('#user-links-logout').click(function(){
document.logout.submit();
return false;
});
}
function spectraMenus(){
if (!document.getElementById('spectra-compound-menu')) return;
var compounds=$('#spectra-compound-menu');
var types=$('#spectra-type-menu');
types.hover(null,function(){$(this).find('div').fadeOut('fast');});
$('body').click(function(event){
target=$(event.target);
if (target==compounds || target.parents('#spectra-compound-menu').length){
if (compounds.find('div').css('display')=='none'){
compounds.find('div').fadeIn('fast');
} else {
if (target.is('h5') || target.is('span')) compounds.find('div').fadeOut('fast');
}
} else {
if (compounds.find('div').css('display') != 'none') compounds.find('div').fadeOut('fast');
if (target==types || target.parents('#spectra-type-menu').length){
if (types.find('div').css('display')=='none'){
types.find('div').fadeIn('fast');
} else {
if (target != types.find('div') && !target.parents('#spectra-type-menu div').length) types.find('div').fadeOut('fast');
}
} else {
if (types.find('div').css('display') != 'none') types.find('div').fadeOut('fast');
}
}
});
}
function fb_init(){
if ($('.fancybox').length) {
$('.fancybox').fancybox();
$('.fancybox-close').click(function(){$.fancybox.close();return false;});
if ($('body').hasClass('disable-fancybox')){
$('#content-main a.fancybox').each(function(){
if (this.href.search('#')==-1) $(this).unbind();
});
}
}
}
function autoSelect() {
$('.auto-select').change(function(){
if ($(this).find('option:selected').val()) this.form.submit();
});
}
function adminBtns(){
if (!document.getElementById('admin-edit-btns')) return;
var addSpectra=$('#admin-edit-btns .hideShow');
var origText=addSpectra.html();
addSpectra.click(function(){
var newText=$(this).html()=='Cancel' ? origText : 'Cancel';
$(this).html(newText);
});
}
function hiddenForm() {
if (!document.getElementById('hidden-form') || !document.getElementById('form-trigger')) return;
var text;
$('#form-trigger').click(function(){
if (!$('#hidden-form input[name="allow-submit"]').length) {
text = $(this).html();
$(this).html('Cancel');
$('#hidden-form').addClass('show');
$('#hidden-form input').removeClass('readonly');
$('#hidden-form').append(' ');
} else {
$(this).html(text);
$('#hidden-form').removeClass('show');
$('#hidden-form input').addClass('readonly');
$('#hidden-form input[name="allow-submit"]').remove();
}
return false;
});
}
function hideShow() {
$('.hideShow').live('click',function(){
var slide=$(this).hasClass('slide') ? 1 : 0;
var target = this.href.split('#');
target = target[1];
if (!document.getElementById(target)) return;
target='#'+target;
if ($(target).css('display')=='none'){
if (slide){
$(target).slideDown('fast');
} else $(target).fadeIn('fast');
} else {
if (slide){
$(target).slideUp('fast');
} else $(target).fadeOut('fast');
}
return false;
});
}
function deleteSpectra(id) {
if (!document.getElementById('hidden-form') || !id) return;
var check = confirm('Are you sure you want to delete this Spectra type?');
if (check) {
$('#hidden-form').append(' ');
$('#hidden-form').submit();
}
}
function spectraParent() {
if (!document.getElementById('spectra-expansion') || !document.getElementById('expansion-parent')) return;
$('#spectra-expansion input').click(function(){
if ($(this).attr('checked')) {
$('#expansion-parent').slideDown();
} else {
$('#expansion-parent').slideUp();
}
});
}
function help(){
if (!$('.help-link').length) return;
$('body').click(function(e){
var target=$(e.target);
if (!target.hasClass('help-text') && !target.parents('.help-text').length || target.hasClass('help-close')) $('.help-text').hide('fast');
if (target.hasClass('help-link')){
var textBox=$(e.target).next();
if (textBox.css('display') != 'none'){
textBox.fadeOut('fast');
} else {
textBox.fadeIn('fast');
}
return false;
}
});
}
//////// BEGIN RE-DO LEGACY JS /////////
function tableHovers(){
// node: 89,90
$('.tableRollovers td').each(function(){
if ($(this).attr('id')) $(this).css('visibility','hidden');
});
$('.tableRollovers a').live('mouseover mouseout',function(event){
if (event.type=='mouseover') $(this).parent().next().css('visibility','visible');
if (event.type=='mouseout') $(this).parent().next().css('visibility','hidden');
});
$('.tableRollovers a').live('click',function(){return false;});
}
function tableHovers2(){
// node: 94
$('.tableOrgRollovers a').live('mouseover mouseout',function(event){
if (event.type=='mouseover'){
if ($(this).hasClass('first')){
$(this).parents('.tableOrgRollovers').find('.tdAnswer .first').fadeIn('fast');
} else {
$(this).parents('.tableOrgRollovers').find('.tdAnswer .last').fadeIn('fast');
}
} else $(this).parents('.tableOrgRollovers').find('.tdAnswer span').fadeOut('fast');
});
$('.tableOrgRollovers a').live('click',function(){return false;});
}
function tableHovers3(){
// node: 95,98
$('.tableOrgRollovers2 a,.tableOrgRollovers2 img').live('mouseover mouseout',function(event){
if (event.type=='mouseover'){
$(this).parents('.tableOrgRollovers2').find('.tdAnswer2 span').fadeIn('fast');
} else $(this).parents('.tableOrgRollovers2').find('.tdAnswer2 span').fadeOut('fast');
});
$('.tableOrgRollovers2 a').live('click',function(){return false;});
}
function procedureSteps(){
// node: 100
$('.js-steps .answer').css('display','none');
$('.js-steps .trigger').live('click',function(){
var id=this.href.split('#');
id='#'+id[1];
$(id).slideDown('fast');
return false;
});
}
function vidLinks(){
// node: 111,114,148
$('.link-video').click(function(){
var vid_url=this.href.replace('.mov', '.mp4'); // Convert MOV to MP4
var size=this.rel.split(',');
if (size[0].search('width') != -1){
var width=size[0].split('=');
var height=size[1].split('=');
width=jQuery.trim(width[1]);
height=jQuery.trim(height[1]);
} else {
var width=size[1].split('=');
var height=size[0].split('=');
width=jQuery.trim(width[1]);
height=jQuery.trim(height[1]);
}
vid='
';
if (!$(this).parent().find('.video-block').length){
$(this).parent().append(vid);
} else {
$(this).parent().find('.video-block').replaceWith(vid);
}
$(this).parent().find('.video-block').fadeIn('fast');
return false;
});
}
function vidLinks2(){
// node: 161
$('.link-video2').click(function(){
var vid_url=this.href.replace('.mov', '.mp4'); // Convert MOV to MP4
var data=this.rel.split(',');
for(var i=0;i ';
$(replace).replaceWith(vid);
return false;
});
}
function holdDown() {
$('.holdDown').mousedown(function(){
var slide=$(this).hasClass('slide') ? 1 : 0;
var target = this.href.split('#');
target = target[1];
if (!document.getElementById(target)) return;
target='#'+target;
if (slide){
$(target).slideDown('fast');
} else $(target).fadeIn('fast');
}).mouseup(function(){
var slide=$(this).hasClass('slide') ? 1 : 0;
var target = this.href.split('#');
target = target[1];
if (!document.getElementById(target)) return;
target='#'+target;
if (slide){
$(target).slideUp('fast');
} else $(target).fadeOut('fast');
});
$('.holdDown').click(function(){return false;});
}