Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fork 3.0 JS improvements

Fork 3.0 JS improvements

With the launch of version 3.0 of Fork CMS, I included some JS improvements. The adjustments made were mostly for consistency and performance reasons. Feel free to contribute at http://github.com/forkcms/forkcms

Thomas Deceuninck

November 22, 2011
Tweet

Other Decks in Programming

Transcript

  1. General code cleanup Old if(!jsFrontend) { var jsFrontend = new

    Object(); } jsFrontend = { // init something like a constructor init: function() { // call functions }, // end eoo: true; } $(document).ready(jsFrontend.init);
  2. General code cleanup New var jsFrontend = { // init

    something like a constructor init: function() { // call functions } } $(jsFrontend.init);
  3. Scope is determined by where a variable is declared, and

    in some cases whether the var keyword is used. Scope Variables
  4. Can be referenced anywhere in the document but must be:

    ‣ Declared outside a function, with or without the var keyword Scope: global Variables
  5. Can be referenced anywhere in the document but must be:

    ‣ Declared outside a function, with or without the var keyword ‣ Declared inside a function, without the var keyword, but only once the function is called Scope: global Variables
  6. Can only be referenced within the function it is declared

    but must be: Scope: local Variables
  7. Can only be referenced within the function it is declared

    but must be: ‣ Declared inside a function, with the var keyword Scope: local Variables
  8. Example 1 Variables var value = 5; // gobal since

    we're in the global scope, outside any function jsFrontend.faq.feedback = { init: function() { // variables var number = 3; // local (we're already inside this anonymous function) result = 100; // global once this function is called var $header = $('#header'); // local (we're already inside this anonymous function) $navigation = $('#navigation'); // global once this function is called // bind click event $header.on('click', function() { var color = 'blue'; // local endResult = 'green'; // global once this function is called var $body = $('body'); // local $frame = $('#frame'); // global once this function is called number++; // this variable is declared outside of this function's scope, // so changes will affect not only this function's scope, // but the declaring function's scope // which means that this variable is "re-used" every time }); } }
  9. ‣ New event API .on() and .off() used for bind,

    live and delegate Changes jQuery 1.7
  10. ‣ New event API: .on() and .off() used for bind,

    live and delegate ‣ Better HTML5 support (footer, header, section, ...) Changes jQuery 1.7
  11. ‣ New event API: .on() and .off() used for bind,

    live and delegate ‣ Better HTML5 support (footer, header, section, ...) ‣ event.layerX and event.layerY Changes jQuery 1.7
  12. ‣ New event API: .on() and .off() used for bind,

    live and delegate ‣ Better HTML5 support (footer, header, section, ...) ‣ event.layerX and event.layerY ‣ $.isNaN() replaced with $.isNumeric() Changes jQuery 1.7
  13. ‣ New event API: .on() and .off() used for bind,

    live and delegate ‣ Better HTML5 support (footer, header, section, ...) ‣ event.layerX and event.layerY ‣ $.isNaN() replaced with $.isNumeric() ‣ $.event.proxy() use $.proxy() instead Changes jQuery 1.7