Friday, 23 August 2013

Using requirejs and jquery button

Using requirejs and jquery button

I have a js file which calls jQuery Button on button elements. Like below.
$( ".cancel" ).button({ icons: { primary: "ui-icon-close" } })
$( ".save" ).button({ icons: { primary: "ui-icon-save" } })
etc..
This appears in most of the pages. (some times dynamic pages as well).
Instead of including this in all pages, I am planning to use define module
like
define("mybutton", ['jquery'], function ($) {
return function () {
$( ".cancel" ).button({ icons: { primary: "ui-icon-close" } }) ;
$( ".save" ).button({ icons: { primary: "ui-icon-save" } }) ;
};
});
and each page will have require("mybutton") where ever necessary.
Please let me know whether I am following the correct way of requirejs.
Thanks.

No comments:

Post a Comment