-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add experimental region and insertRule
- Loading branch information
kangax
authored and
kangax
committed
Jul 19, 2008
1 parent
d7f66f0
commit d5a96c9
Showing
3 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Element.Region = Class.create({ | ||
initialize: function(element) { | ||
this.element = $(element); | ||
var offset = this.element.cumulativeOffset(); | ||
var dim = this.element.getDimensions(); | ||
this.top = offset.top; | ||
this.left = offset.left; | ||
this.bottom = this.top + dim.height; | ||
this.right = this.left + dim.width; | ||
}, | ||
contains: function(other) { | ||
return other.left >= this.left && | ||
other.right <= this.right && | ||
other.top >= this.top && | ||
other.bottom <= this.bottom; | ||
}, | ||
intersectsWith: function(other) { | ||
return ((other.left >= this.left && other.left <= this.right) || | ||
(other.right >= this.left && other.right <= this.right)) && | ||
((other.top >= this.top && other.top <= this.bottom) || | ||
(other.bottom >= this.top && other.bottom <= this.bottom)); | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var insertRule = (function(){ | ||
var ss = document.styleSheets[0], | ||
reSelectorRule = /([^\{]*)\{([^\}]*)\}/; | ||
if (!ss) { | ||
var el = document.createElement('style'); | ||
el.type = 'text/css'; | ||
el.rel = 'stylesheet'; | ||
document.getElementsByTagName('head')[0].appendChild(el); | ||
ss = document.styleSheets[0]; | ||
} | ||
if (ss.addRule) { | ||
return function(rule) { // IE | ||
var match = rule.match(reSelectorRule); | ||
if (!match) return; | ||
var ss = document.styleSheets[document.styleSheets.length-1]; | ||
ss.addRule(match[1], match[2], ss.rules.length); | ||
} | ||
} | ||
return function(rule) { // Others | ||
if (!rule.match(reSelectorRule)) return; | ||
var ss = document.styleSheets[document.styleSheets.length-1]; | ||
ss.insertRule(rule, ss.cssRules.length); | ||
} | ||
})(); |