Blog

Apr 16

Dojo FAQ: What does Dojo’s parser do?

By on April 16, 2014 9:53 am

DojoFAQ

The Dojo Parser provides the ability to declaratively instantiate widgets within our markup, allowing you to add Dojo widgets to your page in the same way you are accustomed to adding HTML5 widgets and form elements, keeping your JavaScript free of boilerplate instantiation code. It does this by scanning the DOM for nodes containing a data-dojo-type attribute and instantiating widgets in place of those nodes. It can scan the page automatically when parseOnLoad is true in our Dojo configuration, or it can be invoked manually by requiring the dojo/parser module and then calling it’s parse method. The parser is also used by Dijit’s _WidgetsInTemplateMixin so we can declaratively instantiate widgets from within our widget templates.

Apr 11

Extension Events

By on April 11, 2014 9:41 am

When working in an event-driven environment such as the web, it is important to utilize tools that allow you to create succinct, easy-to-read code that’s extensible and flexible. One great mechanism that Dojo provides is the ability to use extension events.

What Are They?

Extension events are functions that are passed in lieu of an event type to dojo/on. The extension event function should accept a DOM node and an event listener. The function should encapsulate any logic related to the node and invoke the listener when appropriate. The most common case is adding a listener to a native DOM event (click, mouseover, etc.) with custom logic included that determines whether the handler is called or not.

Mar 26

Dojo FAQ: What is the difference between dojo/on and dojo/aspect?

By on March 26, 2014 10:01 am

DojoFAQ

dojo/on and dojo/aspect are two APIs that appear to do similar jobs but actually serve two different purposes. dojo/on is used to setup event listeners for DOM nodes and event-emitting objects. dojo/aspect provides Aspect Oriented Programming facilities so functionality can be run before, after, or around a method call and can even manipulate the input to the original method or the original method’s output.

Mar 5

Dojo FAQ: Why doesn’t Dijit recognize my dgrid instances?

By on March 5, 2014 8:56 am

DojoFAQ

SitePen’s next-generation grid component, dgrid, is designed to be modular and lightweight, allowing you to only load what you need. It has been designed to work well in Dijit-based UIs, but functionality specific to interacting with Dijit is provided in a module that is not loaded by default. Without this module, two common problems often occur:

  • The dijit/registry module will not find dgrid based on its ID
  • The grid will not size correctly when placed inside a layout container widget, such as dijit/layout/BorderContainer
Feb 25

Dojo FAQ: How can I conditionally load AMD modules?

By on February 25, 2014 7:31 pm

DojoFAQ

AMD: Beyond the Basics

If you’ve been using Dojo 1.7+, you know the basic method of loading modules with AMD:

require([
	'dojo/dom',
	'dojo/query'
], function (dom, query) {
	// dojo/dom and dojo/query modules are 
	// loaded and available for use
});

There are times when you may not know the specific modules you want to load during development. There are a few approaches that can be used to determine which modules to load dynamically at run-time.

Feb 18

Dojo Automated Testing Improvements: Updating to Intern

By on February 18, 2014 6:49 am

2013 saw the development, release, and adoption of Intern, SitePen’s modern, standards-based JavaScript testing framework. One of our priorities for 2014 is converting Dojo’s automated tests from DOH to Intern. Although DOH was an advanced testing framework when it was released, the world of web development has seen some important improvements that necessitated the development of a new testing framework:

  • Remote automated multi-platform browser testing from services like Sauce Labs
  • WebDriver, a standard API for controlling web browser behavior, with a cross-browser implementation by Selenium
  • Continuous integration testing for JavaScript with Travis CI
  • Widespread adoption of server-side JavaScript with NodeJS
Feb 13

Creating Dojo Widgets with Inline Templates

By on February 13, 2014 11:58 am

Many Dojo widgets make use of client-side templating for generating the UI. Template HTML files are brought in to the page with dojo/text, parsed and converted to DOM nodes, and placed on the page, allowing our code to make substitutions, instantiate widgets within the template, and hook up events and attach points. However, we may find ourselves dealing with markup generated on the server and delivered on the page that we want to enhance with Dojo. Luckily, it is quite simple to make a custom widget that uses its source node as the template, allowing us to use markup already on the page as the template for our widget.