Commit 24db763b authored by Dries's avatar Dries

- Patch #787940 by casey, Kiphaas7: generic approach for position:fixed elements like toolbar.

parent e14705f4
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
/** /**
* Provides a generic method to position elements fixed to the viewport. * Provides a generic method to position elements fixed to the viewport.
* *
* Fixed positioning (CSS declaration position:fixed) is done relatively to the * Fixed positioning (CSS declaration position:fixed) is done relative to the
* viewport. This makes it hard to position multiple fixed positioned element * viewport. This makes it hard to position multiple fixed positioned element
* relative to each other (e.g. multiple toolbars should come after each other, * relative to each other (e.g. multiple toolbars should come after each other,
* not on top of each other). * not on top of each other).
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* port add the class "displace-bottom". * port add the class "displace-bottom".
* *
* When a browser doesn't support position:fixed (like IE6) the element gets * When a browser doesn't support position:fixed (like IE6) the element gets
* positioned absolutely by default, but this can be overriden by using the * positioned absolutely by default, but this can be overridden by using the
* "displace-unsupported" class. * "displace-unsupported" class.
*/ */
...@@ -23,16 +23,9 @@ ...@@ -23,16 +23,9 @@
*/ */
Drupal.behaviors.displace = { Drupal.behaviors.displace = {
attach: function (context, settings) { attach: function (context, settings) {
// Test for position:fixed support as IE6 does not. // Test for position:fixed support.
// http://yura.thinkweb2.com/cft/#IS_POSITION_FIXED_SUPPORTED if (!Drupal.positionFixedSupported()) {
if (this.supported === undefined) { $(document.documentElement).addClass('displace-unsupported');
var el = $('<div style="position:fixed;top:10px"/>').appendTo(document.body);
this.supported = el[0].offsetTop === 10;
el.remove();
if (!this.supported) {
$(document.documentElement).addClass('displace-unsupported');
}
} }
$(document.body).once('displace', function () { $(document.body).once('displace', function () {
......
...@@ -299,6 +299,24 @@ Drupal.getSelection = function (element) { ...@@ -299,6 +299,24 @@ Drupal.getSelection = function (element) {
return { 'start': element.selectionStart, 'end': element.selectionEnd }; return { 'start': element.selectionStart, 'end': element.selectionEnd };
}; };
/**
* Checks if position:fixed is supported.
*
* @return
* Boolean indicating whether or not position:fixed is supported.
*
* @see http://yura.thinkweb2.com/cft/#IS_POSITION_FIXED_SUPPORTED
*/
Drupal.positionFixedSupported = function () {
if (this._positionFixedSupported === undefined) {
var el = $('<div style="position:fixed; top:10px" />').appendTo(document.body);
this._positionFixedSupported = el[0].offsetTop === 10;
el.remove();
}
return this._positionFixedSupported;
};
/** /**
* Build an error message from an AJAX response. * Build an error message from an AJAX response.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment