<commit_before>/*
 * SCORM RTE API Management
*/

VISH.SCORM.API = (function(V,$,undefined){

	var init = function(){
		var scorm = new SCORM_API({debug: (V.Utils.getOptions().developping===true), exit_type: 'suspend'});
		var lmsconnected = scorm.initialize();
		scorm.debug("Connected: " + lmsconnected,4);
		// scorm.getvalue('cmi.location');
		// scorm.setvalue('cmi.location', '4');
		// scorm.commit();
		// scorm.terminate();
	};


	/* Base code provided by https://github.com/cybercussion/SCOBot */
	/**
	 * SCORM API
	 * This is a content API, it self-establishes communication with the LMS in SCORM 2004 or 1.2.
	 * Switch statements will convert some SCORM 2004 calls to SCORM 1.2, but you must understand there are limitations
	 * on data storage between versions. Example: Suspend Data 64,000 vs 4096 or Bookmark(location) 1000 vs 255.
	 * Depending on your use, your content may not squeeze into the SCORM 1.2 available space.  Because of this, log messages
	 * will be output so you can monitor your cmi "set" value length.  Ultimately, a LMS may block your request because of this.
	 * This API is meant to simplify common SCORM Tasks, but also offers the ability to use it 'long hand'. Several other
	 * public API's are available online, some free some charge, and this is a best effort to boil it all down.
	 * Documentation, samples, resources, and credits: ADL, <NAME>, Pipwerks, SCORM.com
	 * Goals: SCORM For Everyone else, low overhead, simple API's, containment, and transparency.
	 *
	 * Typical CMI Usage (if used by itself):
	 * var scorm = new SCORM_API({debug: true, exit_type: 'suspend'}),
	 * lmsconnected = scorm.initialize();
	 * scorm.getvalue('cmi.location');
	 * scorm.setvalue('cmi.location', '4');
	 * scorm.commit();
	 * scorm.terminate();
	 *
	 * HTML Event Setup:
	 * If you choose not to use SCOBot tips for onload and onunload, onbeforeunload events you may need to make init, exit methods to do other things
	 * vs. directly referencing the SCORM API here.  Feel free to make those methods if you need to.  'window.top' can be used because
	 * some deployments self occur within a popup in a IFRAME will not fire properly on exit, in some Mozilla browsers.  Last checked, window worked with
	 * JQuery 1.7+ however.  If you have issues trapping the unload event, please try window.top.
	 * $(window).bind('load', YOUR_INITIALIZATION_METHOD);
	 * $(window).bind('unload', YOUR_EXIT_METHOD);
	 *
	 * JSLint was recently changed and its throwing a "use spaces, not tabs" error.  I decided to switch to spaces.
	 * https://github.com/douglascrockford/JSLint/pull/140
	 *
	 * https://github.com/cybercussion/SCOBot
	 * @author <NAME> <<EMAIL>>
	 * @license Copyright (c) 2009-2014, Cybercussion Interactive LLC
	 * As of 3.0.0 this code is under a Creative Commons Attribution-ShareAlike 4.0 International License.
	 * @requires JQuery
	 * @version 3.1.0
	 * @param options {Object} override default values
	 * @constructor
	 */
	/*!
	 * SCORM_API, Updated January 3rd, 2014
	 * Copyright (c) 2009-2013, Cybercussion Interactive LLC.
	 * As of 3.0.0 this code is under a Creative Commons Attribution-ShareAlike 4.0 International License.
	 */
	function SCORM_API(options){
	    // Constructor ////////////
	    "use strict";
	    // Please edit run time options or override them when you instantiate this object.
	    var defaults = {
	            version:           "3.1.0",
	            createDate:        "04/05/2011 08:56AM",
	            modifiedDate:      "01/16/2014 03:57PM",
	            debug:             false,
	            isActive:          false,
	            throw_alerts:      false,
	            prefix:            "SCORM_API",
	            exit_type:         "suspend", // suspend, finish, or "" (undetermined)
	            success_status:    "unknown", // passed, failed, unknown
	            use_standalone:    true,
	            standalone:        false,
	            completion_status: "unknown", // completed, incomplete, unknown
	            time_type:         "GMT",
	            cmi:               null
	        },
	    	// Settings merged with defaults and extended options
	        settings = $.extend(defaults, options),
	    	// Internal API Error Boolean, Error Code object
	        isError = 0,
	        error = {
	            0:   "No Error",
	            404: "Not Found",
	            405: "Prevented on a read only resource"
	        },
	    	// API Object
	        API = {
	            connection: false,
	            version:    "none", // 2004, 1.2 or none
	            mode:       "",
	            path:       false, // Set Path to LMS API or maybe something local later by default?
	            data:       {// Defaults, I'm moving a few of the SCORM defaults into this data object, they will be maintained here thereafter.
	                completion_status: settings.completion_status,
	                success_status:    settings.success_status,
	                exit_type:         settings.exit_type
	            },
	            isActive:   settings.isActive  // If SCO is initialized already, this was added for a page by page concept where pages unload and load.
	        },
	        self = this;
	    // Public to Public call hook within the internal API
	    // Set some more 'settings'
	    settings.error = error; // Inherit
	    settings.startDate = {}; // Set on Success of Initialize aka "the start time"
	    // End Constructor ////////
	    
	    // Private ////////////////
	    /**
	     * No Console
	     * Lack of support in older browsers forced this
	     * @param msg {String} Debug Message
	     * @param lvl {*} 1=Error, 2=Warning, 3=Log, 4=Info
	     * @event debug fired when no console is available.  You could listen to this to put it in an alternative log.
	     */
	    function noconsole(msg,lvl){
	        // ignore (IE 8 and prior or other browser that doesn't support it).  Routing event out so it can be handled.
	        $(self).triggerHandler({
	            'type': "debug",
	            'msg':  msg,
	            'lvl':  lvl
	        });
	    };

	    /**
	     * Debug
	     * Built-In Debug Functionality to output to console (Firebug, Inspector, Dev Tool etc ...)
	     * @param msg {String} Debug Message
	     * @param lvl {Integer} 1=Error, 2=Warning, 3=Log, 4=Info
	     */
	    function debug(msg,lvl){
			// WriteToDebug(msg);

	        if (settings.debug) {// default is false
	            if (!window.console) {// IE 7 probably 6 was throwing a error if 'console undefined'
	                window.console = {};
	                window.console.info = noconsole;
	                window.console.log = noconsole;
	                window.console.warn = noconsole;
	                window.console.error = noconsole;
	                window.console.trace = noconsole;
	            }
	            switch (lvl){
	            case 1:
	                console.error(msg);
	                break;
	            case 2:
	                console.warn(msg);
	                break;
	            case 4:
	                console.info(msg);
	                break;
	            case 3:
	                console.log(msg);
	                break;
	            default:
	                console.log(msg);
	                return false;
	            }
	            return true;
	        }
	        if(lvl < 3 && settings.throw_alerts){
	            alert(msg);
	        }
	        return false;
	    };


	    //Debug in a new window
		//debug info
		var aryDebug = new Array();
		var strDebug = "";
		var winDebug;

		function WriteToDebug(strInfo){
			if (!winDebug || winDebug.closed){
				ShowDebugWindow();
			}

			var strLine;
			strLine = aryDebug.length + ":" + + strInfo;
			aryDebug[aryDebug.length] = strLine;

			if (winDebug && !winDebug.closed){
				winDebug.document.write(strLine + "<br>\n");
			}

			return;
		};

		function ShowDebugWindow(){
			if (winDebug && !winDebug.closed){
				winDebug.close();
			}

			winDebug = window.open("", "Debug", "width=600,height=300,resizable,scrollbars");

			winDebug.document.write(aryDebug.join("<br>\n"));

			winDebug.document.close();

			winDebug.focus();

			return;
		};

	    /**
	     * Find API
	     * API_1484_11 or API for SCORM 2004 or 1.2
	     * @param win {object} Window level
	     */
	    function findAPI(win){
	        var attempts = 0, limit = 500;
	        while ((!win.API && !win.API_1484_11) && (win.parent) && (win.parent !== win) && (attempts <= limit)){
	            attempts += 1;
	            win = win.parent;
	        }
	        if(win.API_1484_11){ //SCORM 2004-specific API.
	            API.version = "2004";
	            //Set version
	            API.path = win.API_1484_11;
	        } else if(win.API){ //SCORM 1.2-specific API
	            API.version = "1.2";
	            //Set version
	            API.path = win.API;
	        } else {
	            return false;
	        }
	        return true;<commit_msg>Enhanced debugger for SCORM API<commit_after>/*
 * SCORM RTE API Management
*/

VISH.SCORM.API = (function(V,$,undefined){

	var init = function(){
		var scorm = new SCORM_API({debug: (V.Utils.getOptions().developping===true), windowDebug: true, exit_type: 'suspend'});
		var lmsconnected = scorm.initialize();
		scorm.debug("Connected: " + lmsconnected,4);
		// scorm.getvalue('cmi.location');
		// scorm.setvalue('cmi.location', '4');
		// scorm.commit();
		// scorm.terminate();
	};


	/* Base code provided by https://github.com/cybercussion/SCOBot */
	/**
	 * SCORM API
	 * This is a content API, it self-establishes communication with the LMS in SCORM 2004 or 1.2.
	 * Switch statements will convert some SCORM 2004 calls to SCORM 1.2, but you must understand there are limitations
	 * on data storage between versions. Example: Suspend Data 64,000 vs 4096 or Bookmark(location) 1000 vs 255.
	 * Depending on your use, your content may not squeeze into the SCORM 1.2 available space.  Because of this, log messages
	 * will be output so you can monitor your cmi "set" value length.  Ultimately, a LMS may block your request because of this.
	 * This API is meant to simplify common SCORM Tasks, but also offers the ability to use it 'long hand'. Several other
	 * public API's are available online, some free some charge, and this is a best effort to boil it all down.
	 * Documentation, samples, resources, and credits: ADL, <NAME>, Pipwerks, SCORM.com
	 * Goals: SCORM For Everyone else, low overhead, simple API's, containment, and transparency.
	 *
	 * Typical CMI Usage (if used by itself):
	 * var scorm = new SCORM_API({debug: true, exit_type: 'suspend'}),
	 * lmsconnected = scorm.initialize();
	 * scorm.getvalue('cmi.location');
	 * scorm.setvalue('cmi.location', '4');
	 * scorm.commit();
	 * scorm.terminate();
	 *
	 * HTML Event Setup:
	 * If you choose not to use SCOBot tips for onload and onunload, onbeforeunload events you may need to make init, exit methods to do other things
	 * vs. directly referencing the SCORM API here.  Feel free to make those methods if you need to.  'window.top' can be used because
	 * some deployments self occur within a popup in a IFRAME will not fire properly on exit, in some Mozilla browsers.  Last checked, window worked with
	 * JQuery 1.7+ however.  If you have issues trapping the unload event, please try window.top.
	 * $(window).bind('load', YOUR_INITIALIZATION_METHOD);
	 * $(window).bind('unload', YOUR_EXIT_METHOD);
	 *
	 * JSLint was recently changed and its throwing a "use spaces, not tabs" error.  I decided to switch to spaces.
	 * https://github.com/douglascrockford/JSLint/pull/140
	 *
	 * https://github.com/cybercussion/SCOBot
	 * @author <NAME> <<EMAIL>>
	 * @license Copyright (c) 2009-2014, Cybercussion Interactive LLC
	 * As of 3.0.0 this code is under a Creative Commons Attribution-ShareAlike 4.0 International License.
	 * @requires JQuery
	 * @version 3.1.0
	 * @param options {Object} override default values
	 * @constructor
	 */
	/*!
	 * SCORM_API, Updated January 3rd, 2014
	 * Copyright (c) 2009-2013, Cybercussion Interactive LLC.
	 * As of 3.0.0 this code is under a Creative Commons Attribution-ShareAlike 4.0 International License.
	 */
	function SCORM_API(options){
	    // Constructor ////////////
	    "use strict";
	    // Please edit run time options or override them when you instantiate this object.
	    var defaults = {
	            version:           "3.1.1",
	            createDate:        "04/05/2011 08:56AM",
	            modifiedDate:      "07/16/2014 09:40AM",
	            debug:             false,
	            windowDebug: 	   false,
	            isActive:          false,
	            throw_alerts:      false,
	            prefix:            "SCORM_API",
	            exit_type:         "suspend", // suspend, finish, or "" (undetermined)
	            success_status:    "unknown", // passed, failed, unknown
	            use_standalone:    true,
	            standalone:        false,
	            completion_status: "unknown", // completed, incomplete, unknown
	            time_type:         "GMT",
	            cmi:               null
	        },
	    	// Settings merged with defaults and extended options
	        settings = $.extend(defaults, options),
	    	// Internal API Error Boolean, Error Code object
	        isError = 0,
	        error = {
	            0:   "No Error",
	            404: "Not Found",
	            405: "Prevented on a read only resource"
	        },
	    	// API Object
	        API = {
	            connection: false,
	            version:    "none", // 2004, 1.2 or none
	            mode:       "",
	            path:       false, // Set Path to LMS API or maybe something local later by default?
	            data:       {// Defaults, I'm moving a few of the SCORM defaults into this data object, they will be maintained here thereafter.
	                completion_status: settings.completion_status,
	                success_status:    settings.success_status,
	                exit_type:         settings.exit_type
	            },
	            isActive:   settings.isActive  // If SCO is initialized already, this was added for a page by page concept where pages unload and load.
	        },
	        self = this;
	    // Public to Public call hook within the internal API
	    // Set some more 'settings'
	    settings.error = error; // Inherit
	    settings.startDate = {}; // Set on Success of Initialize aka "the start time"
	    // End Constructor ////////
	    
	    // Private ////////////////

	    /**
	     * Debug
	     * Built-In Debug Functionality to output to console (Firebug, Inspector, Dev Tool etc ...)
	     * @param msg {String} Debug Message
	     * @param lvl {Integer} 1=Error, 2=Warning, 3=Log, 4=Info
	     */
	    function debug(msg,lvl){
	        if(settings.debug){
	        	if(settings.windowDebug==true){
	        		windowDebug(msg,lvl);
	        	} else {
	        		_debug(msg,lvl);
	        	}
	        }
	        if(lvl < 3 && settings.throw_alerts){
	            alert(msg);
	        }
	        return false;
	    };

	   	function _debug(msg,lvl){
	   		// IE 7 probably 6 was throwing a error if 'console undefined'
            if(!window.console){
                window.console = {};
                window.console.info = noconsole;
                window.console.log = noconsole;
                window.console.warn = noconsole;
                window.console.error = noconsole;
                window.console.trace = noconsole;
            }
            switch(lvl){
            case 1:
                console.error(msg);
                break;
            case 2:
                console.warn(msg);
                break;
            case 4:
                console.info(msg);
                break;
            case 3:
                console.log(msg);
                break;
            default:
                console.log(msg);
                return false;
            }

            return true;
	    };

	    /**
	     * No Console
	     * Lack of support in older browsers forced this
	     * @param msg {String} Debug Message
	     * @param lvl {*} 1=Error, 2=Warning, 3=Log, 4=Info
	     * @event debug fired when no console is available.  You could listen to this to put it in an alternative log.
	     */
	    function noconsole(msg,lvl){
	        // ignore (IE 8 and prior or other browser that doesn't support it).  Routing event out so it can be handled.
	        $(self).triggerHandler({
	            'type': "debug",
	            'msg':  msg,
	            'lvl':  lvl
	        });
	    };


	    //Debug in a new window
		//debug info
		var aryDebug = new Array();
		var strDebug = "";
		var winDebug;

		function windowDebug(strInfo,lvl){

			var isDebugWindowShown = false;
			if(!winDebug || winDebug.closed){
				isDebugWindowShown = ShowDebugWindow();
			} else {
				isDebugWindowShown = true;
			}

			if(isDebugWindowShown==false){
				//pop-up window blocked
				//Disable windowDebug
				settings.windowDebug = false
				debug("Window debug has been blocked",1);
				debug("Debugging messages will be displayed in the console",2);
				debug(strInfo,lvl);
				return false;
			}

			var strLine;
			strLine = (aryDebug.length+1) + ": " + strInfo;
			aryDebug[aryDebug.length] = strLine;

			if(winDebug && !winDebug.closed){
				winDebug.document.write(strLine + "<br>\n");
			}

			return true;
		};

		function ShowDebugWindow(){
			if (winDebug && !winDebug.closed){
				winDebug.close();
			}

			winDebug = window.open("", "Debug", "width=600,height=300,resizable,scrollbars");

			if(typeof winDebug == "undefined"){
				//pop-up window blocked
				return false;
			}

			winDebug.document.write(aryDebug.join("<br>\n"));

			winDebug.document.close();

			winDebug.focus();

			return true;
		};

	    /**
	     * Find API
	     * API_1484_11 or API for SCORM 2004 or 1.2
	     * @param win {object} Window level
	     */
	    function findAPI(win){
	        var attempts = 0, limit = 500;
	        while ((!win.API && !win.API_1484_11) && (win.parent) && (win.parent !== win) && (attempts <= limit)){
	            attempts += 1;
	            win = win.parent;
	        }
	        if(win.API_1484_11){ //SCORM 2004-specific API.
	            API.version = "2004";
	            //Set version
	            API.path = win.API_1484_11;
	        } else if(win.API){ //SCORM 1.2-specific API
	            API.version = "1.2";
	            //Set version
	            API.path = win.API;
	        } else {
	            return false;
	        }
	        return true;
{'fraction_non_alphanumeric': 0.10910072913853633, 'fraction_numerical': 0.019821766135565758, 'mean_word_length': 1.9859700048379294, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7543029', 'n_tokens_mistral': 5978, 'n_tokens_neox': 5110, 'n_words': 1737}