', {class: 'js-pw-content'});
this.content_elem = this.generate_content_elem();
this.div_window.css('left', 100 + window.scrollX + 'px');
this.div_window.css('top', 100 + window.scrollY + 'px');
this.div_window.css('width', this.width + 'px');
this.div_window.css('height', this.height + 'px');
// putting things together
this.div_title.append(this.h3_title).append(this.a_close).appendTo(this.div_window);
this.div_content.append(this.content_elem).appendTo(this.div_window);
this.div_window.appendTo($('body'));
this.resize();
this.div_window.draggable();
this.div_window.resizable({
resize: function(e, ui) {
pw.resize();
}
});
this.manager = null;
// send event to server
io.push("open_file", this.path);
return this;
}
PreviewWindow.prototype.close = function() {
this.div_window.remove();
if (this.manager != null) {
this.manager.del(this);
}
io.push("close_file", this.path);
};
PreviewWindow.prototype.focus = function() {
var my_idx;
console.log("focus");
if (this.manager == null) {
return;
}
this.manager.del(this);
this.manager.add(this);
this.manager.set_zindex();
};
PreviewWindow.prototype.resize = function() {
this.width = this.div_window.width();
this.height = this.div_window.height();
this.div_content.height(this.div_window.height() - this.div_title.height());
};
PreviewWindow.prototype.reload = function() {
console.log("reload " + this.path);
this.content_elem.attr("src", "/preview/" + this.path + "?" + (new Date()).getTime());
};
PreviewWindow.prototype.generate_content_elem = function() {
var timehash = (new Date()).getTime().toString();
var src_url = "/preview/" + this.path + "?" + timehash;
if (this.path.match(/\.(jpe?g|png|eps|svg)/i)) { // images as img
// create off screen image first
var img = new Image();
img.onload = function() {
// TODO: window resizing
// alert(this.width + "x" + this.height);
}
img.src = src_url;
this.content_elem = $('
', {class: 'js-pw-content', src: src_url});
} else { // other files as text in iframe
this.content_elem = $('