javascript - Load js plugin using Require.js after Marionette module is rendered -
im new marionette , requirejs. started change old code structure (backbone) marionette. using requirejs changed old list of scripts needed in initial html page requirejs sintax. until fine, scripts loaded in every module ask. example:
define(['app', 'dhcontroller', 'menu', 'gridmenu', 'menubar', 'sidebar', 'aspieprogress'], function(app) { app.module('dh.views', function (views, app, backbone, marionette, $, _) { ....other stuff... //----- requests ----- // dashboard request item view // ------------------- // // display individual request panel views.erequest = marionette.itemview.extend({ tagname: 'div', template: '#template-request', **<-- in template pluging needed** ui: { piechart: '.pie-progress-level' }, onrender: function () { this.ui.piechart.aspieprogress("go", 50); } }); // dashboard request collection view // ------------------- // // display list of requests views.erequests = marionette.collectionview.extend({ tagname: 'ul', childview: views.erequest, initialize: function () { this.render(); }, ui: {} }); });
the problem is: understand page must loaded in order use these plugin (in case jquery-aspieprogress). so, how load scripts files after whole page rendered.. because if use define([..], function(..){}); or require(..). have said, scripts loaded before , don't anything.
hope it's clear. thanks
solution
well guess depends on how structure app. in case, have module typical router logic inside. well, in same file added (at end) function timeout of 100 , required elements need.
var app = require('app'); app.module('crouter', function (crouter, app, backbone, marionette, $, _) { ... router logic ...}); /** * load files needed in template */ settimeout(function() { require(['menu', 'menubar', 'sidebar', 'gridmenu', 'configcolors', 'configtour', 'breakpoint', 'asscrollable'], function() { ... run whatever needs these libs ... } ); }, 100);
you can see , clear example here: http://requirejs.org/docs/api.html#afterload
Comments
Post a Comment