SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
JavaScript Libraries Overview

          Siarhei Barysiuk
   s.barysiuk@sam-solutions.net
Our roadmap
Libraries: What we will cover today...
5 great open source libraries for your project.
  • prototype
  • jQuery
  • dojo
  • qooxdoo
Libraries: General picture
Global picture




    Lightweight              Widgets   One-page Applications
Prototype
Prototype: Overview
                      http://prototypejs.org
Prototype: Focus
• DOM manipulation
• Ajax transport
• Utility methods for built-in objects
• Class-based OOP
Prototype: DOM manipulation
Say goodbye to getElementById()

 document.getElementById(quot;idquot;).innerHTML = quot;<li>node</li>quot;;



Say hello to $()


  $(quot;idquot;).innerHTML = quot;<li>node</li>quot;;


  $(element)                      extended DOM element
Prototype: DOM Element extension
                            * extend                   * makePositioned
 * absolutize                                                                 * select
                            * fire                      * match
 * addClassName                                                               * setOpacity
                            * firstDescendant           * next
 * addMethods                                                                 * setStyle
                            * getDimensions            * nextSiblings
 * adjacent                                                                   * show
                            * getElementsByClassName   * observe
 * ancestors                                                                  * siblings
                            * getElementsBySelector    * positionedOffset
 * childElements                                                              * stopObserving
                            * getHeight                * previous
 * classNames                                                                 * toggle
                            * getOffsetParent          * previousSiblings
 * cleanWhitespace                                                            * toggleClassName
                            * getStyle                 * readAttribute
 * clonePosition                                                              * undoClipping
                            * getWidth                 * recursivelyCollect
 * cumulativeOffset                                                           * undoPositioned
                            * hasClassName             * relativize
 * cumulativeScrollOffset                                                     * up
                            * hide                     * remove
 * descendantOf                                                               * update
                            * identify                 * removeClassName
 * descendants                                                                * viewportOffset
                            * immediateDescendants     * replace
 * down                                                                       * visible
                            * insert                   * scrollTo
 * empty                                                                      * wrap
                            * inspect                                         * writeAttribute
                            * makeClipping


 $('message').addClassName('read').update('I read this message!').setStyle({opacity: 0.5});
Prototype: Creating a DOM element
The old way:
var a = document.createElement('a');
a.setAttribute('class', 'foo');
a.setAttribute('href', '/foo.html');
a.appendChild(document.createTextNode(quot;Next pagequot;));


The new way:

var a = new Element('a', { 'class': 'foo', href: '/foo.html' }).update(quot;Next pagequot;);
Prototype: Even more bucks
$((id | element)...) -> [HTMLElement...]
$$(cssRule...) -> [HTMLElement...]
$A(iterable) -> actualArray

$F(element) -> value
$H([obj]) -> Hash

$R(start, end[, exclusive = false]) -> ObjectRange

$w(String) -> Array
Prototype: Event handling
$('foo').observe('click', respondToClick);

function respondToClick(event) {
  var element = event.element();
  element.addClassName('active');
}
Prototype: Ajax transport
new Ajax.Request('/some_url',{
		       method:'get',
		       onSuccess: function(transport){
		          var response = transport.responseText || quot;no response textquot;;
		          alert(quot;Success! nnquot; + response);
		       },
		       onFailure: function(){ alert('Something went wrong...') }
		     });



Also available are onXXX callbacks, where XXX is the HTTP response status
like 200 or 404.
Prototype: Ajax transport
new   Ajax.Request('/some_url', {
		     	   method: 'get',
		     	   parameters: {company: 'example', limit: 12}
		     	   });



new Ajax.Request('/some_url', {
			      parameters: $('id_of_form_element').serialize(true)
			      });


                                             form serialization
Prototype: Ajax magic
        new Ajax.Updater(
	   	   			{
	   	   	 	 	 	 success: 'products', 3.1
	   	   	 	 	 	 failure: 'errors'           3.2
	   	   	 	 	 },
	   	   	 	 	 '/some_url', 1
	   	   			{
	   	   			      method: 'get', 2
	   	   			      insertion: Insertion.Top   4
	   	   			}
	   	   	 );
Prototype: Built-in object extensions
                                                             * all
                                                             * any
                                                             * collect
        var myObject = {};                                   * detect
                                                             * each
                                                             * eachSlice
	   	   ['foo', 'bar', 'baz'].each(function(name, index) {
                                                             * entries
	   	     this[name] = index;                                * find
	   	   }, myObject); // we have specified the context       * findAll
                                                             * grep
	   	                                                        * inGroupsOf
	   	   myObject                                             * include
                                                             * inject
	   	   //-> { foo: 0, bar: 1, baz: 2}
                                                             * invoke
                                                             * map
                                                             * max
                                                             * member
                                                             * min
                                                             * partition
                                                             * pluck
                                                             * reject
                                                             * select
                                                             * size
                                                             * sortBy
                                                             * toArray
                                                             * zip
Prototype: Built-in object extensions                    * blank
                                                         * camelize
                                                         * capitalize
                                                         * dasherize
quot;<h1>hello, i'm HTML</h1>quot;.escapeHTML()                  * empty
                                                         * endsWith
