Fix line endings

develop
Sven Slootweg 11 years ago
parent 61f94e46cd
commit 6b2f696448

@ -1,216 +1,216 @@
(function($){ (function($){
$.fn.disableSelection = function() { $.fn.disableSelection = function() {
return this return this
.attr('unselectable', 'on') .attr('unselectable', 'on')
.css('user-select', 'none') .css('user-select', 'none')
.on('selectstart', false); .on('selectstart', false);
}; };
$.fn.enableSelection = function() { $.fn.enableSelection = function() {
return this return this
.attr('unselectable', 'off') .attr('unselectable', 'off')
.css('user-select', 'text') .css('user-select', 'text')
.off('selectstart'); .off('selectstart');
}; };
$.fn.getWindow = function() { $.fn.getWindow = function() {
return this.closest(".window-inner").data("jsde-window"); return this.closest(".window-inner").data("jsde-window");
}; };
})(jQuery); })(jQuery);
var next_z_index = 1; var next_z_index = 1;
var currently_dragged_window = null; var currently_dragged_window = null;
var currently_dragging = false; var currently_dragging = false;
var drag_start = {x: 0, y: 0}; var drag_start = {x: 0, y: 0};
var currently_resized_window = null; var currently_resized_window = null;
var currently_resizing = false; var currently_resizing = false;
var resize_start = {x: 0, y: 0}; var resize_start = {x: 0, y: 0};
$(function(){ $(function(){
$("body").mousemove(_HandleMouseMove); $("body").mousemove(_HandleMouseMove);
$("body").mouseup(_HandleMouseUp); $("body").mouseup(_HandleMouseUp);
}) })
function JsdeWindow(options) function JsdeWindow(options)
{ {
$.extend(this, options); $.extend(this, options);
this._outer = $("#jsde_templates .template_window").clone()[0]; this._outer = $("#jsde_templates .template_window").clone()[0];
this._inner = $(this._outer).find(".window-inner")[0]; this._inner = $(this._outer).find(".window-inner")[0];
this._title = $(this._outer).children(".window-title")[0]; this._title = $(this._outer).children(".window-title")[0];
if(typeof options.visible !== "undefined" && options.visible == false) if(typeof options.visible !== "undefined" && options.visible == false)
{ {
this.Hide(); this.Hide();
} }
if(typeof options.title !== "undefined") if(typeof options.title !== "undefined")
{ {
this.SetTitle(options.title); this.SetTitle(options.title);
} }
if(typeof options.contents !== "undefined") if(typeof options.contents !== "undefined")
{ {
this.SetContents(options.contents); this.SetContents(options.contents);
} }
if(typeof options.x === "undefined") { this.x = 0; } if(typeof options.x === "undefined") { this.x = 0; }
if(typeof options.y === "undefined") { this.y = 0; } if(typeof options.y === "undefined") { this.y = 0; }
if(typeof options.width === "undefined") { this.width = 250; } if(typeof options.width === "undefined") { this.width = 250; }
if(typeof options.height === "undefined") { this.height = 200; } if(typeof options.height === "undefined") { this.height = 200; }
this.SetPosition(this.x, this.y); this.SetPosition(this.x, this.y);
this.SetSize(this.width, this.height); this.SetSize(this.width, this.height);
$(this._outer).click(this._HandleClick); $(this._outer).click(this._HandleClick);
$(this._outer).appendTo("body"); $(this._outer).appendTo("body");
$(this._title).mousedown(this._HandleMouseDown); $(this._title).mousedown(this._HandleMouseDown);
$(this._outer).data("jsde-window", this) $(this._outer).data("jsde-window", this)
$(this._inner).data("jsde-window", this) $(this._inner).data("jsde-window", this)
$(this._title).data("jsde-window", this) $(this._title).data("jsde-window", this)
$(this._outer).find(".window-close a").click(this._HandleClose); $(this._outer).find(".window-close a").click(this._HandleClose);
$(this._outer).find(".window-resizer").mousedown(this._HandleStartResize.bind(this)); $(this._outer).find(".window-resizer").mousedown(this._HandleStartResize.bind(this));
this.BringToForeground(); this.BringToForeground();
} }
JsdeWindow.prototype.BringToForeground = function() JsdeWindow.prototype.BringToForeground = function()
{ {
this.z = next_z_index; this.z = next_z_index;
$(this._outer).css({"z-index": next_z_index}) $(this._outer).css({"z-index": next_z_index})
next_z_index++; next_z_index++;
return this; return this;
} }
JsdeWindow.prototype.Close = function(forced) JsdeWindow.prototype.Close = function(forced)
{ {
if(typeof forced === "undefined") if(typeof forced === "undefined")
{ {
forced = false; forced = false;
} }
$(this._outer).remove(); $(this._outer).remove();
} }
JsdeWindow.prototype.GetContents = function() JsdeWindow.prototype.GetContents = function()
{ {
return $(this._inner).html(); return $(this._inner).html();
} }
JsdeWindow.prototype.GetTitle = function() JsdeWindow.prototype.GetTitle = function()
{ {
return $(this._title).children(".window-title-inner").html(); return $(this._title).children(".window-title-inner").html();
} }
JsdeWindow.prototype.Hide = function() JsdeWindow.prototype.Hide = function()
{ {
this.visible = false; this.visible = false;
return $(this._outer).hide(); return $(this._outer).hide();
} }
JsdeWindow.prototype.SetPosition = function(x, y) JsdeWindow.prototype.SetPosition = function(x, y)
{ {
this.x = x; this.x = x;
this.y = y; this.y = y;
return $(this._outer).css({left: this.x, top: this.y}); return $(this._outer).css({left: this.x, top: this.y});
} }
JsdeWindow.prototype.GetPosition = function() JsdeWindow.prototype.GetPosition = function()
{ {
return {x: this.x, y: this.y}; return {x: this.x, y: this.y};
} }
JsdeWindow.prototype.SetSize = function(width, height) JsdeWindow.prototype.SetSize = function(width, height)
{ {
this.width = width; this.width = width;
this.height = height; this.height = height;
return $(this._outer).css({width: this.width, height: this.height}); return $(this._outer).css({width: this.width, height: this.height});
} }
JsdeWindow.prototype.SetContents = function(html) JsdeWindow.prototype.SetContents = function(html)
{ {
console.log("set contents", html, this); console.log("set contents", html, this);
return $(this._inner).html(html); return $(this._inner).html(html);
} }
JsdeWindow.prototype.SetTitle = function(html) JsdeWindow.prototype.SetTitle = function(html)
{ {
return $(this._title).children(".window-title-inner").html(html); return $(this._title).children(".window-title-inner").html(html);
} }
JsdeWindow.prototype.Show = function() JsdeWindow.prototype.Show = function()
{ {
this.visible = true; this.visible = true;
return $(this._outer).show(); return $(this._outer).show();
} }
JsdeWindow.prototype._HandleClick = function(event) JsdeWindow.prototype._HandleClick = function(event)
{ {
$(this).data("jsde-window").BringToForeground(); $(this).data("jsde-window").BringToForeground();
} }
JsdeWindow.prototype._HandleMouseDown = function(event) JsdeWindow.prototype._HandleMouseDown = function(event)
{ {
currently_dragging = true; currently_dragging = true;
currently_dragged_window = $(this).data("jsde-window"); currently_dragged_window = $(this).data("jsde-window");
drag_start = {x: event.pageX - currently_dragged_window.x, y: event.pageY - currently_dragged_window.y}; drag_start = {x: event.pageX - currently_dragged_window.x, y: event.pageY - currently_dragged_window.y};
$(currently_dragged_window._outer).addClass("window-dragged"); $(currently_dragged_window._outer).addClass("window-dragged");
currently_dragged_window.BringToForeground(); currently_dragged_window.BringToForeground();
$("body").disableSelection(); $("body").disableSelection();
event.stopPropagation(); event.stopPropagation();
} }
JsdeWindow.prototype._HandleClose = function(event) JsdeWindow.prototype._HandleClose = function(event)
{ {
affected_window = $(this).closest(".window-title").data("jsde-window"); affected_window = $(this).closest(".window-title").data("jsde-window");
affected_window.Close(); affected_window.Close();
} }
JsdeWindow.prototype._HandleStartResize = function(event) JsdeWindow.prototype._HandleStartResize = function(event)
{ {
currently_resizing = true; currently_resizing = true;
currently_resized_window = this; currently_resized_window = this;
resize_start = {x: event.pageX - (currently_resized_window.x + currently_resized_window.width), resize_start = {x: event.pageX - (currently_resized_window.x + currently_resized_window.width),
y: event.pageY - (currently_resized_window.y + currently_resized_window.height)}; y: event.pageY - (currently_resized_window.y + currently_resized_window.height)};
$(currently_resized_window._outer).addClass("window-dragged"); $(currently_resized_window._outer).addClass("window-dragged");
currently_resized_window.BringToForeground(); currently_resized_window.BringToForeground();
$("body").disableSelection(); $("body").disableSelection();
event.stopPropagation(); event.stopPropagation();
} }
function _HandleMouseUp(event) function _HandleMouseUp(event)
{ {
if(currently_dragging === true) if(currently_dragging === true)
{ {
currently_dragging = false; currently_dragging = false;
$("body").enableSelection(); $("body").enableSelection();
$(currently_dragged_window._outer).removeClass("window-dragged"); $(currently_dragged_window._outer).removeClass("window-dragged");
} }
if(currently_resizing === true) if(currently_resizing === true)
{ {
currently_resizing = false; currently_resizing = false;
$("body").enableSelection(); $("body").enableSelection();
$(currently_resized_window._outer).removeClass("window-dragged"); $(currently_resized_window._outer).removeClass("window-dragged");
} }
} }
function _HandleMouseMove(event) function _HandleMouseMove(event)
{ {
if(currently_dragging === true) if(currently_dragging === true)
{ {
currently_dragged_window.SetPosition(event.pageX - drag_start.x, event.pageY - drag_start.y); currently_dragged_window.SetPosition(event.pageX - drag_start.x, event.pageY - drag_start.y);
} }
else if(currently_resizing === true) else if(currently_resizing === true)
{ {
var new_x = event.pageX - (resize_start.x + currently_resized_window.x); var new_x = event.pageX - (resize_start.x + currently_resized_window.x);
var new_y = event.pageY - (resize_start.y + currently_resized_window.y); var new_y = event.pageY - (resize_start.y + currently_resized_window.y);
currently_resized_window.SetSize(new_x, new_y); currently_resized_window.SetSize(new_x, new_y);
} }
} }

Loading…
Cancel
Save