Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
648 changes: 324 additions & 324 deletions dom/animate/animate.js

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions dom/closest/closest.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/**
* @add jQuery.fn
*/
steal('jquery', function($) {
/**
* @function closest
* @parent dom
* @plugin jquery/dom/closest
* Overwrites closest to allow open > selectors. This allows controller
* actions such as:
*
* ">li click" : function( el, ev ) { ... }
*/
var oldClosest = jQuery.fn.closest;
jQuery.fn.closest = function(selectors, context){
var rooted = {}, res, result, thing, i, j, selector, rootedIsEmpty = true, selector, selectorsArr = selectors;
if(typeof selectors == "string") selectorsArr = [selectors];

$.each(selectorsArr, function(i, selector){
if(selector.indexOf(">") == 0 ){
if(selector.indexOf(" ") != -1){
throw " closest does not work with > followed by spaces!"
}
rooted[( selectorsArr[i] = selector.substr(1) )] = selector;
if(typeof selectors == "string") selectors = selector.substr(1);
rootedIsEmpty = false;
}
})

res = oldClosest.call(this, selectors, context);

if(rootedIsEmpty) return res;
i =0;
while(i < res.length){
result = res[i], selector = result.selector;
if (rooted[selector] !== undefined) {
result.selector = rooted[selector];
rooted[selector] = false;
if(typeof result.selector !== "string" || result.elem.parentNode !== context ){
res.splice(i,1);
continue;
}
}
i++;
}
return res;
}

return $;
/**
* @add jQuery.fn
*/
steal('jquery', function($) {
/**
* @function closest
* @parent dom
* @plugin jquery/dom/closest
* Overwrites closest to allow open > selectors. This allows controller
* actions such as:
*
* ">li click" : function( el, ev ) { ... }
*/
var oldClosest = $.fn.closest;
$.fn.closest = function(selectors, context){
var rooted = {}, res, result, thing, i, j, selector, rootedIsEmpty = true, selector, selectorsArr = selectors;
if(typeof selectors == "string") selectorsArr = [selectors];
$.each(selectorsArr, function(i, selector){
if(selector.indexOf(">") == 0 ){
if(selector.indexOf(" ") != -1){
throw " closest does not work with > followed by spaces!"
}
rooted[( selectorsArr[i] = selector.substr(1) )] = selector;
if(typeof selectors == "string") selectors = selector.substr(1);
rootedIsEmpty = false;
}
})
res = oldClosest.call(this, selectors, context);
if(rootedIsEmpty) return res;
i =0;
while(i < res.length){
result = res[i], selector = result.selector;
if (rooted[selector] !== undefined) {
result.selector = rooted[selector];
rooted[selector] = false;
if(typeof result.selector !== "string" || result.elem.parentNode !== context ){
res.splice(i,1);
continue;
}
}
i++;
}
return res;
}
return $;
})
148 changes: 74 additions & 74 deletions dom/compare/compare.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
steal('jquery', function($) {

/**
* @function jQuery.fn.compare
* @parent jQuery.compare
*
* Compare two elements and return a bitmask as a number representing the following conditions:
*
* - `000000` -> __0__: Elements are identical
* - `000001` -> __1__: The nodes are in different documents (or one is outside of a document)
* - `000010` -> __2__: #bar precedes #foo
* - `000100` -> __4__: #foo precedes #bar
* - `001000` -> __8__: #bar contains #foo
* - `010000` -> __16__: #foo contains #bar
*
* You can check for any of these conditions using a bitwise AND:
*
* if( $('#foo').compare($('#bar')) & 2 ) {
* console.log("#bar precedes #foo")
* }
*
* @param {HTMLElement|jQuery} element an element or jQuery collection to compare against.
* @return {Number} A number representing a bitmask deatiling how the elements are positioned from each other.
*/

// See http://ejohn.org/blog/comparing-document-position/
jQuery.fn.compare = function(element){ //usually
try{
// Firefox 3 throws an error with XUL - we can't use compare then
element = element.jquery ? element[0] : element;
}catch(e){
return null;
}

// make sure we aren't coming from XUL element
if (window.HTMLElement) {
var s = HTMLElement.prototype.toString.call(element)
if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]' || s === '[object Window]') {
return null;
}
}

if(this[0].compareDocumentPosition){
// For browsers that support it, use compareDocumentPosition
// https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
return this[0].compareDocumentPosition(element);
}

// this[0] contains element
if(this[0] == document && element != document) return 8;

var number =
// this[0] contains element
(this[0] !== element && this[0].contains(element) && 16) +
// element contains this[0]
(this[0] != element && element.contains(this[0]) && 8),
docEl = document.documentElement;

// Use the sourceIndex
if(this[0].sourceIndex){
// this[0] precedes element
number += (this[0].sourceIndex < element.sourceIndex && 4)
// element precedes foo[0]
number += (this[0].sourceIndex > element.sourceIndex && 2)
// The nodes are in different documents
number += (this[0].ownerDocument !== element.ownerDocument ||
(this[0] != docEl && this[0].sourceIndex <= 0 ) ||
(element != docEl && element.sourceIndex <= 0 )) && 1
}

return number;
}

return $;
steal('jquery', function($) {
/**
* @function jQuery.fn.compare
* @parent jQuery.compare
*
* Compare two elements and return a bitmask as a number representing the following conditions:
*
* - `000000` -> __0__: Elements are identical
* - `000001` -> __1__: The nodes are in different documents (or one is outside of a document)
* - `000010` -> __2__: #bar precedes #foo
* - `000100` -> __4__: #foo precedes #bar
* - `001000` -> __8__: #bar contains #foo
* - `010000` -> __16__: #foo contains #bar
*
* You can check for any of these conditions using a bitwise AND:
*
* if( $('#foo').compare($('#bar')) & 2 ) {
* console.log("#bar precedes #foo")
* }
*
* @param {HTMLElement|jQuery} element an element or jQuery collection to compare against.
* @return {Number} A number representing a bitmask deatiling how the elements are positioned from each other.
*/
// See http://ejohn.org/blog/comparing-document-position/
$.fn.compare = function(element){ //usually
try{
// Firefox 3 throws an error with XUL - we can't use compare then
element = element.jquery ? element[0] : element;
}catch(e){
return null;
}
// make sure we aren't coming from XUL element
if (window.HTMLElement) {
var s = HTMLElement.prototype.toString.call(element)
if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]' || s === '[object Window]') {
return null;
}
}
if(this[0].compareDocumentPosition){
// For browsers that support it, use compareDocumentPosition
// https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
return this[0].compareDocumentPosition(element);
}
// this[0] contains element
if(this[0] == document && element != document) return 8;
var number =
// this[0] contains element
(this[0] !== element && this[0].contains(element) && 16) +
// element contains this[0]
(this[0] != element && element.contains(this[0]) && 8),
docEl = document.documentElement;
// Use the sourceIndex
if(this[0].sourceIndex){
// this[0] precedes element
number += (this[0].sourceIndex < element.sourceIndex && 4)
// element precedes foo[0]
number += (this[0].sourceIndex > element.sourceIndex && 2)
// The nodes are in different documents
number += (this[0].ownerDocument !== element.ownerDocument ||
(this[0] != docEl && this[0].sourceIndex <= 0 ) ||
(element != docEl && element.sourceIndex <= 0 )) && 1
}
return number;
}
return $;
});
Loading