Dynamic Languages User Group Feb 7, DynApi Javascript Library
Dynamic Languages User Group Feb 7, Introduction DynApi Javascript Library Easily create dynamic cross-browser content for your website or application A complete Object oriented solution written completely in javascript
Dynamic Languages User Group Feb 7, Agenda Supported Browsers Non-Dynamic Features DynDocument DynLayer DynObject DynLibrary Event handling
Dynamic Languages User Group Feb 7, Overview Using the DynApi can accelerate your dynamic content Automatically handles cross-browser content DynLibrar y Events DynObject DynDocument DynLayer
Dynamic Languages User Group Feb 7, DynApi Library Created by Dan Steinman Open source development available at Includes additional tools Organized in a clear folder structure Distributed under GNU Public License
Dynamic Languages User Group Feb 7, Supported Browsers Opera 7+ Internet Explorer 4+ Konqueror 3+ Safari Netscape 4+ Mozilla 1+ Phoenix 0.5 Firefox
Dynamic Languages User Group Feb 7, Non-Dynamic Features Browser Sniffing URL Parsing Image Preloading Rollovers etc. DynApi functions (dynapi.functions) Cookie handling Non-Gui Widgets Event handling for Non-Gui Widgets
Dynamic Languages User Group Feb 7, DynDocument Replaces the DOM Uses js files to include in page Example: dynapi.library.setPath('../src/'); dynapi.library.include('dynapi.api');
Dynamic Languages User Group Feb 7, DynObject Dynamically create objects in memory String getClassName() // returns the className Function getClass() // returns constructor (class) of the // object boolean isClass(sClassName) // returns true if the object is //inherited from, or of the type sClassName void addMethod(sMethodName, function) void removeMethod(sMethodName) void setID(id) // sets the id of the object String toString() // returns [ClassName]
Dynamic Languages User Group Feb 7, Add your own Functions Adding functions to your objects Example function MyObject() { this.DynObject = DynObject; this.DynObject(); } var p = dynapi.setPrototype('MyObject','DynObject'); // ^ returns the prototype p.methodName = function() {};
Dynamic Languages User Group Feb 7, OnLoad() OnUnload() OnLoad and OnUnload p.onLoad(init); function init(){ alert(‘loaded’); }
Dynamic Languages User Group Feb 7, DynLibrary Assists with dependency issues Load scripts by name Load scripts in packages
Dynamic Languages User Group Feb 7, setPath() and add() setPath(“path to dynlibrary object”) dynapi.library.setPath('path'); // path to dynapi library (eg // "dynapi/src/lib"); add(“object name”) dynapi.library.add('objectName', '../file.js', 'dependentObject');
Dynamic Languages User Group Feb 7, Load as a Package Load scripts in as a package dynapi.library.setPath('../src/lib/'); // includes...
Dynamic Languages User Group Feb 7, Using include for individual scripts Loading scripts individually with include dynapi.library.include('dynapi'); // includes debug and library // functions dynapi.library.include('dynapi.debug'); dynapi.library.include('dynapi.library');
Dynamic Languages User Group Feb 7, Attach Events Attach Events to Child Objects function MyWidget() { this.DynLayer = DynLayer; this.Dynlayer(); this.pdlyr = new Dynlayer(); this.dlyr = this.pdlyr.addChild(new DynLayer()); this.dlyr.widget = this; this.dlyr.addEventListener(MyWidget.childEvents); } MyWidget.childEvents = { oncreate : function(e) { e.getSource().widget.update(); } }; MyWidget.prototype = new DynLayer; MyWidget.prototype.update = function() {};
Dynamic Languages User Group Feb 7, Attach Events Create an event listener in the constructor function MyWidget() { this.DynLayer = DynLayer; this.Dynlayer(); this.pdlyr = new Dynlayer(); this.dlyr = this.pdlyr.addChild(new DynLayer()); var widget = this; var el = { oncreate : function(e) {widget.update();} } this.dlyr.addEventListener(el); } MyWidget.prototype = new DynLayer; MyWidget.prototype.update = function() {};
Dynamic Languages User Group Feb 7, DynLayer The Constructor new DynLayer(html, x, y, width, height, bgColor) Positioning setLocation(x,y) - replaces moveTo
Dynamic Languages User Group Feb 7, Examples
Dynamic Languages User Group Feb 7, Summary DynApi Allows for easy object creation Cross browser scripting
Dynamic Languages User Group Feb 7, Where to Get More Information