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 obj.setAttribute('allowfullscreen', 'allowfullscreen');
160 obj.setAttribute('webkitallowfullscreen', 'webkitallowfullscreen');
161 obj.setAttribute('mozallowfullscreen', 'mozallowfullscreen');
162 if (!window_name && node.title != null) {
163 obj.setAttribute('src', url_prefix + node.title);
165 // Attach unload observers to the iframe. The scorm package may be observing these unload events
166 // and trying to save progress when they occur. We need to ensure we use the Beacon API in those
168 if (typeof mod_scorm_monitorForBeaconRequirement !== 'undefined') {
169 mod_scorm_monitorForBeaconRequirement(obj);
172 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
174 alert(M.util.get_string('popupsblocked', 'scorm'));
181 var cwidth = scormplayerdata.cwidth;
182 var cheight = scormplayerdata.cheight;
183 var poptions = scormplayerdata.popupoptions;
184 poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
185 scorm_openpopup(M.cfg.wwwroot + "/mod/scorm/loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
188 content.prepend(obj);
191 if (scorm_hide_nav == false) {
192 if (nav_display === 1 && navposition_left > 0 && navposition_top > 0) {
193 Y.one('#scorm_object').addClass(cssclasses.scorm_nav_under_content);
197 scorm_tree_node.openAll();
200 mod_scorm_activate_item = scorm_activate_item;
203 * Enables/disables navigation buttons as needed.
206 var scorm_fixnav = function() {
207 var skipprevnode = scorm_skipprev(scorm_current_node);
208 var prevnode = scorm_prev(scorm_current_node);
209 var skipnextnode = scorm_skipnext(scorm_current_node);
210 var nextnode = scorm_next(scorm_current_node);
211 var upnode = scorm_up(scorm_current_node);
213 scorm_buttons[0].set('disabled', ((skipprevnode === null) ||
214 (typeof(skipprevnode.scoid) === 'undefined') ||
215 (scoes_nav[skipprevnode.scoid].isvisible === "false") ||
216 (skipprevnode.title === null) ||
217 (scoes_nav[launch_sco].hideprevious === 1)));
219 scorm_buttons[1].set('disabled', ((prevnode === null) ||
220 (typeof(prevnode.scoid) === 'undefined') ||
221 (scoes_nav[prevnode.scoid].isvisible === "false") ||
222 (prevnode.title === null) ||
223 (scoes_nav[launch_sco].hideprevious === 1)));
225 scorm_buttons[2].set('disabled', (upnode === null) ||
226 (typeof(upnode.scoid) === 'undefined') ||
227 (scoes_nav[upnode.scoid].isvisible === "false") ||
228 (upnode.title === null));
230 scorm_buttons[3].set('disabled', ((nextnode === null) ||
231 ((nextnode.title === null) && (scoes_nav[launch_sco].flow !== 1)) ||
232 (typeof(nextnode.scoid) === 'undefined') ||
233 (scoes_nav[nextnode.scoid].isvisible === "false") ||
234 (scoes_nav[launch_sco].hidecontinue === 1)));
236 scorm_buttons[4].set('disabled', ((skipnextnode === null) ||
237 (skipnextnode.title === null) ||
238 (typeof(skipnextnode.scoid) === 'undefined') ||
239 (scoes_nav[skipnextnode.scoid].isvisible === "false") ||
240 scoes_nav[launch_sco].hidecontinue === 1));
243 var scorm_toggle_toc = function(windowresize) {
244 var toc = Y.one('#scorm_toc');
245 var scorm_content = Y.one('#scorm_content');
246 var scorm_toc_toggle_btn = Y.one('#scorm_toc_toggle_btn');
247 var toc_disabled = toc.hasClass('disabled');
248 var disabled_by = toc.getAttribute('disabled-by');
249 // Remove width element style from resize handle.
250 toc.setStyle('width', null);
251 scorm_content.setStyle('width', null);
252 if (windowresize === true) {
253 if (disabled_by === 'user') {
256 var body = Y.one('body');
257 if (body.get('winWidth') < collapsetocwinsize) {
258 toc.addClass(cssclasses.disabled)
259 .setAttribute('disabled-by', 'screen-size');
260 scorm_toc_toggle_btn.setHTML('>')
261 .set('title', M.util.get_string('show', 'moodle'));
262 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
263 .addClass(cssclasses.scorm_grid_content_toc_hidden);
264 } else if (body.get('winWidth') > collapsetocwinsize) {
265 toc.removeClass(cssclasses.disabled)
266 .removeAttribute('disabled-by');
267 scorm_toc_toggle_btn.setHTML('<')
268 .set('title', M.util.get_string('hide', 'moodle'));
269 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
270 .addClass(cssclasses.scorm_grid_content_toc_visible);
275 toc.removeClass(cssclasses.disabled)
276 .removeAttribute('disabled-by');
277 scorm_toc_toggle_btn.setHTML('<')
278 .set('title', M.util.get_string('hide', 'moodle'));
279 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
280 .addClass(cssclasses.scorm_grid_content_toc_visible);
282 toc.addClass(cssclasses.disabled)
283 .setAttribute('disabled-by', 'user');
284 scorm_toc_toggle_btn.setHTML('>')
285 .set('title', M.util.get_string('show', 'moodle'));
286 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
287 .addClass(cssclasses.scorm_grid_content_toc_hidden);
291 var scorm_resize_layout = function() {
296 // make sure that the max width of the TOC doesn't go to far
298 var scorm_toc_node = Y.one('#scorm_toc');
299 var maxwidth = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
300 scorm_toc_node.setStyle('maxWidth', (maxwidth - 200));
301 var cwidth = parseInt(scorm_toc_node.getComputedStyle('width'), 10);
302 if (cwidth > (maxwidth - 1)) {
303 scorm_toc_node.setStyle('width', (maxwidth - 50));
306 // Calculate the rough new height from the viewport height.
307 var newheight = Y.one('body').get('winHeight') - 5
308 - Y.one('#scorm_layout').getY()
309 - window.pageYOffset;
310 if (newheight < 680 || isNaN(newheight)) {
313 Y.one('#scorm_layout').setStyle('height', newheight);
318 * @deprecated as it is now unused.
319 * @param {string} url
320 * @param {string} datastring
321 * @returns {string|*|boolean}
323 var scorm_ajax_request = function(url, datastring) {
324 var myRequest = NewHttpReq();
325 var result = DoRequest(myRequest, url + datastring);
329 var scorm_up = function(node, update_launch_sco) {
330 if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
331 var parentscoid = scoes_nav[launch_sco].parentscoid;
332 var parent = node.parent;
333 if (parent.title !== scoes_nav[parentscoid].url) {
334 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
335 if (parent === null) {
336 parent = scorm_tree_node.rootNode.children[0];
337 parent.title = scoes_nav[parentscoid].url;
340 if (update_launch_sco) {
341 launch_sco = parentscoid;
348 var scorm_lastchild = function(node) {
349 if (node.children.length) {
350 return scorm_lastchild(node.children[node.children.length - 1]);
356 var scorm_prev = function(node, update_launch_sco) {
357 if (node.previous() && node.previous().children.length &&
358 typeof scoes_nav[launch_sco].prevscoid !== 'undefined') {
359 node = scorm_lastchild(node.previous());
361 var prevscoid = scoes_nav[launch_sco].prevscoid;
362 if (node.title !== scoes_nav[prevscoid].url) {
363 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevscoid].url);
365 node = scorm_tree_node.rootNode.children[0];
366 node.title = scoes_nav[prevscoid].url;
369 if (update_launch_sco) {
370 launch_sco = prevscoid;
377 return scorm_skipprev(node, update_launch_sco);
380 var scorm_skipprev = function(node, update_launch_sco) {
381 if (node.previous() && typeof scoes_nav[launch_sco].prevsibling !== 'undefined') {
382 var prevsibling = scoes_nav[launch_sco].prevsibling;
383 var previous = node.previous();
384 var prevscoid = scoes_nav[launch_sco].prevscoid;
385 if (previous.title !== scoes_nav[prevscoid].url) {
386 previous = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevsibling].url);
387 if (previous === null) {
388 previous = scorm_tree_node.rootNode.children[0];
389 previous.title = scoes_nav[prevsibling].url;
392 if (update_launch_sco) {
393 launch_sco = prevsibling;
396 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
397 var parentscoid = scoes_nav[launch_sco].parentscoid;
398 var parent = node.parent;
399 if (parent.title !== scoes_nav[parentscoid].url) {
400 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
401 if (parent === null) {
402 parent = scorm_tree_node.rootNode.children[0];
403 parent.title = scoes_nav[parentscoid].url;
406 if (update_launch_sco) {
407 launch_sco = parentscoid;
414 var scorm_next = function(node, update_launch_sco) {
415 if (node === false) {
416 return scorm_tree_node.children[0];
418 if (node.children.length && typeof scoes_nav[launch_sco].nextscoid != 'undefined') {
419 node = node.children[0];
420 var nextscoid = scoes_nav[launch_sco].nextscoid;
421 if (node.title !== scoes_nav[nextscoid].url) {
422 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextscoid].url);
424 node = scorm_tree_node.rootNode.children[0];
425 node.title = scoes_nav[nextscoid].url;
428 if (update_launch_sco) {
429 launch_sco = nextscoid;
433 return scorm_skipnext(node, update_launch_sco);
436 var scorm_skipnext = function(node, update_launch_sco) {
437 var next = node.next();
438 if (next && next.title && typeof scoes_nav[launch_sco] !== 'undefined' && typeof scoes_nav[launch_sco].nextsibling !== 'undefined') {
439 var nextsibling = scoes_nav[launch_sco].nextsibling;
440 if (next.title !== scoes_nav[nextsibling].url) {
441 next = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextsibling].url);
443 next = scorm_tree_node.rootNode.children[0];
444 next.title = scoes_nav[nextsibling].url;
447 if (update_launch_sco) {
448 launch_sco = nextsibling;
451 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
452 var parentscoid = scoes_nav[launch_sco].parentscoid;
453 var parent = node.parent;
454 if (parent.title !== scoes_nav[parentscoid].url) {
455 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
456 if (parent === null) {
457 parent = scorm_tree_node.rootNode.children[0];
460 if (update_launch_sco) {
461 launch_sco = parentscoid;
463 return scorm_skipnext(parent, update_launch_sco);
469 * Sends a request to the sequencing handler script on the server.
470 * @param {string} datastring
471 * @returns {string|boolean|*}
473 var scorm_dorequest_sequencing = function(datastring) {
474 var myRequest = NewHttpReq();
475 var result = DoRequest(
477 M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?' + datastring,
485 var scorm_launch_prev_sco = function() {
487 if (scoes_nav[launch_sco].flow === 1) {
488 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=backward';
489 result = scorm_dorequest_sequencing(datastring);
491 // Check the scorm_ajax_result, it may be false.
492 if (result === false) {
493 // Either the outcome was a failure, or we are unloading and simply just don't know
494 // what the outcome actually was.
497 result = Y.JSON.parse(result);
500 if (typeof result.nextactivity !== 'undefined' && typeof result.nextactivity.id !== 'undefined') {
501 var node = scorm_prev(scorm_tree_node.getSelectedNodes()[0]);
503 // Avoid use of TreeView for Navigation.
504 node = scorm_tree_node.getSelectedNodes()[0];
506 if (node.title !== scoes_nav[result.nextactivity.id].url) {
507 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
509 node = scorm_tree_node.rootNode.children[0];
510 node.title = scoes_nav[result.nextactivity.id].url;
513 launch_sco = result.nextactivity.id;
514 scorm_activate_item(node);
517 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
520 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
525 var scorm_launch_next_sco = function () {
527 if (scoes_nav[launch_sco].flow === 1) {
528 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=forward';
529 result = scorm_dorequest_sequencing(datastring);
531 // Check the scorm_ajax_result, it may be false.
532 if (result === false) {
533 // Either the outcome was a failure, or we are unloading and simply just don't know
534 // what the outcome actually was.
537 result = Y.JSON.parse(result);
540 if (typeof result.nextactivity !== 'undefined' && typeof result.nextactivity.id !== 'undefined') {
541 var node = scorm_next(scorm_tree_node.getSelectedNodes()[0]);
543 // Avoid use of TreeView for Navigation.
544 node = scorm_tree_node.getSelectedNodes()[0];
546 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
548 node = scorm_tree_node.rootNode.children[0];
549 node.title = scoes_nav[result.nextactivity.id].url;
551 launch_sco = result.nextactivity.id;
552 scorm_activate_item(node);
555 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
558 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
562 mod_scorm_launch_prev_sco = scorm_launch_prev_sco;
563 mod_scorm_launch_next_sco = scorm_launch_next_sco;
566 // YUI grid class: use 100% of the available width to show only content, TOC hidden.
567 scorm_grid_content_toc_hidden: 'yui3-u-1',
568 // YUI grid class: use 1/5 of the available width to show TOC.
569 scorm_grid_toc: 'yui3-u-1-5',
570 // YUI grid class: use 1/24 of the available width to show TOC toggle button.
571 scorm_grid_toggle: 'yui3-u-1-24',
572 // YUI grid class: use 3/4 of the available width to show content, TOC visible.
573 scorm_grid_content_toc_visible: 'yui3-u-3-4',
574 // Reduce height of #scorm_object to accomodate nav buttons under content.
575 scorm_nav_under_content: 'scorm_nav_under_content',
579 Y.one('#scorm_toc_title').setHTML(toc_title);
581 if (scorm_disable_toc) {
582 Y.one('#scorm_toc').addClass(cssclasses.disabled);
583 Y.one('#scorm_toc_toggle').addClass(cssclasses.disabled);
584 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_hidden);
586 Y.one('#scorm_toc').addClass(cssclasses.scorm_grid_toc);
587 Y.one('#scorm_toc_toggle').addClass(cssclasses.scorm_grid_toggle);
588 Y.one('#scorm_toc_toggle_btn')
590 .setAttribute('title', M.util.get_string('hide', 'moodle'));
591 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_visible);
592 scorm_toggle_toc(true);
595 // hide the TOC if that is the default
596 if (!scorm_disable_toc) {
597 if (scorm_hide_toc == true) {
598 Y.one('#scorm_toc').addClass(cssclasses.disabled);
599 Y.one('#scorm_toc_toggle_btn')
601 .setAttribute('title', M.util.get_string('show', 'moodle'));
602 Y.one('#scorm_content')
603 .removeClass(cssclasses.scorm_grid_content_toc_visible)
604 .addClass(cssclasses.scorm_grid_content_toc_hidden);
608 // Basic initialization completed, show the elements.
609 Y.one('#scorm_toc').removeClass('loading');
610 Y.one('#scorm_toc_toggle').removeClass('loading');
612 // TOC Resize handle.
613 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
614 var scorm_resize_handle = new Y.Resize({
617 defMinWidth: 0.2 * layout_width
620 var toc_source = Y.one('#scorm_tree > ul');
621 var toc = scorm_parse_toc_tree(toc_source);
622 // Empty container after parsing toc.
623 var el = document.getElementById('scorm_tree');
625 var tree = new Y.TreeView({
626 container: '#scorm_tree',
630 scorm_tree_node = tree;
631 // Trigger after instead of on, avoid recursive calls.
632 tree.after('select', function(e) {
634 if (node.title == '' || node.title == null) {
635 return; //this item has no navigation
638 // If item is already active, return; avoid recursive calls.
639 if (obj = Y.one('#scorm_object')) {
640 var scorm_active_url = obj.getAttribute('src');
641 var node_full_url = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?' + node.title;
642 if (node_full_url === scorm_active_url) {
645 } else if(scorm_current_node == node){
649 // Update launch_sco.
650 if (typeof node.scoid !== 'undefined') {
651 launch_sco = node.scoid;
653 scorm_activate_item(node);
654 if (node.children.length) {
655 scorm_bloody_labelclick = true;
658 if (!scorm_disable_toc) {
659 tree.on('close', function(e) {
660 if (scorm_bloody_labelclick) {
661 scorm_bloody_labelclick = false;
665 tree.subscribe('open', function(e) {
666 if (scorm_bloody_labelclick) {
667 scorm_bloody_labelclick = false;
675 // On getting the window, always set the focus on the current item
676 Y.one(Y.config.win).on('focus', function (e) {
677 var current = scorm_tree_node.getSelectedNodes()[0];
678 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
679 if (current.id && !toc_disabled) {
680 Y.one('#' + current.id).focus();
685 if (scorm_hide_nav == false) {
686 // TODO: make some better&accessible buttons.
687 var navbuttonshtml = '<span id="scorm_nav"><button id="nav_skipprev"><<</button> ' +
688 '<button id="nav_prev"><</button> <button id="nav_up">^</button> ' +
689 '<button id="nav_next">></button> <button id="nav_skipnext">>></button></span>';
690 if (nav_display === 1) {
691 Y.one('#scorm_navpanel').setHTML(navbuttonshtml);
693 // Nav panel is floating type.
694 var navposition = null;
695 if (navposition_left < 0 && navposition_top < 0) {
697 navposition = Y.one('#scorm_toc').getXY();
698 navposition[1] += 200;
700 // Set user defined XY.
702 navposition[0] = parseInt(navposition_left, 10);
703 navposition[1] = parseInt(navposition_top, 10);
705 scorm_nav_panel = new Y.Panel({
707 headerContent: M.util.get_string('navigation', 'scorm'),
712 scorm_nav_panel.set('bodyContent', navbuttonshtml);
713 scorm_nav_panel.removeButton('close');
714 scorm_nav_panel.plug(Y.Plugin.Drag, {handles: ['.yui3-widget-hd']});
715 scorm_nav_panel.render();
718 scorm_buttons[0] = new Y.Button({
719 srcNode: '#nav_skipprev',
722 'click' : function(ev) {
723 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
725 'keydown' : function(ev) {
726 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
727 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
732 scorm_buttons[1] = new Y.Button({
733 srcNode: '#nav_prev',
736 'click' : function(ev) {
737 scorm_launch_prev_sco();
739 'keydown' : function(ev) {
740 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
741 scorm_launch_prev_sco();
746 scorm_buttons[2] = new Y.Button({
750 'click' : function(ev) {
751 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
753 'keydown' : function(ev) {
754 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
755 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
760 scorm_buttons[3] = new Y.Button({
761 srcNode: '#nav_next',
764 'click' : function(ev) {
765 scorm_launch_next_sco();
767 'keydown' : function(ev) {
768 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
769 scorm_launch_next_sco();
774 scorm_buttons[4] = new Y.Button({
775 srcNode: '#nav_skipnext',
778 'click' : function(ev) {
779 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
781 'keydown' : function(ev) {
782 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
783 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
790 // finally activate the chosen item
791 var scorm_first_url = null;
792 if (typeof tree.rootNode.children[0] !== 'undefined') {
793 if (tree.rootNode.children[0].title !== scoes_nav[launch_sco].url) {
794 var node = tree.getNodeByAttribute('title', scoes_nav[launch_sco].url);
796 scorm_first_url = node;
799 scorm_first_url = tree.rootNode.children[0];
803 if (scorm_first_url == null) { // This is probably a single sco with no children (AICC Direct uses this).
804 scorm_first_url = tree.rootNode;
806 scorm_first_url.title = scoes_nav[launch_sco].url;
807 scorm_activate_item(scorm_first_url);
810 scorm_resize_layout();
812 // Collapse/expand TOC.
813 Y.one('#scorm_toc_toggle').on('click', scorm_toggle_toc);
814 Y.one('#scorm_toc_toggle').on('key', scorm_toggle_toc, 'down:enter,32');
815 // fix layout if window resized
816 Y.on("windowresize", function() {
817 scorm_resize_layout();
818 var toc_displayed = Y.one('#scorm_toc').getComputedStyle('display') !== 'none';
819 if ((!scorm_disable_toc && !scorm_hide_toc) || toc_displayed) {
820 scorm_toggle_toc(true);
822 // Set 20% as minWidth constrain of TOC.
823 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
824 scorm_resize_handle.set('defMinWidth', 0.2 * layout_width);
826 // On resize drag, change width of scorm_content.
827 scorm_resize_handle.on('resize:resize', function() {
828 var tocwidth = parseInt(Y.one('#scorm_toc').getComputedStyle('width'), 10);
829 var layoutwidth = parseInt(Y.one('#scorm_layout').getStyle('width'), 10);
830 Y.one('#scorm_content').setStyle('width', (layoutwidth - tocwidth - 60));
835 M.mod_scorm.connectPrereqCallback = {
837 success: function(id, o) {
838 if (o.responseText !== undefined) {
841 if (scorm_tree_node && o.responseText) {
842 snode = scorm_tree_node.getSelectedNodes()[0];
845 stitle = snode.title;
847 // All gone with clear, add new root node.
848 scorm_tree_node.clear(scorm_tree_node.createNode());
850 // Make sure the temporary tree element is not there.
851 var el_old_tree = document.getElementById('scormtree123');
853 el_old_tree.parentNode.removeChild(el_old_tree);
855 var el_new_tree = document.createElement('div');
856 var pagecontent = document.getElementById("page-content");
858 pagecontent = document.getElementById("content");
860 el_new_tree.setAttribute('id','scormtree123');
861 el_new_tree.innerHTML = o.responseText;
862 // Make sure it does not show.
863 el_new_tree.style.display = 'none';
864 pagecontent.appendChild(el_new_tree);
865 // Ignore the first level element as this is the title.
866 var startNode = el_new_tree.firstChild.firstChild;
867 if (startNode.tagName == 'LI') {
868 // Go back to the beginning.
869 startNode = el_new_tree;
871 var toc_source = Y.one('#scormtree123 > ul');
872 var toc = mod_scorm_parse_toc_tree(toc_source);
873 scorm_tree_node.appendNode(scorm_tree_node.rootNode, toc);
874 var el = document.getElementById('scormtree123');
875 el.parentNode.removeChild(el);
876 scorm_tree_node.render();
877 scorm_tree_node.openAll();
878 if (stitle !== null) {
879 snode = scorm_tree_node.getNodeByAttribute('title', stitle);
880 // Do not let destroyed node to be selected.
881 if (snode && !snode.state.destroyed) {
883 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
885 if (!snode.state.selected) {
894 failure: function(id, o) {
895 // TODO: do some sort of error handling.