** Changed in: mahara
Milestone: 17.04.0 => 17.10.0
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: Subscription for all Mahara Contributors -- please ask
on #mahara-dev or mahara.org forum before editing or unsubscribing it!
Refactor blocktype JS methods
Status in Mahara:
Currently the PluginBlocktype abstract class has three methods for
a block is loaded:
Called when a block instance is displayed (either on the page in view
mode, or the page in edit mode). Expects to return an array of sub-
arrays where each sub-array has a "file" item, which is the relative
path to a JS file (relative to the blocktype's root), and an optional
"init" item, which is a snippet of code that gets executed once the
"file" library has loaded. (It currently uses jQuery.getScript() to do
$instance): Called when a block instance is displayed (either on the
page in view mode, or the page in edit mode). The code here is
inserted into a <script> tag and placed after all the files loaded via
$instance): Called when a block instance's config modal is displayed.
added a while back to resolve a problem with the older
before the script finished loading, and that would cause errors.
Putting the init code inside of jQuery.getScript()'s success callback
resolves that problem.
But now we have a couple of new problems. The return format of
of sub-arrays as it does). We have this obsolete
use anymore. And, when you're on the page editor screen, adding and
removing blocks dynamically, any JS library files for the block get
called every time you add a block of that type. This is not only
redundant, but also causes bugs when library files aren't namespaced
properly and contain init code that runs each time they're loaded.
What we should probably switch to, is something like this:
is displayed on. When viewing a page in view mode, we can load the
libraries for the blocks on the page; when viewing a page in edit
mode, we can load the libraries for all blocktypes pre-emptively.
for libraries needed in the config modal
Returns a snippet of JS code to run when a block instance is loaded.
(Should be tied into the JS libraries method, so that it only runs
after *all* libraries for this blocktype are loaded.)
$instance): Likewise, but for the config modal
And to make sure that all JS libraries needed by a blocktype are
loaded before the block instance is displayed, we could use the HeadJS
library's "Resource Loading" module, which allows for a JS equivalent
of PHP's "require_once()", callbacks on file loadings, testing whether
a file has been loaded, etc.
To manage notifications about this bug go to:
Mailing list: https://launchpad.net/~mahara-contributors
Post to : email@example.com
Unsubscribe : https://launchpad.net/~mahara-contributors
More help : https://help.launchpad.net/ListHelp