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);
166 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
168 alert(M.util.get_string('popupsblocked', 'scorm'));
175 var cwidth = scormplayerdata.cwidth;
176 var cheight = scormplayerdata.cheight;
177 var poptions = scormplayerdata.popupoptions;
178 poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
179 scorm_openpopup(M.cfg.wwwroot + "/mod/scorm/loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
182 content.prepend(obj);
185 if (scorm_hide_nav == false) {
186 if (nav_display === 1 && navposition_left > 0 && navposition_top > 0) {
187 Y.one('#scorm_object').addClass(cssclasses.scorm_nav_under_content);
191 scorm_tree_node.openAll();
194 mod_scorm_activate_item = scorm_activate_item;
197 * Enables/disables navigation buttons as needed.
200 var scorm_fixnav = function() {
201 var skipprevnode = scorm_skipprev(scorm_current_node);
202 var prevnode = scorm_prev(scorm_current_node);
203 var skipnextnode = scorm_skipnext(scorm_current_node);
204 var nextnode = scorm_next(scorm_current_node);
205 var upnode = scorm_up(scorm_current_node);
207 scorm_buttons[0].set('disabled', ((skipprevnode === null) ||
208 (typeof(skipprevnode.scoid) === 'undefined') ||
209 (scoes_nav[skipprevnode.scoid].isvisible === "false") ||
210 (skipprevnode.title === null) ||
211 (scoes_nav[launch_sco].hideprevious === 1)));
213 scorm_buttons[1].set('disabled', ((prevnode === null) ||
214 (typeof(prevnode.scoid) === 'undefined') ||
215 (scoes_nav[prevnode.scoid].isvisible === "false") ||
216 (prevnode.title === null) ||
217 (scoes_nav[launch_sco].hideprevious === 1)));
219 scorm_buttons[2].set('disabled', (upnode === null) ||
220 (typeof(upnode.scoid) === 'undefined') ||
221 (scoes_nav[upnode.scoid].isvisible === "false") ||
222 (upnode.title === null));
224 scorm_buttons[3].set('disabled', ((nextnode === null) ||
225 ((nextnode.title === null) && (scoes_nav[launch_sco].flow !== 1)) ||
226 (typeof(nextnode.scoid) === 'undefined') ||
227 (scoes_nav[nextnode.scoid].isvisible === "false") ||
228 (scoes_nav[launch_sco].hidecontinue === 1)));
230 scorm_buttons[4].set('disabled', ((skipnextnode === null) ||
231 (skipnextnode.title === null) ||
232 (typeof(skipnextnode.scoid) === 'undefined') ||
233 (scoes_nav[skipnextnode.scoid].isvisible === "false") ||
234 scoes_nav[launch_sco].hidecontinue === 1));
237 var scorm_toggle_toc = function(windowresize) {
238 var toc = Y.one('#scorm_toc');
239 var scorm_content = Y.one('#scorm_content');
240 var scorm_toc_toggle_btn = Y.one('#scorm_toc_toggle_btn');
241 var toc_disabled = toc.hasClass('disabled');
242 var disabled_by = toc.getAttribute('disabled-by');
243 // Remove width element style from resize handle.
244 toc.setStyle('width', null);
245 scorm_content.setStyle('width', null);
246 if (windowresize === true) {
247 if (disabled_by === 'user') {
250 var body = Y.one('body');
251 if (body.get('winWidth') < collapsetocwinsize) {
252 toc.addClass(cssclasses.disabled)
253 .setAttribute('disabled-by', 'screen-size');
254 scorm_toc_toggle_btn.setHTML('>')
255 .set('title', M.util.get_string('show', 'moodle'));
256 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
257 .addClass(cssclasses.scorm_grid_content_toc_hidden);
258 } else if (body.get('winWidth') > collapsetocwinsize) {
259 toc.removeClass(cssclasses.disabled)
260 .removeAttribute('disabled-by');
261 scorm_toc_toggle_btn.setHTML('<')
262 .set('title', M.util.get_string('hide', 'moodle'));
263 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
264 .addClass(cssclasses.scorm_grid_content_toc_visible);
269 toc.removeClass(cssclasses.disabled)
270 .removeAttribute('disabled-by');
271 scorm_toc_toggle_btn.setHTML('<')
272 .set('title', M.util.get_string('hide', 'moodle'));
273 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_hidden)
274 .addClass(cssclasses.scorm_grid_content_toc_visible);
276 toc.addClass(cssclasses.disabled)
277 .setAttribute('disabled-by', 'user');
278 scorm_toc_toggle_btn.setHTML('>')
279 .set('title', M.util.get_string('show', 'moodle'));
280 scorm_content.removeClass(cssclasses.scorm_grid_content_toc_visible)
281 .addClass(cssclasses.scorm_grid_content_toc_hidden);
285 var scorm_resize_layout = function() {
290 // make sure that the max width of the TOC doesn't go to far
292 var scorm_toc_node = Y.one('#scorm_toc');
293 var maxwidth = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
294 scorm_toc_node.setStyle('maxWidth', (maxwidth - 200));
295 var cwidth = parseInt(scorm_toc_node.getComputedStyle('width'), 10);
296 if (cwidth > (maxwidth - 1)) {
297 scorm_toc_node.setStyle('width', (maxwidth - 50));
300 // Calculate the rough new height from the viewport height.
301 var newheight = Y.one('body').get('winHeight') - 5
302 - Y.one('#scorm_layout').getY()
303 - window.pageYOffset;
304 if (newheight < 680 || isNaN(newheight)) {
307 Y.one('#scorm_layout').setStyle('height', newheight);
311 // Handle AJAX Request
312 var scorm_ajax_request = function(url, datastring) {
313 var myRequest = NewHttpReq();
314 var result = DoRequest(myRequest, url + datastring);
318 var scorm_up = function(node, update_launch_sco) {
319 if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
320 var parentscoid = scoes_nav[launch_sco].parentscoid;
321 var parent = node.parent;
322 if (parent.title !== scoes_nav[parentscoid].url) {
323 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
324 if (parent === null) {
325 parent = scorm_tree_node.rootNode.children[0];
326 parent.title = scoes_nav[parentscoid].url;
329 if (update_launch_sco) {
330 launch_sco = parentscoid;
337 var scorm_lastchild = function(node) {
338 if (node.children.length) {
339 return scorm_lastchild(node.children[node.children.length - 1]);
345 var scorm_prev = function(node, update_launch_sco) {
346 if (node.previous() && node.previous().children.length &&
347 typeof scoes_nav[launch_sco].prevscoid !== 'undefined') {
348 node = scorm_lastchild(node.previous());
350 var prevscoid = scoes_nav[launch_sco].prevscoid;
351 if (node.title !== scoes_nav[prevscoid].url) {
352 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevscoid].url);
354 node = scorm_tree_node.rootNode.children[0];
355 node.title = scoes_nav[prevscoid].url;
358 if (update_launch_sco) {
359 launch_sco = prevscoid;
366 return scorm_skipprev(node, update_launch_sco);
369 var scorm_skipprev = function(node, update_launch_sco) {
370 if (node.previous() && typeof scoes_nav[launch_sco].prevsibling !== 'undefined') {
371 var prevsibling = scoes_nav[launch_sco].prevsibling;
372 var previous = node.previous();
373 var prevscoid = scoes_nav[launch_sco].prevscoid;
374 if (previous.title !== scoes_nav[prevscoid].url) {
375 previous = scorm_tree_node.getNodeByAttribute('title', scoes_nav[prevsibling].url);
376 if (previous === null) {
377 previous = scorm_tree_node.rootNode.children[0];
378 previous.title = scoes_nav[prevsibling].url;
381 if (update_launch_sco) {
382 launch_sco = prevsibling;
385 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
386 var parentscoid = scoes_nav[launch_sco].parentscoid;
387 var parent = node.parent;
388 if (parent.title !== scoes_nav[parentscoid].url) {
389 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
390 if (parent === null) {
391 parent = scorm_tree_node.rootNode.children[0];
392 parent.title = scoes_nav[parentscoid].url;
395 if (update_launch_sco) {
396 launch_sco = parentscoid;
403 var scorm_next = function(node, update_launch_sco) {
404 if (node === false) {
405 return scorm_tree_node.children[0];
407 if (node.children.length && typeof scoes_nav[launch_sco].nextscoid != 'undefined') {
408 node = node.children[0];
409 var nextscoid = scoes_nav[launch_sco].nextscoid;
410 if (node.title !== scoes_nav[nextscoid].url) {
411 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextscoid].url);
413 node = scorm_tree_node.rootNode.children[0];
414 node.title = scoes_nav[nextscoid].url;
417 if (update_launch_sco) {
418 launch_sco = nextscoid;
422 return scorm_skipnext(node, update_launch_sco);
425 var scorm_skipnext = function(node, update_launch_sco) {
426 var next = node.next();
427 if (next && next.title && typeof scoes_nav[launch_sco] !== 'undefined' && typeof scoes_nav[launch_sco].nextsibling !== 'undefined') {
428 var nextsibling = scoes_nav[launch_sco].nextsibling;
429 if (next.title !== scoes_nav[nextsibling].url) {
430 next = scorm_tree_node.getNodeByAttribute('title', scoes_nav[nextsibling].url);
432 next = scorm_tree_node.rootNode.children[0];
433 next.title = scoes_nav[nextsibling].url;
436 if (update_launch_sco) {
437 launch_sco = nextsibling;
440 } else if (node.parent && node.parent.parent && typeof scoes_nav[launch_sco].parentscoid !== 'undefined') {
441 var parentscoid = scoes_nav[launch_sco].parentscoid;
442 var parent = node.parent;
443 if (parent.title !== scoes_nav[parentscoid].url) {
444 parent = scorm_tree_node.getNodeByAttribute('title', scoes_nav[parentscoid].url);
445 if (parent === null) {
446 parent = scorm_tree_node.rootNode.children[0];
449 if (update_launch_sco) {
450 launch_sco = parentscoid;
452 return scorm_skipnext(parent, update_launch_sco);
458 var scorm_launch_prev_sco = function() {
460 if (scoes_nav[launch_sco].flow === 1) {
461 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=backward';
462 result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
463 mod_scorm_seq = encodeURIComponent(result);
464 result = Y.JSON.parse (result);
465 if (typeof result.nextactivity.id != undefined) {
466 var node = scorm_prev(scorm_tree_node.getSelectedNodes()[0]);
468 // Avoid use of TreeView for Navigation.
469 node = scorm_tree_node.getSelectedNodes()[0];
471 if (node.title !== scoes_nav[result.nextactivity.id].url) {
472 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
474 node = scorm_tree_node.rootNode.children[0];
475 node.title = scoes_nav[result.nextactivity.id].url;
478 launch_sco = result.nextactivity.id;
479 scorm_activate_item(node);
482 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
485 scorm_activate_item(scorm_prev(scorm_tree_node.getSelectedNodes()[0], true));
490 var scorm_launch_next_sco = function () {
492 if (scoes_nav[launch_sco].flow === 1) {
493 var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=forward';
494 result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
495 mod_scorm_seq = encodeURIComponent(result);
496 result = Y.JSON.parse (result);
497 if (typeof result.nextactivity !== 'undefined' && typeof result.nextactivity.id !== 'undefined') {
498 var node = scorm_next(scorm_tree_node.getSelectedNodes()[0]);
500 // Avoid use of TreeView for Navigation.
501 node = scorm_tree_node.getSelectedNodes()[0];
503 node = scorm_tree_node.getNodeByAttribute('title', scoes_nav[result.nextactivity.id].url);
505 node = scorm_tree_node.rootNode.children[0];
506 node.title = scoes_nav[result.nextactivity.id].url;
508 launch_sco = result.nextactivity.id;
509 scorm_activate_item(node);
512 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
515 scorm_activate_item(scorm_next(scorm_tree_node.getSelectedNodes()[0], true));
519 mod_scorm_launch_prev_sco = scorm_launch_prev_sco;
520 mod_scorm_launch_next_sco = scorm_launch_next_sco;
523 // YUI grid class: use 100% of the available width to show only content, TOC hidden.
524 scorm_grid_content_toc_hidden: 'yui3-u-1',
525 // YUI grid class: use 1/5 of the available width to show TOC.
526 scorm_grid_toc: 'yui3-u-1-5',
527 // YUI grid class: use 1/24 of the available width to show TOC toggle button.
528 scorm_grid_toggle: 'yui3-u-1-24',
529 // YUI grid class: use 3/4 of the available width to show content, TOC visible.
530 scorm_grid_content_toc_visible: 'yui3-u-3-4',
531 // Reduce height of #scorm_object to accomodate nav buttons under content.
532 scorm_nav_under_content: 'scorm_nav_under_content',
536 Y.one('#scorm_toc_title').setHTML(toc_title);
538 if (scorm_disable_toc) {
539 Y.one('#scorm_toc').addClass(cssclasses.disabled);
540 Y.one('#scorm_toc_toggle').addClass(cssclasses.disabled);
541 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_hidden);
543 Y.one('#scorm_toc').addClass(cssclasses.scorm_grid_toc);
544 Y.one('#scorm_toc_toggle').addClass(cssclasses.scorm_grid_toggle);
545 Y.one('#scorm_toc_toggle_btn')
547 .setAttribute('title', M.util.get_string('hide', 'moodle'));
548 Y.one('#scorm_content').addClass(cssclasses.scorm_grid_content_toc_visible);
549 scorm_toggle_toc(true);
552 // hide the TOC if that is the default
553 if (!scorm_disable_toc) {
554 if (scorm_hide_toc == true) {
555 Y.one('#scorm_toc').addClass(cssclasses.disabled);
556 Y.one('#scorm_toc_toggle_btn')
558 .setAttribute('title', M.util.get_string('show', 'moodle'));
559 Y.one('#scorm_content')
560 .removeClass(cssclasses.scorm_grid_content_toc_visible)
561 .addClass(cssclasses.scorm_grid_content_toc_hidden);
565 // Basic initialization completed, show the elements.
566 Y.one('#scorm_toc').removeClass('loading');
567 Y.one('#scorm_toc_toggle').removeClass('loading');
569 // TOC Resize handle.
570 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
571 var scorm_resize_handle = new Y.Resize({
574 defMinWidth: 0.2 * layout_width
577 var toc_source = Y.one('#scorm_tree > ul');
578 var toc = scorm_parse_toc_tree(toc_source);
579 // Empty container after parsing toc.
580 var el = document.getElementById('scorm_tree');
582 var tree = new Y.TreeView({
583 container: '#scorm_tree',
587 scorm_tree_node = tree;
588 // Trigger after instead of on, avoid recursive calls.
589 tree.after('select', function(e) {
591 if (node.title == '' || node.title == null) {
592 return; //this item has no navigation
595 // If item is already active, return; avoid recursive calls.
596 if (obj = Y.one('#scorm_object')) {
597 var scorm_active_url = obj.getAttribute('src');
598 var node_full_url = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?' + node.title;
599 if (node_full_url === scorm_active_url) {
602 } else if(scorm_current_node == node){
606 // Update launch_sco.
607 if (typeof node.scoid !== 'undefined') {
608 launch_sco = node.scoid;
610 scorm_activate_item(node);
611 if (node.children.length) {
612 scorm_bloody_labelclick = true;
615 if (!scorm_disable_toc) {
616 tree.on('close', function(e) {
617 if (scorm_bloody_labelclick) {
618 scorm_bloody_labelclick = false;
622 tree.subscribe('open', function(e) {
623 if (scorm_bloody_labelclick) {
624 scorm_bloody_labelclick = false;
632 // On getting the window, always set the focus on the current item
633 Y.one(Y.config.win).on('focus', function (e) {
634 var current = scorm_tree_node.getSelectedNodes()[0];
635 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
636 if (current.id && !toc_disabled) {
637 Y.one('#' + current.id).focus();
642 if (scorm_hide_nav == false) {
643 // TODO: make some better&accessible buttons.
644 var navbuttonshtml = '<span id="scorm_nav"><button id="nav_skipprev"><<</button> ' +
645 '<button id="nav_prev"><</button> <button id="nav_up">^</button> ' +
646 '<button id="nav_next">></button> <button id="nav_skipnext">>></button></span>';
647 if (nav_display === 1) {
648 Y.one('#scorm_navpanel').setHTML(navbuttonshtml);
650 // Nav panel is floating type.
651 var navposition = null;
652 if (navposition_left < 0 && navposition_top < 0) {
654 navposition = Y.one('#scorm_toc').getXY();
655 navposition[1] += 200;
657 // Set user defined XY.
659 navposition[0] = parseInt(navposition_left, 10);
660 navposition[1] = parseInt(navposition_top, 10);
662 scorm_nav_panel = new Y.Panel({
664 headerContent: M.util.get_string('navigation', 'scorm'),
669 scorm_nav_panel.set('bodyContent', navbuttonshtml);
670 scorm_nav_panel.removeButton('close');
671 scorm_nav_panel.plug(Y.Plugin.Drag, {handles: ['.yui3-widget-hd']});
672 scorm_nav_panel.render();
675 scorm_buttons[0] = new Y.Button({
676 srcNode: '#nav_skipprev',
679 'click' : function(ev) {
680 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
682 'keydown' : function(ev) {
683 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
684 scorm_activate_item(scorm_skipprev(scorm_tree_node.getSelectedNodes()[0], true));
689 scorm_buttons[1] = new Y.Button({
690 srcNode: '#nav_prev',
693 'click' : function(ev) {
694 scorm_launch_prev_sco();
696 'keydown' : function(ev) {
697 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
698 scorm_launch_prev_sco();
703 scorm_buttons[2] = new Y.Button({
707 'click' : function(ev) {
708 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
710 'keydown' : function(ev) {
711 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
712 scorm_activate_item(scorm_up(scorm_tree_node.getSelectedNodes()[0], true));
717 scorm_buttons[3] = new Y.Button({
718 srcNode: '#nav_next',
721 'click' : function(ev) {
722 scorm_launch_next_sco();
724 'keydown' : function(ev) {
725 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
726 scorm_launch_next_sco();
731 scorm_buttons[4] = new Y.Button({
732 srcNode: '#nav_skipnext',
735 'click' : function(ev) {
736 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
738 'keydown' : function(ev) {
739 if (ev.domEvent.keyCode === 13 || ev.domEvent.keyCode === 32) {
740 scorm_activate_item(scorm_skipnext(scorm_tree_node.getSelectedNodes()[0], true));
747 // finally activate the chosen item
748 var scorm_first_url = null;
749 if (typeof tree.rootNode.children[0] !== 'undefined') {
750 if (tree.rootNode.children[0].title !== scoes_nav[launch_sco].url) {
751 var node = tree.getNodeByAttribute('title', scoes_nav[launch_sco].url);
753 scorm_first_url = node;
756 scorm_first_url = tree.rootNode.children[0];
760 if (scorm_first_url == null) { // This is probably a single sco with no children (AICC Direct uses this).
761 scorm_first_url = tree.rootNode;
763 scorm_first_url.title = scoes_nav[launch_sco].url;
764 scorm_activate_item(scorm_first_url);
767 scorm_resize_layout();
769 // Collapse/expand TOC.
770 Y.one('#scorm_toc_toggle').on('click', scorm_toggle_toc);
771 Y.one('#scorm_toc_toggle').on('key', scorm_toggle_toc, 'down:enter,32');
772 // fix layout if window resized
773 Y.on("windowresize", function() {
774 scorm_resize_layout();
775 var toc_displayed = Y.one('#scorm_toc').getComputedStyle('display') !== 'none';
776 if ((!scorm_disable_toc && !scorm_hide_toc) || toc_displayed) {
777 scorm_toggle_toc(true);
779 // Set 20% as minWidth constrain of TOC.
780 var layout_width = parseInt(Y.one('#scorm_layout').getComputedStyle('width'), 10);
781 scorm_resize_handle.set('defMinWidth', 0.2 * layout_width);
783 // On resize drag, change width of scorm_content.
784 scorm_resize_handle.on('resize:resize', function() {
785 var tocwidth = parseInt(Y.one('#scorm_toc').getComputedStyle('width'), 10);
786 var layoutwidth = parseInt(Y.one('#scorm_layout').getStyle('width'), 10);
787 Y.one('#scorm_content').setStyle('width', (layoutwidth - tocwidth - 60));
792 M.mod_scorm.connectPrereqCallback = {
794 success: function(id, o) {
795 if (o.responseText !== undefined) {
798 if (scorm_tree_node && o.responseText) {
799 snode = scorm_tree_node.getSelectedNodes()[0];
802 stitle = snode.title;
804 // All gone with clear, add new root node.
805 scorm_tree_node.clear(scorm_tree_node.createNode());
807 // Make sure the temporary tree element is not there.
808 var el_old_tree = document.getElementById('scormtree123');
810 el_old_tree.parentNode.removeChild(el_old_tree);
812 var el_new_tree = document.createElement('div');
813 var pagecontent = document.getElementById("page-content");
815 pagecontent = document.getElementById("content");
817 el_new_tree.setAttribute('id','scormtree123');
818 el_new_tree.innerHTML = o.responseText;
819 // Make sure it does not show.
820 el_new_tree.style.display = 'none';
821 pagecontent.appendChild(el_new_tree);
822 // Ignore the first level element as this is the title.
823 var startNode = el_new_tree.firstChild.firstChild;
824 if (startNode.tagName == 'LI') {
825 // Go back to the beginning.
826 startNode = el_new_tree;
828 var toc_source = Y.one('#scormtree123 > ul');
829 var toc = mod_scorm_parse_toc_tree(toc_source);
830 scorm_tree_node.appendNode(scorm_tree_node.rootNode, toc);
831 var el = document.getElementById('scormtree123');
832 el.parentNode.removeChild(el);
833 scorm_tree_node.render();
834 scorm_tree_node.openAll();
835 if (stitle !== null) {
836 snode = scorm_tree_node.getNodeByAttribute('title', stitle);
837 // Do not let destroyed node to be selected.
838 if (snode && !snode.state.destroyed) {
840 var toc_disabled = Y.one('#scorm_toc').hasClass('disabled');
842 if (!snode.state.selected) {
851 failure: function(id, o) {
852 // TODO: do some sort of error handling.