1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
function Opacity(p) {
this._construct(p || {});
}
(function() {
Opacity.prototype = {
step: [],
timer: [],
opt: {},
// Constructor, set default parameters
// * #access public
_construct: function(p) {
with (this) {
opt.object = p.object;
opt.end = !isNaN(p.end) ? p.end : 100;
opt.speed = p.speed || 5;
opt.step = p.step || 1;
opt.finish = p.finish;
}
},
// Get browser codeName
// * #access protected
_client: new function () {
var nav = navigator.userAgent;
if (/MSIE|Microsoft/.test(nav))
this.IE = true;
else if (/Firefox/.test(nav))
this.FF = true;
else if (/Opera/.test(nav))
this.Opera = true;
},
// * Make fade
// * #access public
_fadeOpacity: function (p) {
var obj = (p.object || this.opt.object);
if (this.timer[obj]) clearTimeout(this.timer[obj]);
if ($(obj) == null) alert('Unable to get object: '+(obj || 'not defined'));
this._doOpacity(obj,this._getOpacity(obj),(!isNaN(p.end) ? p.end : this.opt.end),(p.speed || this.opt.speed),(p.step || this.opt.step),(p.finish || this.opt.finish));
},
// * Recursive set opacity with the set parameters
// * #access private
_doOpacity: function (o,b,s,n,m,i) {
var x = this.step[o];
x = parseInt((b<s) ? b+m : b-m);
this._setOpacity(o,x);
this._doDebug(o,x);
if ((x <= s && b>s) || (x >= s && b<s)) {
this._doDebug(o,s);
if (typeof i == 'function') eval(i());
return;
}
this.timer[o] = setTimeout(function () {Opacity.prototype._doOpacity(o,x,s,n,m,i)},n);
},
// * Cross-browser method to set opacity value
// * #access protected
_setOpacity: function (o,v) {
if (this._client.IE)
$(o || this.opt.object).style.filter = 'alpha(opacity='+v+')';
else
$(o || this.opt.object).style[(this._client.FF) ? 'MozOpacity' : 'opacity'] = (v/100);
},
// * Method to get cross-browser opacity value
// * #access protected
_getOpacity: function (o) {
if(this._client.IE)
return (new RegExp("opacity\\s*=\\s*(\\d+)", "i").test($(o || this.opt.object).currentStyle["filter"])) ? Number(RegExp["$1"]) : '';
else
return parseInt(document.defaultView.getComputedStyle($(o || this.opt.object), null).getPropertyValue((this._client.FF) ? "-moz-opacity" : "opacity")*100);
},
// * Removed in original ver., only for debugging purposes
// * #access private
_doDebug: function(o,v) {
if ($("debug") == null) {
// main container
var obj_div = document.createElement("DIV");
obj_div.setAttribute('id','cdebug');
// title container
var obj_tdiv = document.createElement("DIV");
obj_tdiv.innerHTML = "Debugger";
obj_tdiv.className = 'beduggerTitle';
obj_div.appendChild(obj_tdiv);
// debug container
var obj_mdiv = document.createElement("DIV");
obj_mdiv.style.cssText = "padding: 5px";
obj_mdiv.setAttribute('id','debug');
obj_div.appendChild(obj_mdiv);
document.body.appendChild(obj_div);
}
if ($("debug_"+o) == null) {
var obj_div = document.createElement("DIV");
obj_div.setAttribute('id','debug_'+o);
$("debug").appendChild(obj_div);
}
$("debug_"+o).innerHTML = "<b>"+o+":</b> "+v+" %";
}
}
})();