Home » Source Code » » window.js

window.js ( File view )

From:
  • By 2010-08-11
  • View(s):5
  • Download(s):0
  • Point(s): 1
			// Copyright (c) 2006 S茅bastien Gruhier (http://xilinus.com, http://itseb.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// VERSION 0.96.2

var Window = Class.create();
Window.prototype = {

	// Constructor
	// Available parameters : className, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, 
	//                        hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent, onload
	initialize: function(id) {

	  if ($(id))
	    alert("Window " + id + " is already register is the DOM!!, be sure to use setDestroyOnClose()")
	    
		this.hasEffectLib = String.prototype.parseColor != null;
		this.options = Object.extend({

		  className:         "dialog",
      minWidth:          100,
      minHeight:         20,
      resizable:         true,
      closable:          true,
      minimizable:       true,
      maximizable:       true,
      draggable:         true,
      userData:          null,
      showEffect:        (this.hasEffectLib ? Effect.Appear : Element.show),
      hideEffect:        (this.hasEffectLib ? Effect.Fade : Element.hide),
      showEffectOptions: {

},
      hideEffectOptions: {

},
      effectOptions:     null,
      parent:            document.getElementsByTagName("body").item(0),
      title:             " ",
      url:               null,
      onload:            Prototype.emptyFunction,
      width:             200,
      height:            300,
      opacity:           1
    
}, arguments[1] || {

});
    		
	  if (this.options.effectOptions) {

	    Object.extend(this.options.hideEffectOptions, this.options.effectOptions);
	    Object.extend(this.options.showEffectOptions, this.options.effectOptions);
	  
}
		if (this.options.hideEffect == Element.hide)
		  this.options.hideEffect = function(){
 Element.hide(this.element); if (this.destroyOnClose) this.destroy(); 
}.bind(this)
		  
		this.element = this._createWindow(id);
		
		// Bind event listener
    this.eventMouseDown = this._initDrag.bindAsEventListener(this);
  	this.eventMouseUp   = this._endDrag.bindAsEventListener(this);
  	this.eventMouseMove = this._updateDrag.bindAsEventListener(this);
  	this.eventKeyPress  = this._keyPress.bindAsEventListener(this);
  	this.eventOnLoad    = this._getWindowBorderSize.bindAsEventListener(this);
    this.eventMouseDownContent = this.toFront.bindAsEventListener(this);
    this.eventResize = this._recenter.bindAsEventListener(this);
 
		this.topbar = $(this.element.id + "_top");
		this.bottombar = $(this.element.id + "_bottom");
    this.content = $(this.element.id + "_content");
    
		Event.observe(this.topbar, "mousedown", this.eventMouseDown);
		Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
		Event.observe(this.content, "mousedown", this.eventMouseDownContent);
		Event.observe(window, "load", this.eventOnLoad);
		Event.observe(window, "resize", this.eventResize);
  	Event.observe(window, "scroll", this.eventResize);
  	
		if (this.options.draggable)  {

			this.bottombar.addClassName("bottom_draggable");
			this.topbar.addClassName("top_draggable");
    
}		
    
		if (this.options.resizable) {

			this.sizer = $(this.element.id + "_sizer");
    	Event.observe(this.sizer, "mousedown", this.eventMouseDown);
    
}	
    
    this.useLeft = null;
    this.useTop = null;
		if (arguments[1].left != null) {

			this.element.setStyle({
left: parseFloat(arguments[1].left) + 'px'
});
			this.useLeft = true;
		
}
		if (arguments[1].right != null) {

			this.element.setStyle({
right: parseFloat(arguments[1].right) + 'px'
});
			this.useLeft = false;
		
}
    if (this.useLeft == null) {

	    this.element.setStyle({
left: "0px"
});
			this.useLeft = true;
    
}
    
		if (arguments[1].top != null) {

			this.element.setStyle({
top: parseFloat(arguments[1].top) + 'px'
});
			this.useTop = true;
		
}
		if (arguments[1].bottom != null) {

			this.element.setStyle({
bottom: parseFloat(arguments[1].bottom) + 'px'
});			
			this.useTop = false;
		
}
    if (this.useTop == null) {

			this.element.setStyle({
top: "0px"
});
			this.useTop = true;
    
}

    this.storedLocation = null;
    
		this.setOpacity(this.options.opacity);
		if (this.options.zIndex)
			this.setZIndex(this.options.zIndex)

		this.destroyOnClose = false;

    this._getWindowBorderSize();
    this.width = this.options.width;
    this.height = this.options.height;
    
    if (this.width && this.height)
		  this.setSize(this.options.width, this.options.height);
		this.setTitle(this.options.title)
		Windows.register(this);	    
  
},
  
	// Destructor
 	destroy: function() {

		Windows.notify("onDestroy", this);
		
  	Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
  	Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
  	Event.stopObserving(this.content, "mousedown", this.eventMouseDownContent);
    
		Event.stopObserving(window, "load", this.eventOnLoad);
		Event.stopObserving(window, "resize", this.eventResize);
  	Event.stopObserving(window, "scroll", this.eventResize);
		
		Event.stopObserving(this.content, "load", this.options.onload);

		if (this.sizer)
    		Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);

		if (this.options.url)
		  this.content.src = null

	 	if(this.iefix) 
			Element.remove(this.iefix);

    Element.remove(this.element);
		Windows.unregister(this);	    
	
},
  	
	// Sets window deleagte, should have functions: "canClose(window)" 
	setDelegate: function(delegate) {

		this.delegate = delegate
	
},
	
	// Gets current window delegate
	getDelegate: function() {

		return this.delegate;
	
},
	
	// Gets window content
	getContent: function () {

		return this.content;
	
},
	
	// Sets the content with an element id
	setContent: function(id, autoresize, autoposition) {

		var d = null;
		var p = null;

		if (autoresize) 
			d = Element.getDimensions(id);
		if (autoposition) 
			p = Position.cumulativeOffset($(id));

		var content = this.getContent()
		content.appendChild($(id));
		$(id).show();
		if (autoresize) 
			this.setSize(d.width, d.height);
		if (autoposition) 
		  this.setLocation(p[1] - this.heightN, p[0] - this.widthW);	  
	
},
	
	setAjaxContent: function(url, options, showCentered, showModal) {

	  this.showFunction = showCentered ? "showCenter" : "show";
	  this.showModal = showModal || false;
	
	  if (options == null)
	    options = {

}  
	  this.onComplete = options.onComplete;
	  options.onComplete = this._setAjaxContent.bind(this);
	  
	  new Ajax.Request(url, options);
	
},
	
	_setAjaxContent: function(originalRequest) {

	  this.getContent().innerHTML = originalRequest.responseText;
	  if (this.onComplete)
	    this.onComplete(originalRequest);
	  this[this.showFunction](this.showModal)
	
},
	
	// Stores position/size in a cookie, by default named with window id
	setCookie: function(name, expires, path, domain, secure) {

		name = name || this.element.id;
		this.cookie = [name, expires, path, domain, secure];
		
		// Get cookie
		var value = WindowUtilities.getCookie(name)
		// If exists
		if (value) {

			var values = value.split(',');
			var x = values[0].split(':');
			var y = values[1].split(':');

			var w = parseFloat(values[2]), h = parseFloat(values[3]);
			var mini = values[4];
			var maxi = values[5];

		  this.setSize(w, h);
			if (mini == "true")
		    this.doMinimize = true; // Minimize will be done at onload window event
			else if (maxi == "true")
			  this.doMaximize = true; // Maximize will be done at onload window event

			this.useLeft = x[0] == "l";
			this.useTop = y[0] == "t";

			this.element.setStyle(this.useLeft ? {
left: x[1]
} : {
right: x[1]
});
			this.element.setStyle(this.useTop ? {
top: y[1]
} : {
bottom: y[1]
});
		
}
	
},
	
	// Gets window ID
	getId: function() {

		return this.element.id;
	
},
	
	// Detroys itself when closing 
	setDestroyOnClose: function() {

	  Object.extend(this.options.hideEffectOptions, {
afterFinish:  this.destroy.bind(this)
});
		this.destroyOnClose = true;
	
},
	
	// initDrag event
	_initDrag: function(event) {

    // Get pointer X,Y
  	this.pointer = [Event.pointerX(event), Event.pointerY(event)];

    // Resize
		if (Event.element(event) == this.sizer) {

			this.doResize = true;
    	this.widthOrg = this.width;
    	this.heightOrg = this.height;
    	this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
    	this.rightOrg = parseFloat(this.element.getStyle('right'));
			Windows.notify("onStartResize", this);
		
}
    else {

		  this.doResize = false;

  		// Check if click on close button, 
  		var closeButton = $(this.getId() + '_close');
  		if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) 
  			return;

  		this.toFront();

  		if (! this.options.draggable) 
  		  return;
  		Windows.notify("onStartMove", this);
    
}  	
  	// Register global event to capture mou
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
auto_suggest.html1.09 kB03-12-07 00:11
crud.html1.68 kB03-12-07 00:11
03.00 B
2col_leftNav.css6.28 kB03-12-07 00:11
autosuggest.css335.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
logger.css1.88 kB03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
site.css1.43 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
03.00 B
auto_suggest.html.txt1.09 kB03-12-07 00:11
auto_suggest.js.txt669.00 B03-12-07 00:11
CountryList.java.txt3.00 kB03-12-07 00:11
crud.html.txt1.68 kB03-12-07 00:11
crud.js.txt1.40 kB03-12-07 00:11
crud.jst.txt755.00 B03-12-07 00:11
index.html.txt3.24 kB03-12-07 00:11
jst_demo.html.txt1.68 kB03-12-07 00:11
LabelValueBean.java.txt4.72 kB03-12-07 00:11
mvcPic.html.txt1.05 kB03-12-07 00:11
rdf.jst.txt284.00 B03-12-07 00:11
rss.jst.txt272.00 B03-12-07 00:11
rss_reader.html.txt1.20 kB03-12-07 00:11
rss_reader.js.txt642.00 B03-12-07 00:11
services.properties.txt168.00 B03-12-07 00:11
services.xml.txt435.00 B03-12-07 00:11
Test.java.txt17.36 kB03-12-07 00:11
TestBean.java.txt1.41 kB03-12-07 00:11
unit_test.html.txt1.03 kB03-12-07 00:11
unit_test.js.txt15.89 kB03-12-07 00:11
unit_test.jst.txt493.00 B03-12-07 00:11
unit_test_js.jst.txt765.00 B03-12-07 00:11
User.java.txt2.49 kB03-12-07 00:11
UserManager.java.txt2.04 kB03-12-07 00:11
web.xml.txt1.58 kB03-12-07 00:11
web.xml_no_spring.txt1.58 kB03-12-07 00:11
03.00 B
check.gif604.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.gif633.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
swato_01.png5.22 kB03-12-07 00:11
swato_02.png13.94 kB03-12-07 00:11
swato_04.png7.94 kB03-12-07 00:11
swato_05.png14.42 kB03-12-07 00:11
swato_Layer-5-over.png27.12 kB03-12-07 00:11
swato_Layer_5.png28.45 kB03-12-07 00:11
wait.gif1.52 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
index.html3.70 kB03-12-07 00:11
03.00 B
effects.js33.07 kB03-12-07 00:11
jkl-floating.js7.22 kB03-12-07 00:11
jkl-parsexml.js14.11 kB03-12-07 00:11
jkl-resizable.js5.05 kB03-12-07 00:11
json.js10.34 kB03-12-07 00:11
logger.js6.77 kB03-12-07 00:11
pop-it-menu.js4.44 kB03-12-07 00:11
prototype.js55.81 kB03-12-07 00:11
swato-engine.js5.06 kB03-12-07 00:11
swato-form.js3.00 kB03-12-07 00:11
swato-jst.js3.91 kB03-12-07 00:11
swato-select.js1.18 kB03-12-07 00:11
swato-suggest.js11.62 kB03-12-07 00:11
swato.js939.00 B03-12-07 00:11
window.js40.77 kB03-12-07 00:11
03.00 B
crud.jst744.00 B03-12-07 00:11
rdf.jst284.00 B03-12-07 00:11
rss.jst272.00 B03-12-07 00:11
unit_test.jst493.00 B03-12-07 00:11
unit_test_js.jst765.00 B03-12-07 00:11
jst_demo.html1.68 kB03-12-07 00:11
03.00 B
MANIFEST.MF106.00 B03-12-07 00:11
mvcPic.html1.05 kB03-12-07 00:11
rss_reader.html1.20 kB03-12-07 00:11
03.00 B
auto_suggest.js665.00 B03-12-07 00:11
crud.js1.41 kB03-12-07 00:11
portal.js4.66 kB03-12-07 00:11
rss_reader.js642.00 B03-12-07 00:11
unit_test.js15.89 kB03-12-07 00:11
swato.jar56.50 kB08-04-08 10:57
test.html18.36 kB03-12-07 00:11
unit_test.html1.03 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
03.00 B
JSONArray.class8.16 kB03-12-07 00:11
JSONObject$1.class199.00 B03-12-07 00:11
JSONObject$Null.class860.00 B03-12-07 00:11
JSONObject.class10.41 kB03-12-07 00:11
JSONTokener.class5.17 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
CountryList.class2.52 kB03-12-07 00:11
LabelValueBean$1.class825.00 B03-12-07 00:11
LabelValueBean.class2.15 kB03-12-07 00:11
LabelValueBeanTest.class1.88 kB03-12-07 00:11
ObjA.class571.00 B03-12-07 00:11
ObjB.class571.00 B03-12-07 00:11
Test$1.class565.00 B03-12-07 00:11
Test$2.class714.00 B03-12-07 00:11
Test$Foo.class231.00 B03-12-07 00:11
Test$InnerFoo.class643.00 B03-12-07 00:11
Test$InnerSubTestBean.class520.00 B03-12-07 00:11
Test$StaticInnerSubTestBean.class437.00 B03-12-07 00:11
Test$TestBeanInvocationHandler.class1.56 kB03-12-07 00:11
Test.class13.72 kB03-12-07 00:11
TestBean.class1.27 kB03-12-07 00:11
User.class1.65 kB03-12-07 00:11
UserManager.class2.27 kB03-12-07 00:11
JSONConverter.class8.00 kB03-12-07 00:11
JSONConverterTest$1.class240.00 B03-12-07 00:11
JSONConverterTest$TestBean.class1.73 kB03-12-07 00:11
JSONConverterTest.class6.13 kB03-12-07 00:11
03.00 B
JSONRequest.class2.96 kB03-12-07 00:11
JSONResponse.class2.41 kB03-12-07 00:11
JSONServlet.class4.00 kB03-12-07 00:11
PropsFileContext.class3.48 kB03-12-07 00:11
RequestAware.class198.00 B03-12-07 00:11
RequestParameterHolder.class2.36 kB03-12-07 00:11
RequestParameterRecorder.class2.17 kB03-12-07 00:11
RequestRedirector.class2.78 kB03-12-07 00:11
ServiceContext.class243.00 B03-12-07 00:11
SessionAware.class191.00 B03-12-07 00:11
SpringContext.class1.39 kB03-12-07 00:11
SwatoActionProxy.class4.86 kB03-12-07 00:11
SwatoVisible.class396.00 B03-12-07 00:11
03.00 B
Pipe.class2.02 kB03-12-07 00:11
Utils.class632.00 B03-12-07 00:11
services.properties168.00 B03-12-07 00:11
services.xml881.00 B03-12-07 00:11
03.00 B
commons-httpclient-2.0.2.jar220.09 kB03-12-07 00:11
commons-logging.jar37.12 kB03-12-07 00:11
spring-beans.jar213.99 kB03-12-07 00:11
spring-context.jar100.22 kB03-12-07 00:11
spring-core.jar71.98 kB03-12-07 00:11
web.xml1.58 kB03-12-07 00:11
...
Sponsored links

window.js (884.61 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D