|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/bluerae/clients/amag/staging/js/ |
Upload File : |
// page init
jQuery(function(){
initTouchNav();
initSameHeight();
});
// align blocks height
function initSameHeight() {
jQuery('div.box-holder').sameHeight({
elements: 'div.box',
useMinHeight: true,
multiLine: true
});
}
// handle dropdowns on mobile devices
function initTouchNav() {
jQuery('#nav').each(function(){
new TouchNav({
navBlock: this
});
});
}
/*
* jQuery SameHeight plugin
*/
;(function($){
$.fn.sameHeight = function(opt) {
var options = $.extend({
skipClass: 'same-height-ignore',
leftEdgeClass: 'same-height-left',
rightEdgeClass: 'same-height-right',
elements: '>*',
flexible: false,
multiLine: false,
useMinHeight: false,
biggestHeight: false
},opt);
return this.each(function(){
var holder = $(this), postResizeTimer, ignoreResize;
var elements = holder.find(options.elements).not('.' + options.skipClass);
if(!elements.length) return;
// resize handler
function doResize() {
elements.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', '');
if(options.multiLine) {
// resize elements row by row
resizeElementsByRows(elements, options);
} else {
// resize elements by holder
resizeElements(elements, holder, options);
}
}
doResize();
// handle flexible layout / font resize
var delayedResizeHandler = function() {
if(!ignoreResize) {
ignoreResize = true;
doResize();
clearTimeout(postResizeTimer);
postResizeTimer = setTimeout(function() {
doResize();
setTimeout(function(){
ignoreResize = false;
}, 10);
}, 100);
}
};
// handle flexible/responsive layout
if(options.flexible) {
$(window).bind('resize orientationchange fontresize', delayedResizeHandler);
}
// handle complete page load including images and fonts
$(window).bind('load', delayedResizeHandler);
});
};
// detect css min-height support
var supportMinHeight = typeof document.documentElement.style.maxHeight !== 'undefined';
// get elements by rows
function resizeElementsByRows(boxes, options) {
var currentRow = $(), maxHeight, maxCalcHeight = 0, firstOffset = boxes.eq(0).offset().top;
boxes.each(function(ind){
var curItem = $(this);
if(curItem.offset().top === firstOffset) {
currentRow = currentRow.add(this);
} else {
maxHeight = getMaxHeight(currentRow);
maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options));
currentRow = curItem;
firstOffset = curItem.offset().top;
}
});
if(currentRow.length) {
maxHeight = getMaxHeight(currentRow);
maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options));
}
if(options.biggestHeight) {
boxes.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', maxCalcHeight);
}
}
// calculate max element height
function getMaxHeight(boxes) {
var maxHeight = 0;
boxes.each(function(){
maxHeight = Math.max(maxHeight, $(this).outerHeight());
});
return maxHeight;
}
// resize helper function
function resizeElements(boxes, parent, options) {
var calcHeight;
var parentHeight = typeof parent === 'number' ? parent : parent.height();
boxes.removeClass(options.leftEdgeClass).removeClass(options.rightEdgeClass).each(function(i){
var element = $(this);
var depthDiffHeight = 0;
var isBorderBox = element.css('boxSizing') === 'border-box';
if(typeof parent !== 'number') {
element.parents().each(function(){
var tmpParent = $(this);
if(parent.is(this)) {
return false;
} else {
depthDiffHeight += tmpParent.outerHeight() - tmpParent.height();
}
});
}
calcHeight = parentHeight - depthDiffHeight;
calcHeight -= isBorderBox ? 0 : element.outerHeight() - element.height();
if(calcHeight > 0) {
element.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', calcHeight);
}
});
boxes.filter(':first').addClass(options.leftEdgeClass);
boxes.filter(':last').addClass(options.rightEdgeClass);
return calcHeight;
}
}(jQuery));
/*
* jQuery FontResize Event
*/
jQuery.onFontResize = (function($) {
$(function() {
var randomID = 'font-resize-frame-' + Math.floor(Math.random() * 1000);
var resizeFrame = $('<iframe>').attr('id', randomID).addClass('font-resize-helper');
// required styles
resizeFrame.css({
width: '100em',
height: '10px',
position: 'absolute',
borderWidth: 0,
top: '-9999px',
left: '-9999px'
}).appendTo('body');
// use native IE resize event if possible
if (window.attachEvent && !window.addEventListener) {
resizeFrame.bind('resize', function () {
$.onFontResize.trigger(resizeFrame[0].offsetWidth / 100);
});
}
// use script inside the iframe to detect resize for other browsers
else {
var doc = resizeFrame[0].contentWindow.document;
doc.open();
doc.write('<scri' + 'pt>window.onload = function(){var em = parent.jQuery("#' + randomID + '")[0];window.onresize = function(){if(parent.jQuery.onFontResize){parent.jQuery.onFontResize.trigger(em.offsetWidth / 100);}}};</scri' + 'pt>');
doc.close();
}
jQuery.onFontResize.initialSize = resizeFrame[0].offsetWidth / 100;
});
return {
// public method, so it can be called from within the iframe
trigger: function (em) {
$(window).trigger("fontresize", [em]);
}
};
}(jQuery));
// navigation accesibility module
function TouchNav(opt) {
this.options = {
hoverClass: 'hover',
menuItems: 'li',
menuOpener: 'a',
menuDrop: 'ul',
navBlock: null
};
for(var p in opt) {
if(opt.hasOwnProperty(p)) {
this.options[p] = opt[p];
}
}
this.init();
}
TouchNav.isActiveOn = function(elem) {
return elem && elem.touchNavActive;
};
TouchNav.prototype = {
init: function() {
if(typeof this.options.navBlock === 'string') {
this.menu = document.getElementById(this.options.navBlock);
} else if(typeof this.options.navBlock === 'object') {
this.menu = this.options.navBlock;
}
if(this.menu) {
this.addEvents();
}
},
addEvents: function() {
// attach event handlers
var self = this;
this.menuItems = lib.queryElementsBySelector(this.options.menuItems, this.menu);
for(var i = 0; i < this.menuItems.length; i++) {
(function(i){
var item = self.menuItems[i],
currentDrop = lib.queryElementsBySelector(self.options.menuDrop, item)[0],
currentOpener = lib.queryElementsBySelector(self.options.menuOpener, item)[0];
// only for touch input devices
if( (self.isTouchDevice || navigator.msPointerEnabled) && currentDrop && currentOpener) {
lib.event.add(currentOpener, 'click', lib.bind(self.clickHandler, self));
lib.event.add(currentOpener, navigator.msPointerEnabled ? 'MSPointerDown' : 'touchstart', function(e){
if(navigator.msPointerEnabled && e.pointerType !== e.MSPOINTER_TYPE_TOUCH) {
self.preventCurrentClick = false;
return;
}
self.touchFlag = true;
self.currentItem = item;
self.currentLink = currentOpener;
self.pressHandler.apply(self, arguments);
});
}
// for desktop computers and touch devices
jQuery(item).bind('mouseenter', function(){
if(!self.touchFlag) {
self.currentItem = item;
self.mouseoverHandler();
}
});
jQuery(item).bind('mouseleave', function(){
if(!self.touchFlag) {
self.currentItem = item;
self.mouseoutHandler();
}
});
item.touchNavActive = true;
})(i);
}
// hide dropdowns when clicking outside navigation
if(this.isTouchDevice || navigator.msPointerEnabled) {
lib.event.add(document, navigator.msPointerEnabled ? 'MSPointerDown' : 'touchstart', lib.bind(this.clickOutsideHandler, this));
}
},
mouseoverHandler: function() {
lib.addClass(this.currentItem, this.options.hoverClass);
jQuery(this.currentItem).trigger('itemhover');
},
mouseoutHandler: function() {
lib.removeClass(this.currentItem, this.options.hoverClass);
jQuery(this.currentItem).trigger('itemleave');
},
hideActiveDropdown: function() {
for(var i = 0; i < this.menuItems.length; i++) {
if(lib.hasClass(this.menuItems[i], this.options.hoverClass)) {
lib.removeClass(this.menuItems[i], this.options.hoverClass);
jQuery(this.menuItems[i]).trigger('itemleave');
}
}
this.activeParent = null;
},
pressHandler: function(e) {
// hide previous drop (if active)
if(this.currentItem !== this.activeParent) {
if(this.activeParent && this.currentItem.parentNode === this.activeParent.parentNode) {
lib.removeClass(this.activeParent, this.options.hoverClass);
} else if(!this.isParent(this.activeParent, this.currentLink)) {
this.hideActiveDropdown();
}
}
// handle current drop
this.activeParent = this.currentItem;
if(lib.hasClass(this.currentItem, this.options.hoverClass)) {
this.preventCurrentClick = false;
} else {
e.preventDefault();
this.preventCurrentClick = true;
lib.addClass(this.currentItem, this.options.hoverClass);
jQuery(this.currentItem).trigger('itemhover');
}
},
clickHandler: function(e) {
// prevent first click on link
if(this.preventCurrentClick || typeof this.preventCurrentClick === 'undefined') {
e.preventDefault();
}
},
clickOutsideHandler: function(event) {
if(navigator.msPointerEnabled && event.pointerType !== event.MSPOINTER_TYPE_TOUCH) return;
var e = event.changedTouches ? event.changedTouches[0] : event;
if(this.activeParent && !this.isParent(this.menu, e.target)) {
this.hideActiveDropdown();
this.touchFlag = false;
}
},
isParent: function(parent, child) {
while(child.parentNode) {
if(child.parentNode == parent) {
return true;
}
child = child.parentNode;
}
return false;
},
isTouchDevice: (function() {
try {
return (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) || navigator.userAgent.indexOf('IEMobile') != -1;
} catch (e) {
return false;
}
}())
};
/*
* Utility module
*/
lib = {
hasClass: function(el,cls) {
return el && el.className ? el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')) : false;
},
addClass: function(el,cls) {
if (el && !this.hasClass(el,cls)) el.className += " "+cls;
},
removeClass: function(el,cls) {
if (el && this.hasClass(el,cls)) {el.className=el.className.replace(new RegExp('(\\s|^)'+cls+'(\\s|$)'),' ');}
},
extend: function(obj) {
for(var i = 1; i < arguments.length; i++) {
for(var p in arguments[i]) {
if(arguments[i].hasOwnProperty(p)) {
obj[p] = arguments[i][p];
}
}
}
return obj;
},
each: function(obj, callback) {
var property, len;
if(typeof obj.length === 'number') {
for(property = 0, len = obj.length; property < len; property++) {
if(callback.call(obj[property], property, obj[property]) === false) {
break;
}
}
} else {
for(property in obj) {
if(obj.hasOwnProperty(property)) {
if(callback.call(obj[property], property, obj[property]) === false) {
break;
}
}
}
}
},
event: (function() {
var fixEvent = function(e) {
e = e || window.event;
if(e.isFixed) return e; else e.isFixed = true;
if(!e.target) e.target = e.srcElement;
e.preventDefault = e.preventDefault || function() {this.returnValue = false;};
e.stopPropagation = e.stopPropagation || function() {this.cancelBubble = true;};
return e;
};
return {
add: function(elem, event, handler) {
if(!elem.events) {
elem.events = {};
elem.handle = function(e) {
var ret, handlers = elem.events[e.type];
e = fixEvent(e);
for(var i = 0, len = handlers.length; i < len; i++) {
if(handlers[i]) {
ret = handlers[i].call(elem, e);
if(ret === false) {
e.preventDefault();
e.stopPropagation();
}
}
}
};
}
if(!elem.events[event]) {
elem.events[event] = [];
if(elem.addEventListener) elem.addEventListener(event, elem.handle, false);
else if(elem.attachEvent) elem.attachEvent('on'+event, elem.handle);
}
elem.events[event].push(handler);
},
remove: function(elem, event, handler) {
var handlers = elem.events[event];
for(var i = handlers.length - 1; i >= 0; i--) {
if(handlers[i] === handler) {
handlers.splice(i,1);
}
}
if(!handlers.length) {
delete elem.events[event];
if(elem.removeEventListener) elem.removeEventListener(event, elem.handle, false);
else if(elem.detachEvent) elem.detachEvent('on'+event, elem.handle);
}
}
};
}()),
queryElementsBySelector: function(selector, scope) {
scope = scope || document;
if(!selector) return [];
if(selector === '>*') return scope.children;
if(typeof document.querySelectorAll === 'function') {
return scope.querySelectorAll(selector);
}
var selectors = selector.split(',');
var resultList = [];
for(var s = 0; s < selectors.length; s++) {
var currentContext = [scope || document];
var tokens = selectors[s].replace(/^\s+/,'').replace(/\s+$/,'').split(' ');
for (var i = 0; i < tokens.length; i++) {
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');
if (token.indexOf('#') > -1) {
var bits = token.split('#'), tagName = bits[0], id = bits[1];
var element = document.getElementById(id);
if (element && tagName && element.nodeName.toLowerCase() != tagName) {
return [];
}
currentContext = element ? [element] : [];
continue;
}
if (token.indexOf('.') > -1) {
var bits = token.split('.'), tagName = bits[0] || '*', className = bits[1], found = [], foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = currentContext[h].getElementsByTagName('*');
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = [];
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (found[k].className && found[k].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))) {
currentContext[currentContextIndex++] = found[k];
}
}
continue;
}
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
var tagName = RegExp.$1 || '*', attrName = RegExp.$2, attrOperator = RegExp.$3, attrValue = RegExp.$4;
if(attrName.toLowerCase() == 'for' && this.browser.msie && this.browser.version < 8) {
attrName = 'htmlFor';
}
var found = [], foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = currentContext[h].getElementsByTagName('*');
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; elements[j]; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = [];
var currentContextIndex = 0, checkFunction;
switch (attrOperator) {
case '=': checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue) }; break;
case '~': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('(\\s|^)'+attrValue+'(\\s|$)'))) }; break;
case '|': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))) }; break;
case '^': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0) }; break;
case '$': checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length) }; break;
case '*': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1) }; break;
default : checkFunction = function(e) { return e.getAttribute(attrName) };
}
currentContext = [];
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (checkFunction(found[k])) {
currentContext[currentContextIndex++] = found[k];
}
}
continue;
}
tagName = token;
var found = [], foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements = currentContext[h].getElementsByTagName(tagName);
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = found;
}
resultList = [].concat(resultList,currentContext);
}
return resultList;
},
trim: function (str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
},
bind: function(f, scope, forceArgs){
return function() {return f.apply(scope, typeof forceArgs !== 'undefined' ? [forceArgs] : arguments);};
}
};