Created
December 12, 2014 11:39
-
-
Save Langmans/aa406e456f914f29af56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.isCSS = function (properties) { | |
var property; | |
for (property in properties) { | |
if (properties.hasOwnProperty(property)) { | |
var required_value = properties[property], | |
actual_value = this.css(property); | |
//console.log('$.isCSS', property, '=', required_value, required_value != actual_value ? '!=' : '==', actual_value, this[0]); | |
if (required_value != actual_value) { | |
return false; | |
} | |
} | |
} | |
return true; | |
}; | |
$.fn.getParentsWithCSS = function (properties) { | |
var error; | |
if (this.length != 1) { | |
error = 'Object length (' + this.length + ') is not 1.'; | |
throw error; | |
} | |
return this.parents().filter(function () { | |
return $(this).isCSS(properties); | |
}); | |
}; | |
$.fn.getParentWithCSS = function (properties) { | |
var error, $parent = this; | |
if (this.length != 1) { | |
error = 'Object length (' + this.length + ') is not 1.'; | |
throw error; | |
} | |
//try { | |
while (($parent = $parent.parent()) && $parent[0] != document && $parent.length) { | |
if ($parent.isCSS(properties)) { | |
return $parent; | |
} | |
} | |
//} catch (e) { | |
// console.log('getParentWithCSS', e, $parent); | |
//} | |
// not found! | |
return $([]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment