From: Raphael D. P. <rap...@us...> - 2005-09-01 18:15:52
|
Update of /cvsroot/thyapi/thyapi/thybase In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32492/thybase Added Files: logothyapi.png thybase.js thydragevent.js Log Message: Synching... --- NEW FILE: thybase.js --- /***************************************************************************\ * ThyAPI - Thyamad Javascript API - Base Element * * http://www.thyamad.com * * * * Copyright (C) 2005 - Raphael Derosso Pereira * * Based on DynAPI v3.0b1 * * ------------------------------------------------------------------------- * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2.1 of the License, * * or any later version. * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License for more details. * \***************************************************************************/ /** * Class: thyBase * * Base class for all other ThyAPI Components. It defines fundamental * functions that all thyAPI components must have. * */ function thyBase (name) { this.DynObject = DynObject; this.DynObject(); } /** * Method: dynapi.setPrototype * * Overloaded DynAPI method that permits multiple inheritance * * Parameters: * * sC - Derivate Class * sP - Base class (or an array of base classes) * */ dynapi.setPrototype = function(sC,sP) { if (typeof(sP) == 'object') { if ((sP.constructor+'')!=(Array+'')) return alert('Prototype Error'); } else { sP = [sP]; } var i; var c = this.frame[sC]; if (!c) return alert('Prototype Error. Unable to find '+sC); var p = this.frame[sP[0]]; if (!p) return alert('Prototype Error. Unable to find '+sP[0]); c.prototype = new p(); for (i=1; i<sP.length; i++) { p = this.frame[sP[i]]; if (!p) return alert('Prototype Error. Unable to find '+sP[i]); var j,prototype = new p(); for (j in prototype) { // Keep existing methods preceded with their // respective class name if (typeof(prototype[j]) == 'function') c.prototype['_'+sP[i]+j] = prototype[j]; c.prototype[j] = prototype[j]; } } c.prototype._className = sC; c.prototype._pClassName = sP; c.toString = function() {return '['+sC+']'}; return c.prototype; } /** * Method: DynObject.isClass * * Overloaded method that checks if a class is derivate from another class * * Parameters: * * cn - base class * n - derivate class * */ DynObject.isClass = function(cn,n) { if (cn == n) return true; else { var c = dynapi.frame[cn]; var p = c.prototype._pClassName; if (p) { if (typeof(p) != 'object') return DynObject.isClass(p,n); var i, result; for (i=0; i<p.length; p++) { if (DynObject.isClass(p[i],n)) return true; } return false; } else return false; } }; p = dynapi.setPrototype('thyBase', 'DynObject'); /** * Method: isFromClass * * Checks if the object is from the specified class type or from a class * derivate from that. * * Parameter: * * className - The name of the class to be checked * * Returns: * * Boolean * */ p.isFromClass = p.isClass; /** * Method: setName * * Changes the name of the widget * * Parameter: * * name - The new widget name * */ p.setName = function (name) { if (name == null || this.name == name) return; this.name = name; } /** * Method: clone * * Returns an exact copy of object (including children and DOM nodes) * * Parameter: * * name - The new name of the object * * FIXME: NOT DONE YET!!! */ p.clone = function (name) { var clone = eval('new '+this._className); var i; for (i in this) { switch (typeof(this[i])) { case 'object': // Do not clone special objects switch (i) { case 'parent': case 'elm': case 'children': clone[i] = null; } if (clone[i] == null) break; // Clone children if (typeof(this[i].clone) == 'function') { clone[i] = this[i].clone(); break; } default: // Do not clone functions and already cloned nodes if (clone[i] == this[i]) break; clone[i] = dynapi.functions.cloneObject(this[i]); } } if (name) { clone.setName(name); } else { clone.setName(clone.name); } if (!this._created) return; var cloneDOM = this.elm.cloneNode(true); var updateID = function (elm, children) { var k; for (k=0; k<children.length; k++) { elm.id = "DynObject"+DynObject._c++; } } } /** * Function: showMessage * * Shows the message * * FIXME: This MUST be implemented using a thyDialog */ function showMessage(message) { alert(message); } --- NEW FILE: logothyapi.png --- (This appears to be a binary file; contents omitted.) --- NEW FILE: thydragevent.js --- /***************************************************************************\ * ThyAPI - Thyamad Javascript API - DragEvent Element * * http://www.thyamad.com * * * * Copyright (C) 2005 - Raphael Derosso Pereira * * Based on DynAPI v3.0b1 * * ------------------------------------------------------------------------- * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2.1 of the License, * * or any later version. * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License for more details. * \***************************************************************************/ /** * Class: thyDragEvent * * This class is based on original DynAPI DragEvent Object, but optimized * for thyAPI functions * */ function thyDragEvent(type,src) { this.thyBase = thyBase; this.thyBase(); this.MouseEvent = MouseEvent; this.MouseEvent(); this.DynEvent(); this.isDragging = false; } var p = dynapi.setPrototype('thyDragEvent',['MouseEvent','thyBase']); p.getX = function() { return this.x; } p.getY = function() { return this.y; } p.getPageX = function() { return this.pageX; } p.getPageY = function() { return this.pageY; } p.cancelDrag = function() { this.isDragging=false; } thyDragEvent.dragevent = new thyDragEvent(); thyDragEvent.lyrListener = { onmousedown : function(e) { var icon,o = e.getSource(); icon = o; //setup drag icon if(o._useDragIcon && o._dragIcon) { icon=o._dragIcon; icon._dragOrg = o; icon.setX(o.getPageX()); icon.setY(o.getPageY()); icon.setWidth(o.getWidth()); icon.setHeight(o.getHeight()); } // Save original offset to keep mouse on its original position icon._dragOrigXOff = o.getX() - e.getPageX(); icon._dragOrigYOff = o.getY() - e.getPageY(); // Prevent Text Selection var orig = e.getOrigin(); orig._oldTextSelectable = orig._textSelectable; orig.setTextSelectable(false); thyDragEvent.dragevent.preStartDrag = true; thyDragEvent.dragevent.toDrag = icon; thyDragEvent.dragevent.event = e; thyDragEvent.dragevent.orig = orig; } } thyDragEvent.startDrag = function(e,dlyr) { var origdlyr = dlyr; if (!dlyr) dlyr = e.getSource(); if (dynapi.ua.dom) { dlyr.elm.ondragstart = function() { return false; }; dlyr.elm.onselectstart = function() { return false; }; if(dlyr._dragOrg) { dlyr._dragOrg.elm.ondragstart = function () {return false}; dlyr._dragOrg.elm.onselectstart = function() { return false; }; } } // Initialize dragEvent object var de=thyDragEvent.dragevent; de.src = dlyr; de.origin = (origdlyr)? e.origin : dlyr; //de.x = e.getPageX()-dlyr.getAbsoluteX(); //de.y = e.getPageY()-dlyr.getAbsoluteY(); de.x = e.getPageX(); de.y = e.getPageY(); de.pageX = e.getPageX(); de.pageY = e.getPageY(); if (dlyr.parent) { de.parentPageX = parseInt(dlyr.parent.getPageX()); de.parentPageY = parseInt(dlyr.parent.getPageY()); } de._mouseEvent = e._mouseEvent; de._browserEvent = e._browserEvent; // ns4 only de.isDragging = true; e.preventDefault(); //e.preventBubble(); dlyr.invokeEvent("dragstart",de); if(dlyr._dragOrg) { dlyr.setDisplay(true); dlyr._dragOrg.invokeEvent("dragstart",e); } } thyDragEvent.docListener = { onmousemove : function(e) { var de = thyDragEvent.dragevent; if (de && !de.isDragging && de.preStartDrag) { thyDragEvent.startDrag(de.event,de.toDrag); de.preStartDrag = false; } else if (de && de.isDragging) { var lyr = de.src; if (!lyr) return; // Properties de.type = "dragmove"; de.pageX = e.getPageX(); de.pageY = e.getPageY(); de._mouseEvent = e._mouseEvent; de._browserEvent = e._browserEvent; // ns4 only //var x=de.pageX-de.parentPageX-de.x; //var y=de.pageY-de.parentPageY-de.y; //var x = de.pageX - lyr.getWidth()/2; //var y = de.pageY - lyr.getHeight()/2; var x = de.pageX + lyr._dragOrigXOff; var y = de.pageY + lyr._dragOrigYOff; // Respect boundary, if any if (lyr._dragBoundary) { var dB = lyr._dragBoundary; var t = dB.top; var r = dB.right; var b = dB.bottom; var l = dB.left; // prevent choppy dragging if child is greater than parent var pw = (lyr.parent.w>lyr.w)? lyr.parent.w-lyr.w:lyr.x; var ph = (lyr.parent.h>lyr.h)? lyr.parent.h-lyr.h:lyr.y; if (x<l) x = l; else if (x>pw-r) x = pw-r; if (y<t) y = t; else if (y>ph-b) y = ph-b; } else if (lyr._dragBoundaryA) { var dB = lyr._dragBoundaryA; var b = dB[2]; var r = dB[1]; var l = dB[3]; var t = dB[0]; var w = lyr.w; var h = lyr.h; if (x<l) x = l; else if (x+w>r) x = r-w; if (y<t) y = t; else if (y+h>b) y = b-h; } // Stop at document edge if (x < 0) x = 0; if (y < 0) y = 0; // Move dragged layer lyr.setX(x); lyr.setY(y); lyr.invokeEvent("dragmove",de); // drag icon if(lyr._dragOrg) { lyr._dragOrg.invokeEvent("dragmove",e); } if (lyr._dragStealth==false && lyr.parent.DragOver) { lyr.parent.DragOver(lyr,e.getPageX(),e.getPageY()); } e.preventDefault(); e.preventBubble(); } }, onmouseup : function(e) { // Get, if any, the currently drag in process and the layer. If none, return var de=thyDragEvent.dragevent; if (!de) return; if (!de.isDragging) { de.type="dragend"; de.src=null; de.preStartDrag = false; if (de.orig) de.orig.setTextSelectable(de.orig._oldTextSelectable); //e.setBubble(true); return; } var lyr=de.src; if (!lyr) return; //if (dynapi.ua.ie) lyr.doc.body.onselectstart = null; // Avoid click for the dragged layer ( with MouseEvent addition ) if (dynapi.ua.def) dynapi.wasDragging=true; if (lyr.parent.DragDrop) lyr.parent.DragDrop(lyr,e.getPageX(),e.getPageY()); // Properties for the event de.type="dragend"; de.isDragging=false; lyr.invokeEvent("dragend",de); // drag icon if(lyr._dragOrg) { lyr.setDisplay(false); lyr._dragOrg.invokeEvent("dragend",de); } // Clean drag stuff de.src=null; e.preventDefault(); de.orig.setTextSelectable(de.orig._oldTextSelectable); //e.preventBubble(); } } thyDragEvent.stopAtDocumentEdge = true; thyDragEvent.setDragBoundary = function(lyr,t,r,b,l) { if (!lyr) {dynapi.debug.print("Error: no object passed to thyDragEvent.setDragBoundary()"); return;} var a=arguments; if (a.length==0) return; if (a.length==1) { lyr._dragBoundary = {left:0,right:0,top:0,bottom:0}; } if (a.length==2) { lyr._dragBoundary = arguments[1]; } else if (a.length==5) { lyr._dragBoundaryA = [t,r,b,l]; } } thyDragEvent.enableDragEvents=function() { for (var i=0;i<arguments.length;i++) { var lyr=arguments[i]; if (!lyr) {dynapi.debug.print("Error: no object passed to DragEvent.enableDragEvents()"); return;} if (lyr.isClass('DynLayer')) lyr.addEventListener(thyDragEvent.lyrListener); } dynapi.document.addEventListener(thyDragEvent.docListener); dynapi.document.captureMouseEvents(); } thyDragEvent.disableDragEvents=function() { for (var i=0;i<arguments.length;i++) { var lyr=arguments[i]; lyr.removeEventListener(thyDragEvent.lyrListener); } } // used mainly inside ondrop and ondragover thyBase.prototype.getDragSource = function() { return this._dragOrg||this; } thyBase.prototype.setDragEnabled = function(b,boundry,useIcon) { if (!self.thyDragEvent) { return false; } if (boundry) { thyDragEvent.setDragBoundary(this,boundry); } if (b) { thyDragEvent.enableDragEvents(this); } else { thyDragEvent.disableDragEvents(this); } this._useDragIcon = useIcon; return true; } thyBase.prototype.setDragIcon = function(icon) { if(!icon) return; this._dragIcon = icon; icon.setZIndex({topmost:true}); icon.setDisplay(false); dynapi.document.addChild(icon); } thyBase.prototype.setDragOverStealthMode = function(b) { this._dragStealth=(b)? true:false; } // Enable ondrop event thyBase.prototype.DragDrop=function(s,mX,mY) { if (!this.children.length) return false; var ch,chX,sX,sY; for (var i in this.children) { ch=this.children[i]; if(!ch._hasDragEvents) ch.DragDrop(s,mX,mY); else { chX=ch.getPageX(); chY=ch.getPageY(); //sX=s.getPageX(); //sY=s.getPageY(); //if (chX<sX && chX+ch.w>sX+s.w && chY<sY && chY+ch.h>sY+s.h) { if ((mX>=chX && mX<=chX+ch.w) && (mY>=chY && mY<=chY+ch.h)) { if (ch.DragDrop(s,mX,mY)) return true; ch.invokeEvent("drop",null,s); return true; } } } return false; }; // Enable ondragover event thyBase.prototype.DragOver=function(s,mX,mY) { if (!this.children.length) return false; var ch,chX,sX,sY; for (var i in this.children) { ch=this.children[i]; if (!ch._hasDragEvents) ch.DragOver(s,mX,mY); else { chX=ch.getPageX(); chY=ch.getPageY(); if ((mX>=chX && mX<=chX+ch.w) && (mY>=chY && mY<=chY+ch.h)) { if (ch.DragOver(s,mX,mY)) return true; ch._isDragOver=true; ch.invokeEvent("dragover",null,s); return true; } else if (ch._isDragOver) { ch._isDragOver=false; ch.invokeEvent("dragout",null,s); } } } return false; }; |