2013-07-23 06:27:03 -05:00
|
|
|
|
// # Ghost jQuery Utils
|
|
|
|
|
|
|
|
|
|
/*global window, document, $ */
|
|
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2013-08-01 16:19:20 -05:00
|
|
|
|
// UTILS
|
2013-07-23 06:27:03 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allows to check contents of each element exactly
|
|
|
|
|
* @param obj
|
|
|
|
|
* @param index
|
|
|
|
|
* @param meta
|
|
|
|
|
* @param stack
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
$.expr[":"].containsExact = function (obj, index, meta, stack) {
|
|
|
|
|
return (obj.textContent || obj.innerText || $(obj).text() || "") === meta[3];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Center an element to the window vertically and centrally
|
|
|
|
|
* @returns {*}
|
|
|
|
|
*/
|
|
|
|
|
$.fn.center = function () {
|
|
|
|
|
this.css({
|
|
|
|
|
'position': 'fixed',
|
|
|
|
|
'left': '50%',
|
|
|
|
|
'top': '50%'
|
|
|
|
|
});
|
|
|
|
|
this.css({
|
|
|
|
|
'margin-left': -this.outerWidth() / 2 + 'px',
|
|
|
|
|
'margin-top': -this.outerHeight() / 2 + 'px'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-25 10:00:41 -05:00
|
|
|
|
$.fn.selectText = function () {
|
|
|
|
|
var elem = this[0],
|
|
|
|
|
range,
|
|
|
|
|
selection;
|
|
|
|
|
if (document.body.createTextRange) {
|
|
|
|
|
range = document.body.createTextRange();
|
|
|
|
|
range.moveToElementText(elem);
|
|
|
|
|
range.select();
|
|
|
|
|
} else if (window.getSelection) {
|
|
|
|
|
selection = window.getSelection();
|
|
|
|
|
range = document.createRange();
|
|
|
|
|
range.selectNodeContents(elem);
|
|
|
|
|
selection.removeAllRanges();
|
|
|
|
|
selection.addRange(range);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-26 06:32:26 -05:00
|
|
|
|
/**
|
|
|
|
|
* Set interactions for all menus and overlays
|
|
|
|
|
* This finds all visible 'hideClass' elements and hides them upon clicking away from the element itself.
|
|
|
|
|
* A callback can be defined to customise the results. By default it will hide the element.
|
|
|
|
|
* @param callback
|
|
|
|
|
*/
|
|
|
|
|
$.fn.hideAway = function (callback) {
|
|
|
|
|
var $self = $(this);
|
|
|
|
|
$("body").on('click', function (event) {
|
|
|
|
|
var $target = $(event.target),
|
|
|
|
|
hideClass = $self.selector;
|
|
|
|
|
if (!$target.parents().is(hideClass + ":visible") && !$target.is(hideClass + ":visible")) {
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback($("body").find(hideClass + ":visible"));
|
|
|
|
|
} else {
|
|
|
|
|
$("body").find(hideClass + ":visible").fadeOut();
|
|
|
|
|
|
|
|
|
|
// Toggle active classes on menu headers
|
|
|
|
|
$("[data-toggle].active").removeClass("active");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-01 16:19:20 -05:00
|
|
|
|
$('.overlay').hideAway(); // TODO: Move to a more sensible global file.
|
2013-07-26 06:32:26 -05:00
|
|
|
|
|
2013-07-23 06:27:03 -05:00
|
|
|
|
}());
|