[新着] Webテンプレートを仮オープンしました
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>プログレスバー</title>
<script type="text/javascript">
if (document.implementation
&& (window.addEventListener || window.attachEvent)
&& Function.prototype
&& Function.prototype.call)
var ProgressBar = (function () {
////////////////////////////////////////////////////////////////////////
function Timer (msec) {
this.timeOut = msec || 1000;
this.timerID = null;
this.timerListener = null;
}
Timer.prototype.addTimerListener = function (listener) {
this.timerListener = listener;
};
Timer.prototype.start = function () {
this.timerID = function (thisObj, callback) {
return setTimeout (
function() {
thisObj.timerListener ();
callback.call (thisObj);
},
thisObj.timeOut
);
} (this, arguments.callee);
};
Timer.prototype.stop = function () {
clearTimeout (this.timerID);
};
//______________________________________________________________________
function ComputedStyle () {
this.width = '0px';
this.height = '1em';
this.background = '#999';
this.border = '1px solid #222';
}
ComputedStyle.prototype.expand = function (pixelWidth) {
this.width = (parseInt (this.width) + pixelWidth) + 'px';
};
//______________________________________________________________________
function ProgressBar () {
Timer.apply (this, arguments);
this.targetNode = document.createElement ('p');
ComputedStyle.call (this.targetNode.style);
};
ProgressBar.prototype = new Timer;
ProgressBar.prototype.constructor = ProgressBar;
ProgressBar.prototype.increase = function () {
ComputedStyle.prototype.expand.apply (this.targetNode.style, arguments);
};
ProgressBar.prototype.addEventListener = function (type, listener, useCapture) {
this.targetNode./*@cc_on @if (@_jscript) attachEvent ('on' + @else @*/
addEventListener (/*@end @*/ type, listener, useCapture);
};
//______________________________________________________________________
ProgressBar.create = function () {
var pb = new this (60);
document.body.appendChild (pb.targetNode);
pb.addTimerListener (function () {
this.increase (2);
} );
pb.addEventListener ('mouseup', function (e) {
pb.stop ();
}, false);
pb.start ();
};
return ProgressBar;
////////////////////////////////////////////////////////////////////////
} )();
</script>
<p style="cursor: pointer; " onclick="ProgressBar.create (); ">プログレスバー追加</p>if ('undefined' == typeof Function.prototype.apply)
Function.prototype.apply = function (thisObj, argArray) {
var result;
var tmpObj = (null == thisObj) ? window : thisObj;
var tmpArg = Array.prototype.slice (arguments, 0).toString ();
tmpObj._$method = this;
result = eval ('tmpObj._$method (' + tmpArg + ')');
delete tmpObj._$method;
return result;
}
if ('undefined' == typeof Function.prototype.call)
Function.prototype.call = function (thisObj) {
return Function.prototype.apply (thisObj, Array.prototype.slice (arguments, 1));
}
//______________________________________________________________________
ProgressBar.prototype.addEventListener = function (type, listener, useCapture) {
try {
// ........
} catch (e) {
this.targetNode['on' + type] = listener; // 手抜き
}
};if ('undefined' == typeof Array.prototype.push)
Array.prototype.push = (function () {
return function () {
var i = 0;
var I = arguments.length;
while (i < I)
this[this.length] = arguments[i++];
return this.length;
};
} )();
if ('undefined' == typeof Array.prototype.slice)
Array.prototype.slice = (function () {
return function (start, end) {
var result = [ ];
var i = toPositive (start, this.length);
var I = ('undefined' == typeof end) ? this.length : toPositive (end, this.length);
while (i < I)
result.push (this[i++]);
return result;
};
function toPositive (n, max) {
n = Number (parseInt (n));
return (n < 0) ? Math.max (n + max, 0) : Math.min (n, max);
}
} )();