//-> quot;&lt;h1&gt;hello, i'm HTML&lt;/h1&gt;quot;              * escapeHTML
                                                         * evalJSON
                                                         * evalScripts
'background-color'.camelize(); // -> 'backgroundColor'   * extractScripts
                                                         * gsub
                                                         * include
'Prototype framework'.include('frame'); //-> true        * inspect
'Prototype framework'.include('frameset');//-> false     * interpolate
                                                         * isJSON
                                                         * parseQuery
                                                         * scan
quot;echo quot;.times(3);   //-> quot;echo echo echo quot;
                                                         * startsWith
                                                         * strip
                                                         * stripScripts
quot;#{animals} on a #{transport}quot;.interpolate({
                                                         * stripTags
                    animals: quot;Pigsquot;,                     * sub
                                                         * succ
                    transport: quot;Surfboardquot; });           * times
//-> quot;Pigs on a Surfboardquot;                               * toArray
                                                         * toJSON
                                                         * toQueryParams
                                                         * truncate
                                                         * underscore
                                                         * unescapeHTML
                                                         * unfilterJSON
Prototype: Class-based OOP
var Person = Class.create({
  initialize: function(name) {
     this.name = name;
  },
  say: function(message) {
     return this.name + ': ' + message;
  }
});




var Pirate = Class.create(Person, {
  // redefine the speak method
  say: function($super, message) {
    return $super(message) + ', yarr!';
  }
});

var john = new Pirate('Long John');
john.say('ahoy matey');
// -> quot;Long John: ahoy matey, yarr!quot;
Prototype: Real life example
            http://gmx.com http://web.de http://gmx.de
Prototype: Conclusion

• lightweight
• good for small projects
• a lot of useful methods
• transport support
• effects with script.aculo.us
• good documented
• a lot of real project which use prototype
Questions?
jQuery
jQuery: Overview
                   http://jquery.com
jQuery: Focus
Motto: Write less, do more.
• DOM manipulation
• Ajax transport
• Effects
• Other functionality with plugins
jQuery: DOM manipulation
Very powerful selectors.

$(quot;#myDivquot;).css(quot;borderquot;,quot;3px solid redquot;);

$(quot;divquot;).css(quot;borderquot;,quot;3px solid redquot;);

$(quot;.myClassquot;).css(quot;borderquot;,quot;3px solid redquot;);

$(quot;*quot;).css(quot;borderquot;,quot;3px solid redquot;);

$(quot;div,span,p.myClassquot;).css(quot;borderquot;,quot;3px solid redquot;);
jQuery: DOM manipulation
Even more powerful than you expect.
$('li:eq(0)')

$('li:even')

$('li:lt(3)')

$('li:not(.goofy)')

$('p a[href*=#]')

$('code, li.goofy')

$('ol .goofy > strong')

$('li + li > a[href$=pdf]')

$('span:hidden')
jQuery: DOM manipulation
Attributes:                 Text:
     attr( name )             text( )
     attr( properties   )     text( val )
     attr( key, value   )
                            HTML:
     attr( key, value   )
     removeAttr( name   )
                               html( )
Classes:                       html( val )
     addClass( class )
                            Value:
     hasClass( class )
     removeClass( class )      val( )
     toggleClass( class )      val( val )
jQuery: DOM manipulation
append( content )
appendTo( content )

prepend( content )
prependTo( content )

after( content )
before( content )

insertAfter( content )
insertBefore( content )

wrap( html )

replaceWith( content )

clone( )
jQuery: Events
Very convenient event handling system.

  3 main methods:

   bind( type, data, fn )

   trigger( type, data )

   unbind( type, data )
jQuery: Binding event handlers
$(quot;pquot;).bind(quot;clickquot;, function(e){
  var str = quot;( quot; + e.pageX + quot;, quot; + e.pageY + quot; )quot;;
  $(quot;spanquot;).text(quot;Click happened! quot; + str);
});

$(quot;pquot;).bind(quot;dblclickquot;, function(){
  $(quot;spanquot;).text(quot;Double-click happened in quot; + this.tagName);
});

$(quot;pquot;).bind(quot;mouseenter mouseleavequot;, function(e){
    $(this).toggleClass(quot;overquot;);
});


$(quot;pquot;).trigger(quot;clickquot;);
jQuery: Binding event handlers
$(quot;pquot;).click(function(e){
  var str = quot;( quot; + e.pageX + quot;, quot; + e.pageY + quot; )quot;;
  $(quot;spanquot;).text(quot;Click happened! quot; + str);
});

$(quot;pquot;).dblclick(function(){
  $(quot;spanquot;).text(quot;Double-click happened in quot; + this.tagName);
});


$(quot;pquot;).click();
jQuery: Custom events
$(quot;pquot;).bind(quot;myCustomEventquot;, function(e, myName, myValue){
  $(this).text(myName + quot;, hi there!quot;);
  $(quot;spanquot;).stop().css(quot;opacityquot;, 1)
           .text(quot;myName = quot; + myName)
           .fadeIn(30).fadeOut(1000);
});




$(quot;buttonquot;).click(function () {
  $(quot;pquot;).trigger(quot;myCustomEventquot;, [ quot;Johnquot; ]);
});
jQuery: onload event
$(document).ready(function () {
    $(quot;pquot;).text(quot;The DOM is now loaded and can be manipulated.quot;);
});
jQuery: Ajax transport
$.ajax({
   type: quot;POSTquot;,
   url: quot;some.phpquot;,
   data: quot;name=John&location=Bostonquot;,
   success: function(msg){
     alert( quot;Data Saved: quot; + msg );
   }
 });

$.ajax({
  url: quot;test.htmlquot;,
  cache: false,
  success: function(html){
    $(quot;#resultsquot;).append(html);
  }
});
jQuery: Ajax transport
$.ajax({
	 url:quot;http://api.flickr.com/services/feeds/photos_public.gne?
tags=cat&tagmode=any&format=jsonquot;,
	 dataType:quot;jsonpquot;,
	 jsonp:quot;jsoncallbackquot;,
	 success: function(data){
          //...
	 	 	 	 })
	}
})
jQuery: Effects
show/hide
toggle

