2010-07-22 00:48:06 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
2013-02-03 20:00:18 +13:00
|
|
|
* Javascript helper function for SCORM module.
|
2010-07-22 00:48:06 +00:00
|
|
|
*
|
|
|
|
* @package mod-scorm
|
|
|
|
* @copyright 2009 Petr Skoda (http://skodak.org)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
mod_scorm_launch_next_sco = null;
|
|
|
|
mod_scorm_launch_prev_sco = null;
|
2010-08-17 04:03:44 +00:00
|
|
|
mod_scorm_activate_item = null;
|
2013-04-04 21:03:10 +13:00
|
|
|
scorm_layout_widget = null;
|
2010-08-17 04:03:44 +00:00
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
M.mod_scorm = {};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, launch_sco, scoes_nav) {
|
2011-07-13 19:00:33 +12:00
|
|
|
var scorm_disable_toc = false;
|
|
|
|
var scorm_hide_nav = true;
|
|
|
|
var scorm_hide_toc = true;
|
2010-07-22 00:48:06 +00:00
|
|
|
if (hide_toc == 0) {
|
2011-08-12 09:55:13 +12:00
|
|
|
if (hide_nav != 1) {
|
|
|
|
scorm_hide_nav = false;
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_hide_toc = false;
|
2011-07-13 19:00:33 +12:00
|
|
|
} else if (hide_toc == 3) {
|
|
|
|
scorm_disable_toc = true;
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 12:44:24 +01:00
|
|
|
scoes_nav = Y.JSON.parse(scoes_nav);
|
2010-07-22 00:48:06 +00:00
|
|
|
var scorm_current_node;
|
|
|
|
var scorm_buttons = [];
|
|
|
|
var scorm_bloody_labelclick = false;
|
2010-07-23 19:00:40 +00:00
|
|
|
var scorm_nav_panel;
|
2010-07-22 00:48:06 +00:00
|
|
|
|
|
|
|
Y.use('yui2-resize', 'yui2-dragdrop', 'yui2-container', 'yui2-button', 'yui2-layout', 'yui2-treeview', 'yui2-json', 'yui2-event', function(Y) {
|
|
|
|
|
2012-08-06 19:07:20 +02:00
|
|
|
Y.YUI2.widget.TextNode.prototype.getContentHtml = function() {
|
2011-11-04 00:24:59 +13:00
|
|
|
var sb = [];
|
|
|
|
sb[sb.length] = this.href ? '<a' : '<span';
|
2012-08-06 19:07:20 +02:00
|
|
|
sb[sb.length] = ' id="' + Y.YUI2.lang.escapeHTML(this.labelElId) + '"';
|
|
|
|
sb[sb.length] = ' class="' + Y.YUI2.lang.escapeHTML(this.labelStyle) + '"';
|
2011-11-04 00:24:59 +13:00
|
|
|
if (this.href) {
|
2012-08-06 19:07:20 +02:00
|
|
|
sb[sb.length] = ' href="' + Y.YUI2.lang.escapeHTML(this.href) + '"';
|
|
|
|
sb[sb.length] = ' target="' + Y.YUI2.lang.escapeHTML(this.target) + '"';
|
2011-11-04 00:24:59 +13:00
|
|
|
}
|
|
|
|
if (this.title) {
|
2012-08-06 19:07:20 +02:00
|
|
|
sb[sb.length] = ' title="' + Y.YUI2.lang.escapeHTML(this.title) + '"';
|
2011-11-04 00:24:59 +13:00
|
|
|
}
|
|
|
|
sb[sb.length] = ' >';
|
|
|
|
sb[sb.length] = this.label;
|
|
|
|
sb[sb.length] = this.href?'</a>':'</span>';
|
|
|
|
return sb.join("");
|
|
|
|
};
|
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
var scorm_activate_item = function(node) {
|
|
|
|
if (!node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scorm_current_node = node;
|
|
|
|
scorm_current_node.highlight();
|
|
|
|
|
|
|
|
// remove any reference to the old API
|
|
|
|
if (window.API) {
|
|
|
|
window.API = null;
|
|
|
|
}
|
|
|
|
if (window.API_1484_11) {
|
|
|
|
window.API_1484_11 = null;
|
|
|
|
}
|
|
|
|
var url_prefix = M.cfg.wwwroot + '/mod/scorm/loadSCO.php?';
|
|
|
|
var el_old_api = document.getElementById('scormapi123');
|
|
|
|
if (el_old_api) {
|
|
|
|
el_old_api.parentNode.removeChild(el_old_api);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.title) {
|
2012-10-17 11:17:53 +08:00
|
|
|
var el_scorm_api = document.getElementById("external-scormapi");
|
|
|
|
el_scorm_api.parentNode.removeChild(el_scorm_api);
|
2010-07-22 00:48:06 +00:00
|
|
|
el_scorm_api = document.createElement('script');
|
|
|
|
el_scorm_api.setAttribute('id','external-scormapi');
|
|
|
|
el_scorm_api.setAttribute('type','text/javascript');
|
|
|
|
var pel_scorm_api = document.getElementById('scormapi-parent');
|
|
|
|
pel_scorm_api.appendChild(el_scorm_api);
|
2012-05-07 14:32:47 +12:00
|
|
|
var api_url = M.cfg.wwwroot + '/mod/scorm/loaddatamodel.php?' + node.title;
|
2010-07-22 00:48:06 +00:00
|
|
|
document.getElementById('external-scormapi').src = api_url;
|
|
|
|
}
|
2010-09-18 13:32:06 +00:00
|
|
|
|
2012-08-06 19:07:20 +02:00
|
|
|
var content = new Y.YUI2.util.Element('scorm_content');
|
2013-07-17 14:30:22 +12:00
|
|
|
var obj = document.createElement('iframe');
|
|
|
|
obj.setAttribute('id', 'scorm_object');
|
|
|
|
obj.setAttribute('type', 'text/html');
|
|
|
|
if (!window_name && node.title != null) {
|
|
|
|
obj.setAttribute('src', url_prefix + node.title);
|
|
|
|
}
|
|
|
|
if (window_name) {
|
|
|
|
var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
|
|
|
|
if(! mine) {
|
|
|
|
alert(M.str.scorm.popupsblocked);
|
2010-10-20 22:40:09 +00:00
|
|
|
}
|
2013-07-17 14:30:22 +12:00
|
|
|
mine.close()
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
2013-07-17 14:30:22 +12:00
|
|
|
|
2012-08-06 19:07:20 +02:00
|
|
|
var old = Y.YUI2.util.Dom.get('scorm_object');
|
2010-07-22 00:48:06 +00:00
|
|
|
if (old) {
|
2011-06-30 16:55:16 +12:00
|
|
|
if(window_name) {
|
2010-10-20 22:40:09 +00:00
|
|
|
var cwidth = scormplayerdata.cwidth;
|
|
|
|
var cheight = scormplayerdata.cheight;
|
|
|
|
var poptions = scormplayerdata.popupoptions;
|
2011-07-13 13:31:28 +12:00
|
|
|
scorm_openpopup(M.cfg.wwwroot + "/mod/scorm/loadSCO.php?" + node.title, window_name, poptions, cwidth, cheight);
|
2011-06-30 16:55:16 +12:00
|
|
|
} else {
|
|
|
|
content.replaceChild(obj, old);
|
2010-10-20 22:40:09 +00:00
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
} else {
|
|
|
|
content.appendChild(obj);
|
|
|
|
}
|
2010-07-25 21:55:05 +00:00
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_resize_frame();
|
|
|
|
|
2010-07-23 07:03:26 +00:00
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
2013-04-04 21:03:10 +13:00
|
|
|
if (left.expand) {
|
2010-07-23 07:03:26 +00:00
|
|
|
scorm_current_node.focus();
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
if (scorm_hide_nav == false) {
|
|
|
|
scorm_fixnav();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-17 04:03:44 +00:00
|
|
|
mod_scorm_activate_item = scorm_activate_item;
|
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
/**
|
|
|
|
* Enables/disables navigation buttons as needed.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
var scorm_fixnav = function() {
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_buttons[0].set('disabled', (scorm_skipprev(scorm_current_node) == null || scorm_skipprev(scorm_current_node).title == null ||
|
2012-10-15 16:34:39 +08:00
|
|
|
scoes_nav[launch_sco].hideprevious == 1));
|
|
|
|
scorm_buttons[1].set('disabled', (scorm_prev(scorm_current_node) == null || scorm_prev(scorm_current_node).title == null ||
|
|
|
|
scoes_nav[launch_sco].hideprevious == 1));
|
2011-08-15 16:59:30 +12:00
|
|
|
scorm_buttons[2].set('disabled', (scorm_up(scorm_current_node) == null) || scorm_up(scorm_current_node).title == null);
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_buttons[3].set('disabled', (((scorm_next(scorm_current_node) == null || scorm_next(scorm_current_node).title == null) &&
|
|
|
|
(scoes_nav[launch_sco].flow != 1)) || (scoes_nav[launch_sco].hidecontinue == 1)));
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_buttons[4].set('disabled', (scorm_skipnext(scorm_current_node) == null || scorm_skipnext(scorm_current_node).title == null ||
|
2012-10-15 16:34:39 +08:00
|
|
|
scoes_nav[launch_sco].hidecontinue == 1));
|
2010-07-22 00:48:06 +00:00
|
|
|
};
|
|
|
|
|
2010-07-25 21:55:05 +00:00
|
|
|
var scorm_resize_parent = function() {
|
|
|
|
// fudge IE7 to redraw the screen
|
|
|
|
parent.resizeBy(-10, -10);
|
|
|
|
parent.resizeBy(10, 10);
|
2012-08-06 19:07:20 +02:00
|
|
|
var ifr = Y.YUI2.util.Dom.get('scorm_object');
|
2010-07-25 21:55:05 +00:00
|
|
|
if (ifr) {
|
|
|
|
ifr.detachEvent("onload", scorm_resize_parent);
|
|
|
|
}
|
2010-09-18 13:32:06 +00:00
|
|
|
};
|
2010-07-22 00:48:06 +00:00
|
|
|
|
|
|
|
var scorm_resize_layout = function(alsowidth) {
|
|
|
|
if (window_name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alsowidth) {
|
|
|
|
scorm_layout_widget.setStyle('width', '');
|
|
|
|
var newwidth = scorm_get_htmlelement_size('content', 'width');
|
|
|
|
}
|
|
|
|
// make sure that the max width of the TOC doesn't go to far
|
2010-07-25 21:55:05 +00:00
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
2012-08-06 19:07:20 +02:00
|
|
|
var maxwidth = parseInt(Y.YUI2.util.Dom.getStyle('scorm_layout', 'width'));
|
2012-01-26 20:41:41 +13:00
|
|
|
left.set('maxWidth', (maxwidth - 50));
|
2010-07-22 00:48:06 +00:00
|
|
|
var cwidth = left.get('width');
|
2012-01-26 20:41:41 +13:00
|
|
|
if (cwidth > (maxwidth - 1)) {
|
|
|
|
left.set('width', (maxwidth - 50));
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 22:57:38 +00:00
|
|
|
scorm_layout_widget.setStyle('height', '100%');
|
2011-08-01 16:26:43 +12:00
|
|
|
var center = scorm_layout_widget.getUnitByPosition('center');
|
|
|
|
center.setStyle('height', '100%');
|
|
|
|
|
|
|
|
// calculate the rough new height
|
2012-08-06 19:07:20 +02:00
|
|
|
newheight = Y.YUI2.util.Dom.getViewportHeight() -5;
|
2011-08-01 16:26:43 +12:00
|
|
|
if (newheight < 600) {
|
|
|
|
newheight = 600;
|
|
|
|
}
|
|
|
|
scorm_layout_widget.set('height', newheight);
|
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_layout_widget.render();
|
|
|
|
scorm_resize_frame();
|
|
|
|
|
2010-07-23 19:00:40 +00:00
|
|
|
if (scorm_nav_panel) {
|
|
|
|
scorm_nav_panel.align('bl', 'bl');
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var scorm_get_htmlelement_size = function(el, prop) {
|
2012-08-06 19:07:20 +02:00
|
|
|
var val = Y.YUI2.util.Dom.getStyle(el, prop);
|
2010-07-22 00:48:06 +00:00
|
|
|
if (val == 'auto') {
|
|
|
|
if (el.get) {
|
|
|
|
el = el.get('element'); // get real HTMLElement from YUI element
|
|
|
|
}
|
2012-08-06 19:07:20 +02:00
|
|
|
val = Y.YUI2.util.Dom.getComputedStyle(Y.YUI2.util.Dom.get(el), prop);
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
return parseInt(val);
|
|
|
|
};
|
|
|
|
|
|
|
|
var scorm_resize_frame = function() {
|
2012-08-06 19:07:20 +02:00
|
|
|
var obj = Y.YUI2.util.Dom.get('scorm_object');
|
2010-07-22 00:48:06 +00:00
|
|
|
if (obj) {
|
|
|
|
var content = scorm_layout_widget.getUnitByPosition('center').get('wrap');
|
|
|
|
// basically trap IE6 and 7
|
2012-08-06 19:07:20 +02:00
|
|
|
if (Y.YUI2.env.ua.ie > 5 && Y.YUI2.env.ua.ie < 8) {
|
2010-07-22 00:48:06 +00:00
|
|
|
if( obj.style.setAttribute ) {
|
|
|
|
obj.style.setAttribute("cssText", 'width: ' +(content.offsetWidth - 6)+'px; height: ' + (content.offsetHeight - 10)+'px;');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
obj.style.setAttribute('width', (content.offsetWidth - 6)+'px', 0);
|
|
|
|
obj.style.setAttribute('height', (content.offsetHeight - 10)+'px', 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-01-26 20:41:41 +13:00
|
|
|
obj.style.width = (content.offsetWidth)+'px';
|
2010-07-22 00:48:06 +00:00
|
|
|
obj.style.height = (content.offsetHeight - 10)+'px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
// Handle AJAX Request
|
|
|
|
var scorm_ajax_request = function(url, datastring) {
|
2012-10-15 16:34:39 +08:00
|
|
|
var myRequest = NewHttpReq();
|
2012-06-21 23:12:34 +05:30
|
|
|
var result = DoRequest(myRequest, url + datastring);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
var scorm_up = function(node, update_launch_sco) {
|
2010-07-22 00:48:06 +00:00
|
|
|
var node = scorm_tree_node.getHighlightedNode();
|
2012-06-21 23:12:34 +05:30
|
|
|
if (node.depth > 0 && typeof scoes_nav[launch_sco].parentscoid != 'undefined') {
|
|
|
|
var parentscoid = scoes_nav[launch_sco].parentscoid;
|
|
|
|
node.parent.title = scoes_nav[parentscoid].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = parentscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
return node.parent;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
var scorm_lastchild = function(node) {
|
|
|
|
if (node.children.length) {
|
|
|
|
return scorm_lastchild(node.children[node.children.length-1]);
|
|
|
|
} else {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
var scorm_prev = function(node, update_launch_sco) {
|
|
|
|
if (node.previousSibling && node.previousSibling.children.length &&
|
|
|
|
typeof scoes_nav[launch_sco].prevscoid != 'undefined') {
|
|
|
|
var node = scorm_lastchild(node.previousSibling);
|
|
|
|
if (node) {
|
2012-10-15 16:34:39 +08:00
|
|
|
var prevscoid = scoes_nav[launch_sco].prevscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
node.title = scoes_nav[prevscoid].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = prevscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
return node;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
2012-06-21 23:12:34 +05:30
|
|
|
return scorm_skipprev(node, update_launch_sco);
|
2010-07-22 00:48:06 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
var scorm_skipprev = function(node, update_launch_sco) {
|
|
|
|
if (node.previousSibling && typeof scoes_nav[launch_sco].prevsibling != 'undefined') {
|
2012-10-15 16:34:39 +08:00
|
|
|
var prevsibling = scoes_nav[launch_sco].prevsibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
node.previousSibling.title = scoes_nav[prevsibling].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = prevsibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
return node.previousSibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
} else if (node.depth > 0 && typeof scoes_nav[launch_sco].parentscoid != 'undefined') {
|
2012-10-15 16:34:39 +08:00
|
|
|
var parentscoid = scoes_nav[launch_sco].parentscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
node.parent.title = scoes_nav[parentscoid].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = parentscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
return node.parent;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
var scorm_next = function(node, update_launch_sco) {
|
2010-07-22 00:48:06 +00:00
|
|
|
if (node === false) {
|
|
|
|
return scorm_tree_node.getRoot().children[0];
|
|
|
|
}
|
2012-06-21 23:12:34 +05:30
|
|
|
if (node.children.length && typeof scoes_nav[launch_sco].nextscoid != 'undefined') {
|
2012-10-15 16:34:39 +08:00
|
|
|
var node = node.children[0];
|
2012-06-21 23:12:34 +05:30
|
|
|
var nextscoid = scoes_nav[launch_sco].nextscoid;
|
|
|
|
node.title = scoes_nav[nextscoid].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = nextscoid;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
return node;
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
2012-06-21 23:12:34 +05:30
|
|
|
return scorm_skipnext(node, update_launch_sco);
|
2010-07-22 00:48:06 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
var scorm_skipnext = function(node, update_launch_sco) {
|
|
|
|
if (node.nextSibling && typeof scoes_nav[launch_sco].nextsibling != 'undefined') {
|
2012-10-15 16:34:39 +08:00
|
|
|
var nextsibling = scoes_nav[launch_sco].nextsibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
node.nextSibling.title = scoes_nav[nextsibling].url;
|
|
|
|
if (update_launch_sco) {
|
2012-10-15 16:34:39 +08:00
|
|
|
launch_sco = nextsibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
return node.nextSibling;
|
2012-06-21 23:12:34 +05:30
|
|
|
} else if (node.depth > 0 && typeof scoes_nav[launch_sco].parentscoid != 'undefined') {
|
2012-10-15 16:34:39 +08:00
|
|
|
var parentscoid = scoes_nav[launch_sco].parentscoid;
|
|
|
|
if (update_launch_sco) {
|
|
|
|
launch_sco = parentscoid;
|
|
|
|
}
|
2012-06-21 23:12:34 +05:30
|
|
|
return scorm_skipnext(node.parent, update_launch_sco);
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2012-10-15 16:34:39 +08:00
|
|
|
// Launch prev sco
|
2012-06-21 23:12:34 +05:30
|
|
|
var scorm_launch_prev_sco = function() {
|
2012-10-15 16:34:39 +08:00
|
|
|
var result = null;
|
|
|
|
if (scoes_nav[launch_sco].flow == 1) {
|
|
|
|
var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=backward';
|
2012-06-21 23:12:34 +05:30
|
|
|
result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
|
|
|
|
mod_scorm_seq = encodeURIComponent(result);
|
2013-04-18 12:44:24 +01:00
|
|
|
result = Y.JSON.parse (result);
|
2012-06-21 23:12:34 +05:30
|
|
|
if (typeof result.nextactivity.id != undefined) {
|
2012-10-15 16:34:39 +08:00
|
|
|
var node = scorm_prev(scorm_tree_node.getHighlightedNode())
|
|
|
|
if (node == null) {
|
|
|
|
// Avoid use of TreeView for Navigation
|
|
|
|
node = scorm_tree_node.getHighlightedNode();
|
|
|
|
}
|
|
|
|
node.title = scoes_nav[result.nextactivity.id].url;
|
|
|
|
launch_sco = result.nextactivity.id;
|
|
|
|
scorm_activate_item(node);
|
|
|
|
scorm_fixnav();
|
2012-06-21 23:12:34 +05:30
|
|
|
} else {
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_activate_item(scorm_prev(scorm_tree_node.getHighlightedNode(), true));
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
} else {
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_activate_item(scorm_prev(scorm_tree_node.getHighlightedNode(), true));
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
};
|
2012-10-15 16:34:39 +08:00
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
// Launch next sco
|
|
|
|
var scorm_launch_next_sco = function () {
|
2012-10-15 16:34:39 +08:00
|
|
|
var result = null;
|
|
|
|
if (scoes_nav[launch_sco].flow == 1) {
|
|
|
|
var datastring = scoes_nav[launch_sco].url + '&function=scorm_seq_flow&request=forward';
|
2012-06-21 23:12:34 +05:30
|
|
|
result = scorm_ajax_request(M.cfg.wwwroot + '/mod/scorm/datamodels/sequencinghandler.php?', datastring);
|
|
|
|
mod_scorm_seq = encodeURIComponent(result);
|
2013-04-18 12:44:24 +01:00
|
|
|
result = Y.JSON.parse (result);
|
2012-06-21 23:12:34 +05:30
|
|
|
if (typeof result.nextactivity.id != undefined) {
|
2012-10-15 16:34:39 +08:00
|
|
|
var node = scorm_next(scorm_tree_node.getHighlightedNode())
|
|
|
|
if (node == null) {
|
|
|
|
// Avoid use of TreeView for Navigation
|
|
|
|
node = scorm_tree_node.getHighlightedNode();
|
|
|
|
}
|
|
|
|
node.title = scoes_nav[result.nextactivity.id].url;
|
|
|
|
launch_sco = result.nextactivity.id;
|
|
|
|
scorm_activate_item(node);
|
|
|
|
scorm_fixnav();
|
2012-06-21 23:12:34 +05:30
|
|
|
} else {
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_activate_item(scorm_next(scorm_tree_node.getHighlightedNode(), true));
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
} else {
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_activate_item(scorm_next(scorm_tree_node.getHighlightedNode(), true));
|
2012-06-21 23:12:34 +05:30
|
|
|
}
|
|
|
|
};
|
2012-10-15 16:34:39 +08:00
|
|
|
|
2012-06-21 23:12:34 +05:30
|
|
|
mod_scorm_launch_prev_sco = scorm_launch_prev_sco;
|
|
|
|
mod_scorm_launch_next_sco = scorm_launch_next_sco;
|
2010-08-17 04:03:44 +00:00
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
// layout
|
2012-08-06 19:07:20 +02:00
|
|
|
Y.YUI2.widget.LayoutUnit.prototype.STR_COLLAPSE = M.str.moodle.hide;
|
|
|
|
Y.YUI2.widget.LayoutUnit.prototype.STR_EXPAND = M.str.moodle.show;
|
2010-07-22 00:48:06 +00:00
|
|
|
|
2011-07-13 19:00:33 +12:00
|
|
|
if (scorm_disable_toc) {
|
2012-08-06 19:07:20 +02:00
|
|
|
scorm_layout_widget = new Y.YUI2.widget.Layout('scorm_layout', {
|
2011-07-13 19:00:33 +12:00
|
|
|
minWidth: 255,
|
|
|
|
minHeight: 600,
|
|
|
|
units: [
|
|
|
|
{ position: 'left', body: 'scorm_toc', header: toc_title, width: 0, resize: true, gutter: '0px 0px 0px 0px', collapse: false},
|
|
|
|
{ position: 'center', body: '<div id="scorm_content"></div>', gutter: '0px 0px 0px 0px', scroll: true}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
} else {
|
2012-08-06 19:07:20 +02:00
|
|
|
scorm_layout_widget = new Y.YUI2.widget.Layout('scorm_layout', {
|
2011-07-13 19:00:33 +12:00
|
|
|
minWidth: 255,
|
|
|
|
minHeight: 600,
|
|
|
|
units: [
|
|
|
|
{ position: 'left', body: 'scorm_toc', header: toc_title, width: 250, resize: true, gutter: '2px 5px 5px 2px', collapse: true, minWidth:250, maxWidth: 590},
|
|
|
|
{ position: 'center', body: '<div id="scorm_content"></div>', gutter: '2px 5px 5px 2px', scroll: true}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_layout_widget.render();
|
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
2011-07-13 19:00:33 +12:00
|
|
|
if (!scorm_disable_toc) {
|
|
|
|
left.on('collapse', function() {
|
|
|
|
scorm_resize_frame();
|
|
|
|
});
|
|
|
|
left.on('expand', function() {
|
|
|
|
scorm_resize_frame();
|
|
|
|
});
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
// ugly resizing hack that works around problems with resizing of iframes and objects
|
|
|
|
left._resize.on('startResize', function() {
|
2012-08-06 19:07:20 +02:00
|
|
|
var obj = Y.YUI2.util.Dom.get('scorm_object');
|
2010-07-22 00:48:06 +00:00
|
|
|
obj.style.display = 'none';
|
|
|
|
});
|
|
|
|
left._resize.on('endResize', function() {
|
2012-08-06 19:07:20 +02:00
|
|
|
var obj = Y.YUI2.util.Dom.get('scorm_object');
|
2010-07-22 00:48:06 +00:00
|
|
|
obj.style.display = 'block';
|
|
|
|
scorm_resize_frame();
|
|
|
|
});
|
|
|
|
|
|
|
|
// hide the TOC if that is the default
|
2011-07-13 19:00:33 +12:00
|
|
|
if (!scorm_disable_toc) {
|
|
|
|
if (scorm_hide_toc == true) {
|
|
|
|
left.collapse();
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
// TOC tree
|
2012-08-06 19:07:20 +02:00
|
|
|
var tree = new Y.YUI2.widget.TreeView('scorm_tree');
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_tree_node = tree;
|
|
|
|
tree.singleNodeHighlight = true;
|
|
|
|
tree.subscribe('labelClick', function(node) {
|
2012-05-11 12:51:39 +12:00
|
|
|
if (node.title == '' || node.title == null) {
|
|
|
|
return; //this item has no navigation
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_activate_item(node);
|
|
|
|
if (node.children.length) {
|
|
|
|
scorm_bloody_labelclick = true;
|
|
|
|
}
|
|
|
|
});
|
2011-07-13 19:00:33 +12:00
|
|
|
if (!scorm_disable_toc) {
|
|
|
|
tree.subscribe('collapse', function(node) {
|
|
|
|
if (scorm_bloody_labelclick) {
|
|
|
|
scorm_bloody_labelclick = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tree.subscribe('expand', function(node) {
|
|
|
|
if (scorm_bloody_labelclick) {
|
|
|
|
scorm_bloody_labelclick = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-07-22 00:48:06 +00:00
|
|
|
tree.expandAll();
|
|
|
|
tree.render();
|
|
|
|
|
2012-10-19 10:02:30 +02:00
|
|
|
// On getting the window, always set the focus on the current item
|
|
|
|
Y.YUI2.util.Event.on(window, 'focus', function (e) {
|
|
|
|
var current = scorm_tree_node.getHighlightedNode();
|
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
|
|
|
if (current && left.expand) {
|
|
|
|
current.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
// navigation
|
|
|
|
if (scorm_hide_nav == false) {
|
2013-04-29 15:23:04 +08:00
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
|
|
|
navposition = Y.YUI2.util.Dom.getXY(left);
|
|
|
|
navposition[1] += 200;
|
|
|
|
scorm_nav_panel = new Y.YUI2.widget.Panel('scorm_navpanel', { visible:true, draggable:true, close:false, xy: navposition,
|
2010-07-22 00:48:06 +00:00
|
|
|
autofillheight: "body"} );
|
2010-07-23 19:00:40 +00:00
|
|
|
scorm_nav_panel.setHeader(M.str.scorm.navigation);
|
2010-09-18 13:32:06 +00:00
|
|
|
|
2010-07-22 00:48:06 +00:00
|
|
|
//TODO: make some better&accessible buttons
|
2010-07-23 19:00:40 +00:00
|
|
|
scorm_nav_panel.setBody('<span id="scorm_nav"><button id="nav_skipprev"><<</button><button id="nav_prev"><</button><button id="nav_up">^</button><button id="nav_next">></button><button id="nav_skipnext">>></button></span>');
|
|
|
|
scorm_nav_panel.render();
|
2012-08-06 19:07:20 +02:00
|
|
|
scorm_buttons[0] = new Y.YUI2.widget.Button('nav_skipprev');
|
|
|
|
scorm_buttons[1] = new Y.YUI2.widget.Button('nav_prev');
|
|
|
|
scorm_buttons[2] = new Y.YUI2.widget.Button('nav_up');
|
|
|
|
scorm_buttons[3] = new Y.YUI2.widget.Button('nav_next');
|
|
|
|
scorm_buttons[4] = new Y.YUI2.widget.Button('nav_skipnext');
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_buttons[0].on('click', function(ev) {
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_activate_item(scorm_skipprev(scorm_tree_node.getHighlightedNode(), true));
|
2010-07-22 00:48:06 +00:00
|
|
|
});
|
|
|
|
scorm_buttons[1].on('click', function(ev) {
|
2012-10-15 16:34:39 +08:00
|
|
|
scorm_launch_prev_sco();
|
2010-07-22 00:48:06 +00:00
|
|
|
});
|
|
|
|
scorm_buttons[2].on('click', function(ev) {
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_activate_item(scorm_up(scorm_tree_node.getHighlightedNode(), true));
|
2010-07-22 00:48:06 +00:00
|
|
|
});
|
|
|
|
scorm_buttons[3].on('click', function(ev) {
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_launch_next_sco();
|
2010-07-22 00:48:06 +00:00
|
|
|
});
|
|
|
|
scorm_buttons[4].on('click', function(ev) {
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_activate_item(scorm_skipnext(scorm_tree_node.getHighlightedNode(), true));
|
2010-07-22 00:48:06 +00:00
|
|
|
});
|
2010-07-23 19:00:40 +00:00
|
|
|
scorm_nav_panel.render();
|
2010-07-22 00:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// finally activate the chosen item
|
2012-10-15 16:34:39 +08:00
|
|
|
var scorm_first_url = tree.getRoot().children[0];
|
2013-01-11 23:45:23 +13:00
|
|
|
if (scorm_first_url == null) { // This is probably a single sco with no children (AICC Direct uses this).
|
|
|
|
scorm_first_url = tree.getRoot();
|
|
|
|
}
|
2012-06-21 23:12:34 +05:30
|
|
|
scorm_first_url.title = scoes_nav[launch_sco].url;
|
2010-07-22 00:48:06 +00:00
|
|
|
scorm_activate_item(scorm_first_url);
|
|
|
|
|
|
|
|
// resizing
|
|
|
|
scorm_resize_layout(false);
|
|
|
|
|
|
|
|
// fix layout if window resized
|
|
|
|
window.onresize = function() {
|
|
|
|
scorm_resize_layout(true);
|
|
|
|
};
|
|
|
|
});
|
2013-02-03 20:00:18 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
M.mod_scorm.connectPrereqCallback = {
|
|
|
|
|
|
|
|
success: function(o) {
|
|
|
|
YUI().use('yui2-treeview', 'yui2-layout', function(Y) {
|
|
|
|
// MDL-29159 The core version of getContentHtml doesn't escape text properly.
|
|
|
|
Y.YUI2.widget.TextNode.prototype.getContentHtml = function() {
|
|
|
|
var sb = [];
|
|
|
|
sb[sb.length] = this.href ? '<a' : '<span';
|
|
|
|
sb[sb.length] = ' id="' + Y.YUI2.lang.escapeHTML(this.labelElId) + '"';
|
|
|
|
sb[sb.length] = ' class="' + Y.YUI2.lang.escapeHTML(this.labelStyle) + '"';
|
|
|
|
if (this.href) {
|
|
|
|
sb[sb.length] = ' href="' + Y.YUI2.lang.escapeHTML(this.href) + '"';
|
|
|
|
sb[sb.length] = ' target="' + Y.YUI2.lang.escapeHTML(this.target) + '"';
|
|
|
|
}
|
|
|
|
if (this.title) {
|
|
|
|
sb[sb.length] = ' title="' + Y.YUI2.lang.escapeHTML(this.title) + '"';
|
|
|
|
}
|
|
|
|
sb[sb.length] = ' >';
|
|
|
|
sb[sb.length] = this.label;
|
|
|
|
sb[sb.length] = this.href?'</a>':'</span>';
|
|
|
|
return sb.join("");
|
|
|
|
};
|
|
|
|
|
|
|
|
if (o.responseText !== undefined) {
|
|
|
|
var tree = new Y.YUI2.widget.TreeView('scorm_tree');
|
|
|
|
if (scorm_tree_node && o.responseText) {
|
|
|
|
var hnode = scorm_tree_node.getHighlightedNode();
|
|
|
|
var hidx = null;
|
|
|
|
if (hnode) {
|
|
|
|
hidx = hnode.index + scorm_tree_node.getNodeCount();
|
|
|
|
}
|
|
|
|
// all gone
|
|
|
|
var root_node = scorm_tree_node.getRoot();
|
|
|
|
while (root_node.children.length > 0) {
|
|
|
|
scorm_tree_node.removeNode(root_node.children[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// make sure the temporary tree element is not there
|
|
|
|
var el_old_tree = document.getElementById('scormtree123');
|
|
|
|
if (el_old_tree) {
|
|
|
|
el_old_tree.parentNode.removeChild(el_old_tree);
|
|
|
|
}
|
|
|
|
var el_new_tree = document.createElement('div');
|
|
|
|
var pagecontent = document.getElementById("page-content");
|
|
|
|
el_new_tree.setAttribute('id','scormtree123');
|
|
|
|
el_new_tree.innerHTML = o.responseText;
|
|
|
|
// make sure it doesnt show
|
|
|
|
el_new_tree.style.display = 'none';
|
|
|
|
pagecontent.appendChild(el_new_tree)
|
|
|
|
// ignore the first level element as this is the title
|
|
|
|
var startNode = el_new_tree.firstChild.firstChild;
|
|
|
|
if (startNode.tagName == 'LI') {
|
|
|
|
// go back to the beginning
|
|
|
|
startNode = el_new_tree;
|
|
|
|
}
|
|
|
|
//var sXML = new XMLSerializer().serializeToString(startNode);
|
|
|
|
scorm_tree_node.buildTreeFromMarkup('scormtree123');
|
|
|
|
var el = document.getElementById('scormtree123');
|
|
|
|
el.parentNode.removeChild(el);
|
|
|
|
scorm_tree_node.expandAll();
|
|
|
|
scorm_tree_node.render();
|
|
|
|
if (hidx != null) {
|
|
|
|
hnode = scorm_tree_node.getNodeByIndex(hidx);
|
|
|
|
if (hnode) {
|
|
|
|
hnode.highlight();
|
|
|
|
var left = scorm_layout_widget.getUnitByPosition('left');
|
2013-04-04 21:03:10 +13:00
|
|
|
if (left.expand) {
|
2013-02-03 20:00:18 +13:00
|
|
|
hnode.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
failure: function(o) {
|
|
|
|
// TODO: do some sort of error handling.
|
|
|
|
}
|
|
|
|
|
2013-04-19 15:20:02 +01:00
|
|
|
};
|