1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * Javascript helper function for SCORM module.
20 * @copyright 2009 Petr Skoda (http://skodak.org)
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 mod_scorm_launch_next_sco = null;
25 mod_scorm_launch_prev_sco = null;
26 mod_scorm_activate_item = null;
27 mod_scorm_parse_toc_tree = null;
28 scorm_layout_widget = null;
30 window.scorm_current_node = null;
32 function underscore(str) {
33 str = String(str).replace(/.N/g,".");
34 return str.replace(/\./g,"__");
39 M.mod_scorm.init = function(Y, nav_display, navposition_left, navposition_top, hide_toc, collapsetocwinsize, toc_title, window_name, launch_sco, scoes_nav) {
40 var scorm_disable_toc = false;
41 var scorm_hide_nav = true;
42 var scorm_hide_toc = true;
44 if (nav_display !== 0) {
45 scorm_hide_nav = false;
47 scorm_hide_toc = false;
48 } else if (hide_toc == 3) {
49 scorm_disable_toc = true;
52 scoes_nav = Y.JSON.parse(scoes_nav);
53 var scorm_buttons = [];
54 var scorm_bloody_labelclick = false;
57 Y.use('button', 'dd-plugin', 'panel', 'resize', 'gallery-sm-treeview', function(Y) {
59 Y.TreeView.prototype.getNodeByAttribute = function(attribute, value) {
61 domnode = Y.one('a[' + attribute + '="' + value + '"]');
62 if (domnode !== null) {
63 node = scorm_tree_node.getNodeById(domnode.ancestor('li').get('id'));
68 Y.TreeView.prototype.openAll = function () {
69 this.get('container').all('.yui3-treeview-can-have-children').each(function(target) {
70 this.getNodeById(target.get('id')).open();
74 Y.TreeView.prototype.closeAll = function () {
75 this.get('container').all('.yui3-treeview-can-have-children').each(function(target) {
76 this.getNodeById(target.get('id')).close();
80 var scorm_parse_toc_tree = function(srcNode) {
84 textlabel : '> li, > span',
89 srcNode.all(SELECTORS.child).each(function(childNode) {
91 labelNode = childNode.one(SELECTORS.label),
92 textNode = childNode.one(SELECTORS.textlabel),
93 subTreeNode = childNode.one(SELECTORS.subtree);
96 var title = labelNode.getAttribute('title');
97 var scoid = labelNode.getData('scoid');
98 child.label = labelNode.get('outerHTML');
99 // Will be good to change to url instead of title.
100 if (title && title !== '#') {
103 if (typeof scoid !== 'undefined') {
106 } else if (textNode) {
107 // The selector did not find a label node with anchor.
108 child.label = textNode.get('outerHTML');
112 child.children = scorm_parse_toc_tree(subTreeNode);
115 children.push(child);
121 mod_scorm_parse_toc_tree = scorm_parse_toc_tree;
123 var scorm_activate_item = function(node) {
127 // Check if the item is already active, avoid recursive calls.
128 var content = Y.one('#scorm_content');
129 var old = Y.one('#scorm_object');
131 var scorm_active_url = Y.one('#scorm_object').getAttribute('src');
132 var node_full_url = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?' + node.title;
133 if (node_full_url === scorm_active_url) {
136 // Start to unload iframe here
138 content.removeChild(old);
142 // End of - Avoid recursive calls.
144 scorm_current_node = node;
145 if (!scorm_current_node.state.selected) {
146 scorm_current_node.select();
149 scorm_tree_node.closeAll();
150 var url_prefix = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?';
151 var el_old_api = document.getElementById('scormapi123');
153 el_old_api.parentNode.removeChild(el_old_api);
156 var obj = document.createElement('iframe');
157 obj.setAttribute('id', 'scorm_object');
158 obj.setAttribute('type', 'text/html');
159 if (!window_name && node.title != null) {
160 obj.setAttribute('src', url_prefix + node.title);
163 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
165 alert(M.util.get_string('popupsblocked', 'scorm'));
172 var cwidth = scormplayerdata.cwidth;
173 var cheight = scormplayerdata.cheight;
174 var poptions = scormplayerdata.popupoptions;
175 poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
176 scorm_openpopup(M.cfg.wwwroot + "/mod/scorm/loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
179 content.prepend(obj);
182 if (scorm_hide_nav == false) {
183 if (nav_display === 1 && navposition_left > 0 && navposition_top > 0) {
184 Y.one('#scorm_object').addClass(cssclasses.scorm_nav_under_content);
188 scorm_tree_node.openAll();
191 mod_scorm_activate_item = scorm_activate_item;
194 * Enables/disables navigation buttons as needed.
197 var scorm_fixnav = function() {
198 var skipprevnode = scorm_skipprev(scorm_current_node);
199 var prevnode = scorm_prev(scorm_current_node);
200 var skipnextnode = scorm_skipnext(scorm_current_node);
201 var nextnode = scorm_next(scorm_current_node);
202 var upnode = scorm_up(scorm_current_node);
204 scorm_buttons[0].set('disabled', ((skipprevnode === null) ||
205 (typeof(skipprevnode.scoid) === 'undefined') ||
206 (scoes_nav[skipprevnode.scoid].isvisible === "false") ||
207 (skipprevnode.title === null) ||
208 (scoes_nav[launch_sco].hideprevious === 1)));
210 scorm_buttons[1].set('disabled', ((prevnode === null) ||
211 (typeof(prevnode.scoid) === 'undefined') ||
212 (scoes_nav[prevnode.scoid].isvisible === "false") ||
213 (prevnode.title === null) ||
214 (scoes_nav[launch_sco].hideprevious === 1)));
216 scorm_buttons[2].set('disabled', (upnode === null) ||
217 (typeof(upnode.scoid) === 'undefined') ||
218 (scoes_nav[upnode.scoid].isvisible === "false") ||
219 (upnode.title === null));
221 scorm_buttons[3].set('disabled', ((nextnode === null) ||
222 ((nextnode.title === null) && (scoes_nav[launch_sco].flow !== 1)) ||
223 (typeof(nextnode.scoid) === 'undefined') ||
224 (scoes_nav[nextnode.scoid].isvisible === "false") ||
225 (scoes_nav[launch_sco].hidecontinue === 1)));
227 scorm_buttons[4].set('disabled', ((skipnextnode === null) ||
228 (skipnextnode.title === null) ||
229 (typeof(skipnextnode.scoid) === 'undefined') ||
230 (scoes_nav[skipnextnode.scoid].isvisible === "false") ||
231 scoes_nav[launch_sco].hidecontinue === 1));
234 var scorm_toggle_toc = function(windowresize) {
235 var toc = Y.one('#scorm_toc');
236 var scorm_content = Y.one('#scorm_content');
237 var scorm_toc_toggle_btn = Y.one('#scorm_toc_toggle_btn');
238 var toc_disabled = toc.hasClass('disabled');
239 var disabled_by = toc.getAttribute('disabled-by');
240 // Remove width element style from resize handle.
241 toc.setStyle('width', null);
242 scorm_content.setStyle('width', null);
243 if (windowresize === true) {
244 if (disabled_by === 'user') {
247 var body = Y.one('body');
248 if (body.get('winWidth') < collapsetocwinsize) {
249 toc.addClass(cssclasses.disabled)
250 .setAttribute('disabled-by', 'screen-size');
251 scorm_toc_toggle_btn.setHTML('>')
252 .set('title', M.util.get_string('show', 'moodle'));
253 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
254 .addClass(cssclasses.scorm_grid_content_toc_hidden);
255 } else if (body.get('winWidth') > collapsetocwinsize) {
256 toc.removeClass(cssclasses.disabled)
257 .removeAttribute('disabled-by');
258 scorm_toc_toggle_btn.setHTML('<')
259 .set('title', M.util.get_string('hide', 'moodle'));
260 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
261 .addClass(cssclasses.scorm_grid_content_toc_visible);
266 toc.removeClass(cssclasses.disabled)
267 .removeAttribute('disabled-by');
268 scorm_toc_toggle_btn.setHTML('<')
269 .set('title', M.util.get_string('hide', 'moodle'));
270 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
271 .addClass(cssclasses.scorm_grid_content_toc_visible);
273 toc.addClass(cssclasses.disabled)
274 .setAttribute('disabled-by', 'user');
275 scorm_toc_toggle_btn.setHTML('>')
276 .set('title', M.util.get_string('show', 'moodle'));
277 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
278 .addClass(cssclasses.scorm_grid_content_toc_hidden);
282 var scorm_resize_layout = function() {
287 // make sure that the max width of the TOC doesn't go to far
289 var scorm_toc_node = Y.one('#scorm_toc');
290 var maxwidth = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
291 scorm_toc_node.setStyle('maxWidth', (maxwidth - 200));
292 var cwidth = parseInt(scorm_toc_node.getComputedStyle('width'), 10);
293 if (cwidth > (maxwidth - 1)) {
294 scorm_toc_node.setStyle('width', (maxwidth - 50));
297 // Calculate the rough new height from the viewport height.
298 newheight = Y.one('body').get('winHeight') - 5;
299 if (newheight < 600) {
302 Y.one('#scorm_layout').setStyle('height', newheight);
306 // Handle AJAX Request
307 var scorm_ajax_request = function(url, datastring) {
308 var myRequest = NewHttpReq();
309 var result = DoRequest(myRequest, url + datastring);
313 var scorm_up = function(node, update_launch_sco) {
314 if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
315 var parentscoid = scoes_nav[launch_sco].parentscoid;
316 var parent = node.parent;
317 if (parent.title !== scoes_nav[parentscoid].url) {
318 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
319 if (parent === null) {
320 parent = scorm_tree_node.rootNode.children[0];
321 parent.title = scoes_nav[parentscoid].url;
324 if (update_launch_sco) {
325 launch_sco = parentscoid;
332 var scorm_lastchild = function(node) {
333 if (node.children.length) {
334 return scorm_lastchild(node.children[node.children.length - 1]);
340 var scorm_prev = function(node, update_launch_sco) {
341 if (node.previous() && node.previous().children.length &&
342 typeof scoes_nav[launch_sco].prevscoid !== 'undefined') {
343 node = scorm_lastchild(node.previous());
345 var prevscoid = scoes_nav[launch_sco].prevscoid;
346 if (node.title !== scoes_nav[prevscoid].url) {
347 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevscoid].url);
349 node = scorm_tree_node.rootNode.children[0];
350 node.title = scoes_nav[prevscoid].url;
353 if (update_launch_sco) {
354 launch_sco = prevscoid;
361 return scorm_skipprev(node, update_launch_sco);
364 var scorm_skipprev = function(node, update_launch_sco) {
365 if (node.previous() && typeof scoes_nav[launch_sco].prevsibling !== 'undefined') {
366 var prevsibling = scoes_nav[launch_sco].prevsibling;
367 var previous = node.previous();
368 var prevscoid = scoes_nav[launch_sco].prevscoid;
369 if (previous.title !== scoes_nav[prevscoid].url) {
370 previous = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevsibling].url);
371 if (previous === null) {
372 previous = scorm_tree_node.rootNode.children[0];
373 previous.title = scoes_nav[prevsibling].url;
376 if (update_launch_sco) {
377 launch_sco = prevsibling;
380 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
381 var parentscoid = scoes_nav[launch_sco].parentscoid;
382 var parent = node.parent;
383 if (parent.title !== scoes_nav[parentscoid].url) {
384 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
385 if (parent === null) {
386 parent = scorm_tree_node.rootNode.children[0];
387 parent.title = scoes_nav[parentscoid].url;
390 if (update_launch_sco) {
391 launch_sco = parentscoid;
398 var scorm_next = function(node, update_launch_sco) {
399 if (node === false) {
400 return scorm_tree_node.children[0];
402 if (node.children.length && typeof scoes_nav[launch_sco].nextscoid != 'undefined') {
403 node = node.children[0];
404 var nextscoid = scoes_nav[launch_sco].nextscoid;
405 if (node.title !== scoes_nav[nextscoid].url) {
406 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextscoid].url);
408 node = scorm_tree_node.rootNode.children[0];
409 node.title = scoes_nav[nextscoid].url;
412 if (update_launch_sco) {
413 launch_sco = nextscoid;
417 return scorm_skipnext(node, update_launch_sco);
420 var scorm_skipnext = function(node, update_launch_sco) {
421 var next = node.next();
422 if (next && next.title && typeof scoes_nav[launch_sco] !== 'undefined' && typeof scoes_nav[launch_sco].nextsibling !== 'undefined') {
423 var nextsibling = scoes_nav[launch_sco].nextsibling;
424 if (next.title !== scoes_nav[nextsibling].url) {
425 next = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextsibling].url);
427 next = scorm_tree_node.rootNode.children[0];
428 next.title = scoes_nav[nextsibling].url;
431 if (update_launch_sco) {
432 launch_sco = nextsibling;
435 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
436 var parentscoid = scoes_nav[launch_sco].parentscoid;
437 var parent = node.parent;
438 if (parent.title !== scoes_nav[parentscoid].url) {
439 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
440 if (parent === null) {
441 parent = scorm_tree_node.rootNode.children[0];
444 if (update_launch_sco) {
445 launch_sco = parentscoid;
447 return scorm_skipnext(parent, update_launch_sco);
453 var scorm_launch_prev_sco = function() {
455 if (scoes_nav[launch_sco].flow === 1) {
456 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=backward';
457 result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
458 mod_scorm_seq = encodeURIComponent(result);
459 result = Y.JSON.parse (result);
460 if (typeof result.nextactivity.id != undefined) {
461 var node = scorm_prev(scorm_tree_node.getSelectedNodes()[0]);
463 // Avoid use of TreeView for Navigation.
464 node = scorm_tree_node.getSelectedNodes()[0];
466 if (node.title !== scoes_nav[result.nextactivity.id].url) {
467 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
469 node = scorm_tree_node.rootNode.children[0];
470 node.title = scoes_nav[result.nextactivity.id].url;
473 launch_sco = result.nextactivity.id;
474 scorm_activate_item(node);
477 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
480 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
485 var scorm_launch_next_sco = function () {
487 if (scoes_nav[launch_sco].flow === 1) {
488 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=forward';
489 result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
490 mod_scorm_seq = encodeURIComponent(result);
491 result = Y.JSON.parse (result);
492 if (typeof result.nextactivity !== 'undefined' && typeof result.nextactivity.id !== 'undefined') {
493 var node = scorm_next(scorm_tree_node.getSelectedNodes()[0]);
495 // Avoid use of TreeView for Navigation.
496 node = scorm_tree_node.getSelectedNodes()[0];
498 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
500 node = scorm_tree_node.rootNode.children[0];
501 node.title = scoes_nav[result.nextactivity.id].url;
503 launch_sco = result.nextactivity.id;
504 scorm_activate_item(node);
507 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
510 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
514 mod_scorm_launch_prev_sco = scorm_launch_prev_sco;
515 mod_scorm_launch_next_sco = scorm_launch_next_sco;
518 // YUI grid class: use 100% of the available width to show only content, TOC hidden.
519 scorm_grid_content_toc_hidden: 'yui3-u-1',
520 // YUI grid class: use 1/5 of the available width to show TOC.
521 scorm_grid_toc: 'yui3-u-1-5',
522 // YUI grid class: use 1/24 of the available width to show TOC toggle button.
523 scorm_grid_toggle: 'yui3-u-1-24',
524 // YUI grid class: use 3/4 of the available width to show content, TOC visible.
525 scorm_grid_content_toc_visible: 'yui3-u-3-4',
526 // Reduce height of #scorm_object to accomodate nav buttons under content.
527 scorm_nav_under_content: 'scorm_nav_under_content',
531 Y.one('#scorm_toc_title').setHTML(toc_title);
533 if (scorm_disable_toc) {
534 Y.one('#scorm_toc').addClass(cssclasses.disabled);
535 Y.one('#scorm_toc_toggle').addClass(cssclasses.disabled);
536 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_hidden);
538 Y.one('#scorm_toc').addClass(cssclasses.scorm_grid_toc);
539 Y.one('#scorm_toc_toggle').addClass(cssclasses.scorm_grid_toggle);
540 Y.one('#scorm_toc_toggle_btn')
542 .setAttribute('title', M.util.get_string('hide', 'moodle'));
543 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_visible);
544 scorm_toggle_toc(true);
547 // hide the TOC if that is the default
548 if (!scorm_disable_toc) {
549 if (scorm_hide_toc == true) {
550 Y.one('#scorm_toc').addClass(cssclasses.disabled);
551 Y.one('#scorm_toc_toggle_btn')
553 .setAttribute('title', M.util.get_string('show', 'moodle'));
554 Y.one('#scorm_content')
555 .removeClass(cssclasses.scorm_grid_content_toc_visible)
556 .addClass(cssclasses.scorm_grid_content_toc_hidden);
560 // TOC Resize handle.
561 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
562 var scorm_resize_handle = new Y.Resize({
565 defMinWidth: 0.2 * layout_width
568 var toc_source = Y.one('#scorm_tree > ul');
569 var toc = scorm_parse_toc_tree(toc_source);
570 // Empty container after parsing toc.
571 var el = document.getElementById('scorm_tree');
573 var tree = new Y.TreeView({
574 container: '#scorm_tree',
578 scorm_tree_node = tree;
579 // Trigger after instead of on, avoid recursive calls.
580 tree.after('select', function(e) {
582 if (node.title == '' || node.title == null) {
583 return; //this item has no navigation
586 // If item is already active, return; avoid recursive calls.
587 if (obj = Y.one('#scorm_object')) {
588 var scorm_active_url = obj.getAttribute('src');
589 var node_full_url = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?' + node.title;
590 if (node_full_url === scorm_active_url) {
593 } else if(scorm_current_node == node){
597 // Update launch_sco.
598 if (typeof node.scoid !== 'undefined') {
599 launch_sco = node.scoid;
601 scorm_activate_item(node);
602 if (node.children.length) {
603 scorm_bloody_labelclick = true;
606 if (!scorm_disable_toc) {
607 tree.on('close', function(e) {
608 if (scorm_bloody_labelclick) {
609 scorm_bloody_labelclick = false;
613 tree.subscribe('open', function(e) {
614 if (scorm_bloody_labelclick) {
615 scorm_bloody_labelclick = false;
623 // On getting the window, always set the focus on the current item
624 Y.one(Y.config.win).on('focus', function (e) {
625 var current = scorm_tree_node.getSelectedNodes()[0];
626 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
627 if (current.id && !toc_disabled) {
628 Y.one('#' + current.id).focus();
633 if (scorm_hide_nav == false) {
634 // TODO: make some better&accessible buttons.
635 var navbuttonshtml = '<span id="scorm_nav"><button id="nav_skipprev"><<</button> ' +
636 '<button id="nav_prev"><</button> <button id="nav_up">^</button> ' +
637 '<button id="nav_next">></button> <button id="nav_skipnext">>></button></span>';
638 if (nav_display === 1) {
639 Y.one('#scorm_navpanel').setHTML(navbuttonshtml);
641 // Nav panel is floating type.
642 var navposition = null;
643 if (navposition_left < 0 && navposition_top < 0) {
645 navposition = Y.one('#scorm_toc').getXY();
646 navposition[1] += 200;
648 // Set user defined XY.
650 navposition[0] = parseInt(navposition_left, 10);
651 navposition[1] = parseInt(navposition_top, 10);
653 scorm_nav_panel = new Y.Panel({
655 headerContent: M.util.get_string('navigation', 'scorm'),
660 scorm_nav_panel.set('bodyContent', navbuttonshtml);
661 scorm_nav_panel.removeButton('close');
662 scorm_nav_panel.plug(Y.Plugin.Drag, {handles: ['.yui3-widget-hd']});
663 scorm_nav_panel.render();
666 scorm_buttons[0] = new Y.Button({
667 srcNode: '#nav_skipprev',
670 'click' : function(ev) {
671 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
673 'keydown' : function(ev) {
674 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
675 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
680 scorm_buttons[1] = new Y.Button({
681 srcNode: '#nav_prev',
684 'click' : function(ev) {
685 scorm_launch_prev_sco();
687 'keydown' : function(ev) {
688 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
689 scorm_launch_prev_sco();
694 scorm_buttons[2] = new Y.Button({
698 'click' : function(ev) {
699 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
701 'keydown' : function(ev) {
702 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
703 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
708 scorm_buttons[3] = new Y.Button({
709 srcNode: '#nav_next',
712 'click' : function(ev) {
713 scorm_launch_next_sco();
715 'keydown' : function(ev) {
716 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
717 scorm_launch_next_sco();
722 scorm_buttons[4] = new Y.Button({
723 srcNode: '#nav_skipnext',
726 'click' : function(ev) {
727 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
729 'keydown' : function(ev) {
730 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
731 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
738 // finally activate the chosen item
739 var scorm_first_url = null;
740 if (typeof tree.rootNode.children[0] !== 'undefined') {
741 if (tree.rootNode.children[0].title !== scoes_nav[launch_sco].url) {
742 var node = tree.getNodeByAttribute('title', scoes_nav[launch_sco].url);
744 scorm_first_url = node;
747 scorm_first_url = tree.rootNode.children[0];
751 if (scorm_first_url == null) { // This is probably a single sco with no children (AICC Direct uses this).
752 scorm_first_url = tree.rootNode;
754 scorm_first_url.title = scoes_nav[launch_sco].url;
755 scorm_activate_item(scorm_first_url);
758 scorm_resize_layout();
760 // Collapse/expand TOC.
761 Y.one('#scorm_toc_toggle').on('click', scorm_toggle_toc);
762 Y.one('#scorm_toc_toggle').on('key', scorm_toggle_toc, 'down:enter,32');
763 // fix layout if window resized
764 Y.on("windowresize", function() {
765 scorm_resize_layout();
766 var toc_displayed = Y.one('#scorm_toc').getComputedStyle('display') !== 'none';
767 if ((!scorm_disable_toc && !scorm_hide_toc) || toc_displayed) {
768 scorm_toggle_toc(true);
770 // Set 20% as minWidth constrain of TOC.
771 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
772 scorm_resize_handle.set('defMinWidth', 0.2 * layout_width);
774 // On resize drag, change width of scorm_content.
775 scorm_resize_handle.on('resize:resize', function() {
776 var tocwidth = parseInt(Y.one('#scorm_toc').getComputedStyle('width'), 10);
777 var layoutwidth = parseInt(Y.one('#scorm_layout').getStyle('width'), 10);
778 Y.one('#scorm_content').setStyle('width', (layoutwidth - tocwidth - 60));
783 M.mod_scorm.connectPrereqCallback = {
785 success: function(id, o) {
786 if (o.responseText !== undefined) {
789 if (scorm_tree_node && o.responseText) {
790 snode = scorm_tree_node.getSelectedNodes()[0];
793 stitle = snode.title;
795 // All gone with clear, add new root node.
796 scorm_tree_node.clear(scorm_tree_node.createNode());
798 // Make sure the temporary tree element is not there.
799 var el_old_tree = document.getElementById('scormtree123');
801 el_old_tree.parentNode.removeChild(el_old_tree);
803 var el_new_tree = document.createElement('div');
804 var pagecontent = document.getElementById("page-content");
806 pagecontent = document.getElementById("content");
808 el_new_tree.setAttribute('id','scormtree123');
809 el_new_tree.innerHTML = o.responseText;
810 // Make sure it does not show.
811 el_new_tree.style.display = 'none';
812 pagecontent.appendChild(el_new_tree);
813 // Ignore the first level element as this is the title.
814 var startNode = el_new_tree.firstChild.firstChild;
815 if (startNode.tagName == 'LI') {
816 // Go back to the beginning.
817 startNode = el_new_tree;
819 var toc_source = Y.one('#scormtree123 > ul');
820 var toc = mod_scorm_parse_toc_tree(toc_source);
821 scorm_tree_node.appendNode(scorm_tree_node.rootNode, toc);
822 var el = document.getElementById('scormtree123');
823 el.parentNode.removeChild(el);
824 scorm_tree_node.render();
825 scorm_tree_node.openAll();
826 if (stitle !== null) {
827 snode = scorm_tree_node.getNodeByAttribute('title', stitle);
828 // Do not let destroyed node to be selected.
829 if (snode && !snode.state.destroyed) {
831 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
833 if (!snode.state.selected) {
842 failure: function(id, o) {
843 // TODO: do some sort of error handling.