Ghost/ghost/admin/assets/lib/jquery-utils.js
Matthew Harrison-Jones 9d6a4f52e1 Improved mobile interactions
This is simply a commit which improves the mobile interactions. This does not fix UI problems on mobiles.

New interactions;

Menu
* Swipe right on header to show sidebar
* Swipe left on sidebar to hide

Content
* Tap / Swipe left on item to show preview
* Swipe right to show content list

Settings
* Tap / Swipe left on link to show settings
* Swipe right on settings to show links
2013-08-16 12:44:11 +01:00

100 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// # Ghost jQuery Utils
/*global window, document, $ */
(function () {
"use strict";
// ## UTILS
/**
* 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'
});
$(window).trigger('centered');
return this;
};
$.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);
}
};
/**
* 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;
};
// ## GLOBALS
$('.overlay').hideAway();
/**
* Adds appropriate inflection for pluralizing the singular form of a word when appropriate.
* This is an overly simplistic implementation that does not handle irregular plurals.
* @param {Number} count
* @param {String} singularWord
* @returns {String}
*/
$.pluralize = function inflect(count, singularWord) {
var base = [count, ' ', singularWord];
return (count === 1) ? base.join('') : base.concat('s').join('');
};
}());