From b54f595387ef67a4e0455be21dde9da10949f193 Mon Sep 17 00:00:00 2001 From: peterd Date: Sat, 13 Sep 2014 14:26:28 +0200 Subject: [PATCH] opacity fix for IE10 _doesOpacity for detecting correct opacity ability --- colorPicker.js | 15 +++++++++------ developer/colorPicker.css | 2 +- jQuery_implementation/jqColor.js | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/colorPicker.js b/colorPicker.js index fbec47b..7fe52c9 100644 --- a/colorPicker.js +++ b/colorPicker.js @@ -15,6 +15,7 @@ // } _devMode = !_data, // if no _data we assume that colorPicker.data.js is missing (for development) _isIE = document.createStyleSheet !== undefined && document.getElementById, + _doesOpacity = typeof document.body.style.opacity !== 'undefined', // _isIE8 = _isIE && document.querySelectorAll, _valueRanges = {}, // will be assigned in initInstance() by Colors instance @@ -341,7 +342,7 @@ replace('_blank.png', !_isIE ? urlData + _data._blankPng : _options.imagePath + '_blank.cur'). replace('"Courier New",', !_isIE ? '' : '"Courier New",'). replace(/opacity:(\d*\.*(\d+))/g, function($1, $2){ - return _isIE ? '-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=' + + return !_doesOpacity ? '-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=' + Math.round(+$2 * 100) + ')";filter: alpha(opacity=' + Math.round(+$2 * 100) + ')' : '-moz-opacity: ' + $2 + '; -khtml-opacity: ' + $2 + '; opacity: ' + $2; }); @@ -353,9 +354,11 @@ } } - app.children[0].style.cssText = _options.initStyle || ''; // for initial hiding... + app = app.children[0]; + app.style.cssText = _options.initStyle || ''; // for initial hiding... + app.className = app.className.split(' ')[0]; // cleanup for multy instances - return (_options.appenTo || document.body).appendChild(app.children[0]); + return (_options.appenTo || document.body).appendChild(app); } function getInstanceNodes(colorPicker, THIS) { // check nodes again... are they all needed? @@ -1190,12 +1193,12 @@ function getOpacityCSS(value) { if (value === undefined) value = 1; - if (_isIE) { - return 'filter: alpha(opacity=' + Math.round(value * 100) + ');'; - } else { + if (_doesOpacity) { return 'opacity: ' + (Math.round(value * 10000000000) / 10000000000) + ';'; // value.toFixed(16) = 99% slower // some speed test: // return ['opacity: ', (Math.round(value * 1e+10) / 1e+10), ';'].join(''); + } else { + return 'filter: alpha(opacity=' + Math.round(value * 100) + ');'; } } diff --git a/developer/colorPicker.css b/developer/colorPicker.css index 7f61b80..5a95c43 100644 --- a/developer/colorPicker.css +++ b/developer/colorPicker.css @@ -645,6 +645,6 @@ filter: alpha(opacity=30); -moz-opacity: 0.3; -khtml-opacity: 0.3; - opacity: .30; + opacity: 0.30; display: block; } \ No newline at end of file diff --git a/jQuery_implementation/jqColor.js b/jQuery_implementation/jqColor.js index 7da1d67..243ef01 100644 --- a/jQuery_implementation/jqColor.js +++ b/jQuery_implementation/jqColor.js @@ -76,7 +76,7 @@ color: elm.value, // this has to go to focus as well!!! initStyle: 'display: none', mode: $.docCookies('colorPickerMode') || 'hsv-h', - memoryColors: $.docCookies('colorPickerMemos'), + memoryColors: $.docCookies('colorPickerMemos'), // no-alpha???? size: $.docCookies('colorPickerSize') || 1, renderCallback: renderCallback, actionCallback: actionCallback