slideDown/slideUp
slideToggle

fadeIn/fadeOut
fadeTo

animate
jQuery: Conclusion
• lightweight
• powerful CSS selectors
• ‘less code’ way
• built-in effects and animation
• transport support (including cross-domain)
• a lot of real-life examples
Questions?
Dojo
Dojo: Overview
                 http://dojotoolkit.org
Dojo: Focus
• DOM manipulation
• Animations
• Ajax
• Event and keyboard normalization
• Internationalization (i18n)
• Widgets
Dojo: Package system
Dojo has a package system built-in to load all the code you need,
and is controlled by dojo.require().
This function allows us to pull in parts of the Dojo Toolkit not provided for
in the Base dojo.js, such as Drag and Drop, additional animations, Dijit widgets,
DojoX projects, or even your own code.

dojo.require(quot;dijit.form.Buttonquot;);
dojo.require(quot;dijit.TitlePanequot;);
Dojo: Selectors
dojo.addOnLoad(function(){
	 // our dom is ready, get the node:
	 dojo.query(quot;#testHeadingquot;)
		    // add quot;testClassquot; to its class=quot;quot; attribute
	 	 .addClass(quot;testClassquot;)
		    // and fade it out after 500 ms
	 	 .fadeOut({ delay:500 }).play();
});
Dojo: Event handling
dojo.addOnLoad(function(){
    var node = dojo.byId(quot;testHeadingquot;);
    dojo.connect(node,quot;onclickquot;,function(){
	    node.innerHTML = quot;I've been clickedquot;;     	
    });	
});

dojo.addOnLoad(function(){
     dojo.query(quot;#testHeadingquot;)
	   .style(quot;cursorquot;,quot;pointerquot;)
	   .connect(quot;onclickquot;,function(){
	      this.innerHTML = quot;I've been clickedquot;;
	 });	
});
Dojo: Ajax transport
var init = function(){
	 var contentNode = dojo.byId(quot;contentquot;);
	 dojo.xhrGet({
	 	 url: quot;js/sample.txtquot;,
	 	 handleAs: quot;textquot;,
	 	 load: function(data,args){
	 	 	 // fade out the node we're modifying
	 	 	 dojo.fadeOut({
	 	 	 	 node: contentNode,
	 	 	 	 onEnd: function(){
				          // set the data, fade it back in
				          contentNode.innerHTML = data;
				          dojo.fadeIn({node: contentNode}).play();
				}
	 	 	 }).play();
	 	 },
	 	 // if any error occurs, it goes here:
	 	 error: function(error,args){
	 	 	 console.warn(quot;error!quot;,error);
		}
	 });
};
dojo.addOnLoad(init);
Dojo: Ajax transport
// sumbit the form
var formSubmit = function(e){
	   // prevent the form from actually submitting
	   e.preventDefault();
	   // submit the form in the background	
	   dojo.xhrPost({
	   	   url: quot;alternate-submit.phpquot;,
	   	   form: quot;mainFormquot;,
	   	   handleAs: quot;textquot;,
	   	   handle: function(data,args){
	   	   	   if(typeof data == quot;errorquot;){
	   	   	   	   console.warn(quot;error!quot;,args);
	   	   	   }else{
	   	   	   	   // show our response
	   	   	   	   console.log(data);
	   	   	   }
	   	   }
	   });
};
dojo.addOnLoad(function(){
	   var theForm = dojo.byId(quot;mainFormquot;);
	   // another dojo.connect syntax: call a function directly	
	   dojo.connect(theForm,quot;onsubmitquot;,formSubmit);
});
Dojo: Widgets
First Name:
<input type=quot;textquot; size=quot;20quot; name=quot;firstquot;
dojoType=quot;dijit.form.TextBoxquot;
            trim=quot;truequot; propercase=quot;truequot; />

Price:	 	
<input type=quot;textquot;
    maxlength=quot;12quot;
    class=quot;fillwidth currencyquot;
    id=quot;grossincomequot; name=quot;grossincomequot;
    value=quot;0.00quot;
    dojoType=quot;dijit.form.CurrencyTextBoxquot;
    required=quot;truequot;
    onChange=quot;updateTotals()quot;
    currency=quot;USDquot;/>


dojo.require(quot;dijit.form.TextBoxquot;);
dojo.require(quot;dijit.form.CurrencyTextquot;);
Dojo: Dijit at a Glance

                Border Container          AccordionContainer
  ContentPane                                                      Toolbar

  Slider         ComboBox           CurrencyTextBox       NumberTextBox
                 CheckBox         DateTextBox
 Textarea                                           ValidationTextBox
                FilteringSelect     InlineEditBox
 TimeTextBox                                              TabContainer
                NumberSpinner           StackContainer
                                                            Menu
      Dialog
                Tree   ProgressBar         Editor        Grid
Dojo: DojoX - Dojo eXtensions

   Cometd                             Cryptography
                                                                 Widgets
                  Charting
                                                                               FX
                               Data                 Layout
    Collections
                                                                        Wire
                                        Grid
                             I/O
              Image                                            Timing
  XML Utilities                                 Offline                         GFX
                             String Utilities
                                                             Validate
              UUID
Dojo: Dojo custom build

1. groups together modules into layers
2. interns external non-JavaScript files
3. smooshes the layer down with ShrinkSafe
4. copies all non-layered scripts to the appropriate places
Dojo: Conclusion
• not so lightweight as previous
• tons of features
• separate packages
• custom build
Questions?
qooxdoo
qooxdoo: Overview
                    http://qooxdo.org
qooxdoo: Focus

• One page Rich Internet Applications
• A lot of ideas from Qt
• OOP approach
• No HTML and CSS programming
qooxdoo: The power is in OOP
The main actors of qooxdoo OO are:

• Classes
• Interfaces
• Mixins
qooxdoo: Classes
qx.Class.define(quot;qx.test.Catquot;, {
  construct : function() { ... }
});

qx.Class.define(quot;qx.test.Catquot;, {
  ...
  statics : {
    LEGS: 4,
    makeSound : function() { ... }
  }
});

qx.Class.define(quot;qx.test.Catquot;, {
  ...
  members: {
    name : quot;Kittyquot;,
    getName: function() { return this.name }
  }
});
qooxdoo: Special Types of Classes
qx.Class.define(quot;qx.test.Catquot;, {
  type : quot;staticquot;
  ...
});

qx.Class.define(quot;qx.test.Catquot;, {
  type : quot;abstractquot;
  ...
});

qx.Class.define(quot;qx.test.Catquot;, {
  type : quot;singletonquot;
  ...
});
qooxdoo: Inheritance
qx.Class.define(quot;qx.test.Animalquot;, {
  members: {
    makeSound : function(howManyTimes) {
       ....
    }
  }
});

qx.Class.define(quot;qx.test.Catquot;, {
  extend: qx.test.Animal,
  members: {
    makeSound : function() {
      this.debug(quot;I'm a catquot;);
      /* howManyTimes or any other parameter are passed.   We
don't need to know how many parameters are used. */
      arguments.callee.base.apply(this, arguments);
    }
  }
});
qooxdoo: Interfaces
Defining interface:
qx.Interface.define(quot;qx.test.ISamplequot;,
 {
   extend: [SuperInterfaces],

      properties: {quot;colorquot;: {}, quot;namequot;: {} },

      members:
      {
         meth1: function() { return true; },
         meth2: function(a, b) { return arguments.length == 2; },
         meth3: function(c) { return qx.Class.hasInterface(c.constructor, qx.some.IInterface); }
      },

      statics:
      {
         PI : 3.14,
         staticMethod: function(z) { return typeof z == quot;stringquot;; }
      },

});
qooxdoo: Interfaces
Implementing interface:
qx.Class.define(quot;qx.test.Samplequot;,
 {
   implement: [qx.test.ISample],

      properties: {
         quot;colorquot;: { check: quot;colorquot;},
         quot;namequot;: { check: quot;Stringquot;}
      },

      members:
      {
        meth1: function() { return 42; },
        meth2: function(a, b) { return a+b },
        meth3: function(c) { c.foo() }
      }
});
qooxdoo: Mixins
Defining mixin:
qx.Mixin.define(quot;namequot;,
{
  include: [SuperMixins],

  properties: {
     quot;tabIndexquot;: {check: quot;Numberquot;, init: -1}
  },

  members:
  {
    prop1: quot;fooquot;,
    meth1: function() {},
    meth2: function() {}
  }
});
qooxdoo: Mixins
Attaching mixin:
qx.Class.define(quot;my.cool.Classquot;,
{
  include : [my.cool.MMixin, my.other.cool.MMixin]
  ...
});


qx.Class.include(qx.ui.core.Widget, qx.MWidgetExtensions);
qooxdoo: Properties
...
properties : {
  width : { check : quot;Numberquot;, apply : quot;applyWidthquot; }
}

members :
{
  applyWidth : function(value) {
    this.setStyleProperty(quot;widthquot;, value + quot;pxquot;);
  }
}
...


widget.addEventListener(quot;changeWidthquot;, function(e) {
  e.getValue().innerHTML = quot;Hello Worldquot;;
});
qooxdoo: GUI
qooxdoo: GUI and even more features
• Layouting
• Widgets
• Interaction
• Selection Handling
• Drag & Drop
• Theming
• Low-level Ajax Transport
• RPC
• Logging and Debugging
• Unit testing
qooxdoo: Tooling
Generator:

• Optimization
• Compressing
• Internalization
• API Documentation
• More
XML description for UI - qxtransformer



    http://qxtransformer.org
qooxdoo: Real life example
                      http://gmx.com
Questions?

Contenu connexe

Tendances

Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
Kaniska Mandal
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
旻琦 潘
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
Rebecca Murphey
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 

Tendances (19)

Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Nodejs mongoose
Nodejs mongooseNodejs mongoose
Nodejs mongoose
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
 
Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8Practical JavaScript Programming - Session 1/8
Practical JavaScript Programming - Session 1/8
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
BVJS
BVJSBVJS
BVJS
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
Surviving the Zombie Apocalypse using Custom Post Types and Taxonomies
Surviving the Zombie Apocalypse using Custom Post Types and TaxonomiesSurviving the Zombie Apocalypse using Custom Post Types and Taxonomies
Surviving the Zombie Apocalypse using Custom Post Types and Taxonomies
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 

Similaire à JavaScript Libraries Overview

case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
tidwellveronique
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
MARRY7
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 

Similaire à JavaScript Libraries Overview (20)

Posfix
PosfixPosfix
Posfix
 
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docxcase3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
case3h231diamond.gifcase3h231energy.jpgcase3h231moder.docx
 
dcs plus Catalogue 2015
dcs plus Catalogue 2015dcs plus Catalogue 2015
dcs plus Catalogue 2015
 
Building DSLs With Eclipse
Building DSLs With EclipseBuilding DSLs With Eclipse
Building DSLs With Eclipse
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
"this" in JavaScript
"this" in JavaScript"this" in JavaScript
"this" in JavaScript
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Grain final border one
Grain final border oneGrain final border one
Grain final border one
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
Zend Framework and the Doctrine2 MongoDB ODM (ZF1)
 
Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Beautiful code
Beautiful codeBeautiful code
Beautiful code
 

Plus de Siarhei Barysiuk (6)

Pure css skinning with menu box and menu
Pure css skinning with menu box and menuPure css skinning with menu box and menu
Pure css skinning with menu box and menu
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
JavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best PracticesJavaScript and UI Architecture Best Practices
JavaScript and UI Architecture Best Practices
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
JavaScript Basics And DOM Manipulation
JavaScript Basics And DOM ManipulationJavaScript Basics And DOM Manipulation
JavaScript Basics And DOM Manipulation
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

JavaScript Libraries Overview

  • 1.
  • 2. JavaScript Libraries Overview Siarhei Barysiuk s.barysiuk@sam-solutions.net
  • 4. Libraries: What we will cover today... 5 great open source libraries for your project. • prototype • jQuery • dojo • qooxdoo
  • 5. Libraries: General picture Global picture Lightweight Widgets One-page Applications
  • 7. Prototype: Overview http://prototypejs.org
  • 8. Prototype: Focus • DOM manipulation • Ajax transport • Utility methods for built-in objects • Class-based OOP
  • 9. Prototype: DOM manipulation Say goodbye to getElementById() document.getElementById(quot;idquot;).innerHTML = quot;<li>node</li>quot;; Say hello to $() $(quot;idquot;).innerHTML = quot;<li>node</li>quot;; $(element) extended DOM element
  • 10. Prototype: DOM Element extension * extend * makePositioned * absolutize * select * fire * match * addClassName * setOpacity * firstDescendant * next * addMethods * setStyle * getDimensions * nextSiblings * adjacent * show * getElementsByClassName * observe * ancestors * siblings * getElementsBySelector * positionedOffset * childElements * stopObserving * getHeight * previous * classNames * toggle * getOffsetParent * previousSiblings * cleanWhitespace * toggleClassName * getStyle * readAttribute * clonePosition * undoClipping * getWidth * recursivelyCollect * cumulativeOffset * undoPositioned * hasClassName * relativize * cumulativeScrollOffset * up * hide * remove * descendantOf * update * identify * removeClassName * descendants * viewportOffset * immediateDescendants * replace * down * visible * insert * scrollTo * empty * wrap * inspect * writeAttribute * makeClipping $('message').addClassName('read').update('I read this message!').setStyle({opacity: 0.5});
  • 11. Prototype: Creating a DOM element The old way: var a = document.createElement('a'); a.setAttribute('class', 'foo'); a.setAttribute('href', '/foo.html'); a.appendChild(document.createTextNode(quot;Next pagequot;)); The new way: var a = new Element('a', { 'class': 'foo', href: '/foo.html' }).update(quot;Next pagequot;);
  • 12. Prototype: Even more bucks $((id | element)...) -> [HTMLElement...] $$(cssRule...) -> [HTMLElement...] $A(iterable) -> actualArray $F(element) -> value $H([obj]) -> Hash $R(start, end[, exclusive = false]) -> ObjectRange $w(String) -> Array
  • 13. Prototype: Event handling $('foo').observe('click', respondToClick); function respondToClick(event) { var element = event.element(); element.addClassName('active'); }
  • 14. Prototype: Ajax transport new Ajax.Request('/some_url',{ method:'get', onSuccess: function(transport){ var response = transport.responseText || quot;no response textquot;; alert(quot;Success! nnquot; + response); }, onFailure: function(){ alert('Something went wrong...') } }); Also available are onXXX callbacks, where XXX is the HTTP response status like 200 or 404.
  • 15. Prototype: Ajax transport new Ajax.Request('/some_url', { method: 'get', parameters: {company: 'example', limit: 12} }); new Ajax.Request('/some_url', { parameters: $('id_of_form_element').serialize(true) }); form serialization
  • 16. Prototype: Ajax magic new Ajax.Updater( { success: 'products', 3.1 failure: 'errors' 3.2 }, '/some_url', 1 { method: 'get', 2 insertion: Insertion.Top 4 } );
  • 17. Prototype: Built-in object extensions * all * any * collect var myObject = {}; * detect * each * eachSlice ['foo', 'bar', 'baz'].each(function(name, index) { * entries this[name] = index; * find }, myObject); // we have specified the context * findAll * grep * inGroupsOf myObject * include * inject //-> { foo: 0, bar: 1, baz: 2} * invoke * map * max * member * min * partition * pluck * reject * select * size * sortBy * toArray * zip
  • 18. Prototype: Built-in object extensions * blank * camelize * capitalize * dasherize quot;<h1>hello, i'm HTML</h1>quot;.escapeHTML() * empty * endsWith //-> quot;&lt;h1&gt;hello, i'm HTML&lt;/h1&gt;quot; * escapeHTML * evalJSON * evalScripts 'background-color'.camelize(); // -> 'backgroundColor' * extractScripts * gsub * include 'Prototype framework'.include('frame'); //-> true * inspect 'Prototype framework'.include('frameset');//-> false * interpolate * isJSON * parseQuery * scan quot;echo quot;.times(3); //-> quot;echo echo echo quot; * startsWith * strip * stripScripts quot;#{animals} on a #{transport}quot;.interpolate({ * stripTags animals: quot;Pigsquot;, * sub * succ transport: quot;Surfboardquot; }); * times //-> quot;Pigs on a Surfboardquot; * toArray * toJSON * toQueryParams * truncate * underscore * unescapeHTML * unfilterJSON
  • 19. Prototype: Class-based OOP var Person = Class.create({ initialize: function(name) { this.name = name; }, say: function(message) { return this.name + ': ' + message; } }); var Pirate = Class.create(Person, { // redefine the speak method say: function($super, message) { return $super(message) + ', yarr!'; } }); var john = new Pirate('Long John'); john.say('ahoy matey'); // -> quot;Long John: ahoy matey, yarr!quot;
  • 20. Prototype: Real life example http://gmx.com http://web.de http://gmx.de
  • 21. Prototype: Conclusion • lightweight • good for small projects • a lot of useful methods • transport support • effects with script.aculo.us • good documented • a lot of real project which use prototype
  • 24. jQuery: Overview http://jquery.com
  • 25. jQuery: Focus Motto: Write less, do more. • DOM manipulation • Ajax transport • Effects • Other functionality with plugins
  • 26. jQuery: DOM manipulation Very powerful selectors. $(quot;#myDivquot;).css(quot;borderquot;,quot;3px solid redquot;); $(quot;divquot;).css(quot;borderquot;,quot;3px solid redquot;); $(quot;.myClassquot;).css(quot;borderquot;,quot;3px solid redquot;); $(quot;*quot;).css(quot;borderquot;,quot;3px solid redquot;); $(quot;div,span,p.myClassquot;).css(quot;borderquot;,quot;3px solid redquot;);
  • 27. jQuery: DOM manipulation Even more powerful than you expect. $('li:eq(0)') $('li:even') $('li:lt(3)') $('li:not(.goofy)') $('p a[href*=#]') $('code, li.goofy') $('ol .goofy > strong') $('li + li > a[href$=pdf]') $('span:hidden')
  • 28. jQuery: DOM manipulation Attributes: Text: attr( name ) text( ) attr( properties ) text( val ) attr( key, value ) HTML: attr( key, value ) removeAttr( name ) html( ) Classes: html( val ) addClass( class ) Value: hasClass( class ) removeClass( class ) val( ) toggleClass( class ) val( val )
  • 29. jQuery: DOM manipulation append( content ) appendTo( content ) prepend( content ) prependTo( content ) after( content ) before( content ) insertAfter( content ) insertBefore( content ) wrap( html ) replaceWith( content ) clone( )
  • 30. jQuery: Events Very convenient event handling system. 3 main methods: bind( type, data, fn ) trigger( type, data ) unbind( type, data )
  • 31. jQuery: Binding event handlers $(quot;pquot;).bind(quot;clickquot;, function(e){ var str = quot;( quot; + e.pageX + quot;, quot; + e.pageY + quot; )quot;; $(quot;spanquot;).text(quot;Click happened! quot; + str); }); $(quot;pquot;).bind(quot;dblclickquot;, function(){ $(quot;spanquot;).text(quot;Double-click happened in quot; + this.tagName); }); $(quot;pquot;).bind(quot;mouseenter mouseleavequot;, function(e){ $(this).toggleClass(quot;overquot;); }); $(quot;pquot;).trigger(quot;clickquot;);
  • 32. jQuery: Binding event handlers $(quot;pquot;).click(function(e){ var str = quot;( quot; + e.pageX + quot;, quot; + e.pageY + quot; )quot;; $(quot;spanquot;).text(quot;Click happened! quot; + str); }); $(quot;pquot;).dblclick(function(){ $(quot;spanquot;).text(quot;Double-click happened in quot; + this.tagName); }); $(quot;pquot;).click();
  • 33. jQuery: Custom events $(quot;pquot;).bind(quot;myCustomEventquot;, function(e, myName, myValue){ $(this).text(myName + quot;, hi there!quot;); $(quot;spanquot;).stop().css(quot;opacityquot;, 1) .text(quot;myName = quot; + myName) .fadeIn(30).fadeOut(1000); }); $(quot;buttonquot;).click(function () { $(quot;pquot;).trigger(quot;myCustomEventquot;, [ quot;Johnquot; ]); });
  • 34. jQuery: onload event $(document).ready(function () { $(quot;pquot;).text(quot;The DOM is now loaded and can be manipulated.quot;); });
  • 35. jQuery: Ajax transport $.ajax({ type: quot;POSTquot;, url: quot;some.phpquot;, data: quot;name=John&location=Bostonquot;, success: function(msg){ alert( quot;Data Saved: quot; + msg ); } }); $.ajax({ url: quot;test.htmlquot;, cache: false, success: function(html){ $(quot;#resultsquot;).append(html); } });
  • 36. jQuery: Ajax transport $.ajax({ url:quot;http://api.flickr.com/services/feeds/photos_public.gne? tags=cat&tagmode=any&format=jsonquot;, dataType:quot;jsonpquot;, jsonp:quot;jsoncallbackquot;, success: function(data){ //... }) } })
  • 38. jQuery: Conclusion • lightweight • powerful CSS selectors • ‘less code’ way • built-in effects and animation • transport support (including cross-domain) • a lot of real-life examples
  • 40. Dojo
  • 41. Dojo: Overview http://dojotoolkit.org
  • 42. Dojo: Focus • DOM manipulation • Animations • Ajax • Event and keyboard normalization • Internationalization (i18n) • Widgets
  • 43. Dojo: Package system Dojo has a package system built-in to load all the code you need, and is controlled by dojo.require(). This function allows us to pull in parts of the Dojo Toolkit not provided for in the Base dojo.js, such as Drag and Drop, additional animations, Dijit widgets, DojoX projects, or even your own code. dojo.require(quot;dijit.form.Buttonquot;); dojo.require(quot;dijit.TitlePanequot;);
  • 44. Dojo: Selectors dojo.addOnLoad(function(){ // our dom is ready, get the node: dojo.query(quot;#testHeadingquot;) // add quot;testClassquot; to its class=quot;quot; attribute .addClass(quot;testClassquot;) // and fade it out after 500 ms .fadeOut({ delay:500 }).play(); });
  • 45. Dojo: Event handling dojo.addOnLoad(function(){ var node = dojo.byId(quot;testHeadingquot;); dojo.connect(node,quot;onclickquot;,function(){ node.innerHTML = quot;I've been clickedquot;; }); }); dojo.addOnLoad(function(){ dojo.query(quot;#testHeadingquot;) .style(quot;cursorquot;,quot;pointerquot;) .connect(quot;onclickquot;,function(){ this.innerHTML = quot;I've been clickedquot;; }); });
  • 46. Dojo: Ajax transport var init = function(){ var contentNode = dojo.byId(quot;contentquot;); dojo.xhrGet({ url: quot;js/sample.txtquot;, handleAs: quot;textquot;, load: function(data,args){ // fade out the node we're modifying dojo.fadeOut({ node: contentNode, onEnd: function(){ // set the data, fade it back in contentNode.innerHTML = data; dojo.fadeIn({node: contentNode}).play(); } }).play(); }, // if any error occurs, it goes here: error: function(error,args){ console.warn(quot;error!quot;,error); } }); }; dojo.addOnLoad(init);
  • 47. Dojo: Ajax transport // sumbit the form var formSubmit = function(e){ // prevent the form from actually submitting e.preventDefault(); // submit the form in the background dojo.xhrPost({ url: quot;alternate-submit.phpquot;, form: quot;mainFormquot;, handleAs: quot;textquot;, handle: function(data,args){ if(typeof data == quot;errorquot;){ console.warn(quot;error!quot;,args); }else{ // show our response console.log(data); } } }); }; dojo.addOnLoad(function(){ var theForm = dojo.byId(quot;mainFormquot;); // another dojo.connect syntax: call a function directly dojo.connect(theForm,quot;onsubmitquot;,formSubmit); });
  • 48. Dojo: Widgets First Name: <input type=quot;textquot; size=quot;20quot; name=quot;firstquot; dojoType=quot;dijit.form.TextBoxquot; trim=quot;truequot; propercase=quot;truequot; /> Price: <input type=quot;textquot; maxlength=quot;12quot; class=quot;fillwidth currencyquot; id=quot;grossincomequot; name=quot;grossincomequot; value=quot;0.00quot; dojoType=quot;dijit.form.CurrencyTextBoxquot; required=quot;truequot; onChange=quot;updateTotals()quot; currency=quot;USDquot;/> dojo.require(quot;dijit.form.TextBoxquot;); dojo.require(quot;dijit.form.CurrencyTextquot;);
  • 49. Dojo: Dijit at a Glance Border Container AccordionContainer ContentPane Toolbar Slider ComboBox CurrencyTextBox NumberTextBox CheckBox DateTextBox Textarea ValidationTextBox FilteringSelect InlineEditBox TimeTextBox TabContainer NumberSpinner StackContainer Menu Dialog Tree ProgressBar Editor Grid
  • 50. Dojo: DojoX - Dojo eXtensions Cometd Cryptography Widgets Charting FX Data Layout Collections Wire Grid I/O Image Timing XML Utilities Offline GFX String Utilities Validate UUID
  • 51. Dojo: Dojo custom build 1. groups together modules into layers 2. interns external non-JavaScript files 3. smooshes the layer down with ShrinkSafe 4. copies all non-layered scripts to the appropriate places
  • 52. Dojo: Conclusion • not so lightweight as previous • tons of features • separate packages • custom build
  • 55. qooxdoo: Overview http://qooxdo.org
  • 56. qooxdoo: Focus • One page Rich Internet Applications • A lot of ideas from Qt • OOP approach • No HTML and CSS programming
  • 57. qooxdoo: The power is in OOP The main actors of qooxdoo OO are: • Classes • Interfaces • Mixins
  • 58. qooxdoo: Classes qx.Class.define(quot;qx.test.Catquot;, { construct : function() { ... } }); qx.Class.define(quot;qx.test.Catquot;, { ... statics : { LEGS: 4, makeSound : function() { ... } } }); qx.Class.define(quot;qx.test.Catquot;, { ... members: { name : quot;Kittyquot;, getName: function() { return this.name } } });
  • 59. qooxdoo: Special Types of Classes qx.Class.define(quot;qx.test.Catquot;, { type : quot;staticquot; ... }); qx.Class.define(quot;qx.test.Catquot;, { type : quot;abstractquot; ... }); qx.Class.define(quot;qx.test.Catquot;, { type : quot;singletonquot; ... });
  • 60. qooxdoo: Inheritance qx.Class.define(quot;qx.test.Animalquot;, { members: { makeSound : function(howManyTimes) { .... } } }); qx.Class.define(quot;qx.test.Catquot;, { extend: qx.test.Animal, members: { makeSound : function() { this.debug(quot;I'm a catquot;); /* howManyTimes or any other parameter are passed. We don't need to know how many parameters are used. */ arguments.callee.base.apply(this, arguments); } } });
  • 61. qooxdoo: Interfaces Defining interface: qx.Interface.define(quot;qx.test.ISamplequot;, { extend: [SuperInterfaces], properties: {quot;colorquot;: {}, quot;namequot;: {} }, members: { meth1: function() { return true; }, meth2: function(a, b) { return arguments.length == 2; }, meth3: function(c) { return qx.Class.hasInterface(c.constructor, qx.some.IInterface); } }, statics: { PI : 3.14, staticMethod: function(z) { return typeof z == quot;stringquot;; } }, });
  • 62. qooxdoo: Interfaces Implementing interface: qx.Class.define(quot;qx.test.Samplequot;, { implement: [qx.test.ISample], properties: { quot;colorquot;: { check: quot;colorquot;}, quot;namequot;: { check: quot;Stringquot;} }, members: { meth1: function() { return 42; }, meth2: function(a, b) { return a+b }, meth3: function(c) { c.foo() } } });
  • 63. qooxdoo: Mixins Defining mixin: qx.Mixin.define(quot;namequot;, { include: [SuperMixins], properties: { quot;tabIndexquot;: {check: quot;Numberquot;, init: -1} }, members: { prop1: quot;fooquot;, meth1: function() {}, meth2: function() {} } });
  • 64. qooxdoo: Mixins Attaching mixin: qx.Class.define(quot;my.cool.Classquot;, { include : [my.cool.MMixin, my.other.cool.MMixin] ... }); qx.Class.include(qx.ui.core.Widget, qx.MWidgetExtensions);
  • 65. qooxdoo: Properties ... properties : { width : { check : quot;Numberquot;, apply : quot;applyWidthquot; } } members : { applyWidth : function(value) { this.setStyleProperty(quot;widthquot;, value + quot;pxquot;); } } ... widget.addEventListener(quot;changeWidthquot;, function(e) { e.getValue().innerHTML = quot;Hello Worldquot;; });
  • 67. qooxdoo: GUI and even more features • Layouting • Widgets • Interaction • Selection Handling • Drag & Drop • Theming • Low-level Ajax Transport • RPC • Logging and Debugging • Unit testing
  • 68. qooxdoo: Tooling Generator: • Optimization • Compressing • Internalization • API Documentation • More XML description for UI - qxtransformer http://qxtransformer.org
  • 69. qooxdoo: Real life example http://gmx.com