');
this.base(parent, object);
this.obj.addClass(options.cls);
this._create(options);
},
{
_create: function (options) {
options.width && this.obj.width(options.width);
options.height && this.obj.height(options.height);
this.aspect = options.aspect;
if (this.obj[0].nodeName == "IMG") {
var tmp = $('
').addClass("dq-image").insertBefore(this.obj);
this.obj.appendTo(tmp);
this.client = this.obj;
this.obj = tmp;
} else {
var style = this.obj[0].currentStyle || document.defaultView.getComputedStyle(this.obj[0], '');
var img = $('img', this.obj);
this.client = (img.length ? img : $('
').appendTo(this.obj))
.width(style.width).height(style.height);
if (options.imgHeight) {
this.client.height(options.imgHeght);
}
if (options.imgWidth) {
this.client.width(options.imgWidth);
}
}
if (options.preview) {
this.client.hide();
this._preview = $('
').attr('src', options.preview).appendTo(this.obj).hide();
}
options.src && this.src(options.src);
this.client.attr('alt', options.alt);
this.onLoaded = options.onLoaded;
this.onError = options.onError;
this.client.bind('load', this, function (e) {
var me = e.data;
me._preview && me._preview.hide().remove();
me.client.show();
var tmp = new Image();
tmp.src = me.src();
if (me.aspect) {
var style = me.obj[0].currentStyle || document.defaultView.getComputedStyle(me.obj[0], '');
if (tmp.width <= tmp.height) {
if (style.height == 'auto' || tmp.hegiht <= parseInt(style.height)) {
me.client.width(tmp.width);
me.client.height(tmp.height);
} else {
var dh = parseInt(style.height) / tmp.height;
me.client.width(tmp.width * dh);
me.client.height(tmp.height * dh);
}
} else {
if (style.width == 'auto' || tmp.width <= parseInt(style.width)) {
me.client.width(tmp.width);
me.client.height(tmp.height);
} else {
var dx = parseInt(style.width) / tmp.width;
me.client.width(tmp.width * dx);
me.client.height(tmp.height * dx);
}
}
}
me.onLoaded && me.onLoaded(me.client);
});
this.client.bind('error', this, function (e) {
var me = e.data;
me._preview && me._preview.hide();
me.client.show();
me.onError && me.onError.apply(me, arguments);
});
this.obj.bind('click', this, function (e) {
e.data.onClick && e.data.onClick(e.data, e);
});
this.onClick = options.onClick;
},
alt: function (value) {
if (!arguments.length) {
return this.client.attr('alt');
}
this.client.attr('alt', value);
},
animate: function (options) {
this.show();
options = DQ.options(options, {
speed: 15.625 * 3,
count: 4,
height: 32
});
var i = 0, me = this;
me.client.css('margin-left', 0);
setTimeout(function () {
i++;
me.client.css('margin-left', -options.height * i);
if (i == options.count) {
me.hide();
return;
}
setTimeout(arguments.callee, options.speed);
}, options.speed);
},
aspect: true,
fromFile: function (uri) {
///
/// 指定のイメージを読み込みます。
///
if (this._preview) {
this._preview.show();
this.client.hide();
}
this.client.attr('src', uri + "?" + new Date().getTime());
},
src: function (value) {
if (!arguments.length) {
return this.client.attr('src');
}
this.fromFile(value);
},
preview: "",
onClick: null,
onError: null,
onLoaded: null
});
function wait(condition, callback) {
var _condition = (typeof condition == "string") ?
function () { return eval(condition); } : condition;
if (_condition()) {
callback && callback();
}
setTimeout(function () {
if (_condtion()) {
callback && callback();
}
arguments.callee(arguments);
}, 15.625);
}