Class Index | File Index

Classes


Namespace mmir.CommonUtils

mmir.CommonUtils
Defined in: commonUtils.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
A Utility class to support various functions.
Field Summary
Field Attributes Field Name and Description
<private>  
<private>  
 
Regular Expression for matching HTML comments.
Method Summary
Method Attributes Method Name and Description
 
This function is used check whether a network connection is enabled.
 
concatArray(array)
extracts all the strings from a String-Array into a single string
<private>  
constructor($, constants)
Constructor-Method of Class mmir.CommonUtils
 
Converts the object's direct properties to a valid JSON String (i.e.
 
Converts the object to a valid JSON String value.
 
getCompiledGrammarPath(generatedGrammarsPath, grammarId, isFileNameOnly)
Get the file path/name for a compiled grammar (executable JavaScript grammars).
 
This function returns an array of strings with the contents of a directory.
 
This function returns an array of strings with the contents of a directory, giving only those files which match the filter.
 
 
getLocalScript(scriptUrl, success, fail)
Note: On Android 4.0 jQuery.getScript() is not working properly - so use this function instead!
Similar to the jQuery.getScript() function - appending a url of a javascript-source to the header of the main document.
 
 
init(success, errorFunc)
 
isArray(object)
Checks if an object is an Array.
<private>  
This helper initializes a function for detecting if an Object is an Array.
 
Detects via the user-agent-string if the application is running on Android.
 
Should detect - via the user-agent-string - if the application is running on Android, Symbian or iOS; in other words: on a smartphone.
 
loadAllCordovaPlugins(pluginsPath, cbFunction)
Load all plugins (i.e.
 
loadCompiledGrammars(generatedGrammarsPath, cbFunction, ignoreGrammarIds)
Load all compiled grammars (executable JavaScript grammars).
 
loadDirectoryStructure(success, errorFunc)
Parses the directory structure - paths given by property mmir.CommonUtils-constructor-directoriesToParse - and storing the result in the class-property mmir.CommonUtils-directoryStructure
 
loadImpl(librariesPath, isSerial, completedCallback, checkIsAlreadyLoadedFunc, statusCallback)
Load implementation files (i.e.
 
loadScript(url, callback)
Similar to the jQuery.getScript() function - appending a url of a javascript-source to the header of the main document.
 
parseParamsToDictionary(urlParamsPartStrings)
IMPORTED FROM paramsParseFunc.js

Convert parameter-part of an URL to a "dictionary", containing the parameter keys and values

?id=5&name=heinz&name=kunz

	{
	  id: "5",
	  name: ["heinz", "kunz"],
   
	  //utility functions
	  has: function(key) : Boolean,
	  isMultiple: function(key) : Boolean,// is entry an Array of values
	  getKeys: function() : String[],     // get list of all keys
	}
	

The returnd "dictionary" has the following functions:

  • has(String key): returns true if the dictionary contains an entry for key
  • isMultiple(String key): returns true if the entry for key is an Array (i.e.
 
This function iterates over all elements of a specific class and changes the font-size of the contained text to the maximal possible size - while still being small enough to fit in the element.
 
Set to "backwards compatibility mode" (for pre version 2.0).
<private>  
stripPathName(pathname)
This function is used by mmir.CommonUtils#getDirectoryContents and mmir.CommonUtils#getDirectoryContentsWithFilter to strip the pathname parameter
 
toJSONStringValue(theObjectValue)
Converts the object to a valid JSON String value.
Namespace Detail
mmir.CommonUtils
A Utility class to support various functions.
var isList = mmir.CommonUtils.isArray(list);
Requires:
StringExtensions
Constants (optionally: jQuery)
mmir.SemanticInterpreter (in {@link mmir.CommonUtils#loadCompiledGrammars})
jQuery.isArray in #isArrayHelper
jQuery.Deferred in #loadImpl, #loadDirectoryStructure, #setToCompatibilityMode
jQuery.ajax in #loadDirectoryStructure
jQuery in #resizeFitToSourroundingBox
Field Detail
<private> {CommonUtils} instance

<private> {Logger} logger

{String|RegExp} regexHTMLComment
Regular Expression for matching HTML comments.
This RegExp also matches multi-line comments. Note upon using the RegExp that it does not consider if a HTML comment is specified within a String or data-definition (i.e. the comment is matched regardless were its defined).
Method Detail
{Boolean} checkNetworkConnection()
This function is used check whether a network connection is enabled.
This version of checking the network connection is based on the cordova 2.3.0 API. TODO implement with HTML5 functions (in addition to / instead of cordova)?
Returns:
{Boolean} true if a network connection is enabled
Requires:
Cordova: org.apache.cordova.network-information

{string} concatArray(array)
extracts all the strings from a String-Array into a single string
Parameters:
array
Returns:
{string} text

<private> constructor($, constants)
Constructor-Method of Class mmir.CommonUtils
Parameters:
{jQuery} $ Optional
the jQuery instance/object (OPTIONAL); some few function need jQuery to work correctly (see requires annotations)
constants

{String} convertJSONStringToHTML(_o)
Converts the object's direct properties to a valid JSON String (i.e. no recursion for Object properties).
Parameters:
{Object} _o
the object to convert to a JSON String.
Returns:
{String} the String value

{String} convertJSONStringValueToHTML(theObjectValue)
Converts the object to a valid JSON String value. Ensures that the returned value does not contain (un-escaped) double-quotes, so that the returned value can be used as a JSON value, also does replace all newlines with the HTML-equivalent '<br/>', e.g.
 var jsonValue = mmir.CommonUtils.convertJSONStringValueToHTML(someValue);
 var data = JSON.parse('"theValue":"' + jsonValue + '"');
 ...
Parameters:
{Object} theObjectValue
the object to convert to a JSON String value. If NULL or UNDEFINED, an EMPTY String will be returned
Returns:
{String} the String value

{String} getCompiledGrammarPath(generatedGrammarsPath, grammarId, isFileNameOnly)
Get the file path/name for a compiled grammar (executable JavaScript grammars).
Parameters:
{String} generatedGrammarsPath
Path of the grammars which should be loaded, e.g. gen/grammar/
{String} grammarId
the ID (e.g. language code) for the grammar
{Boolean} isFileNameOnly Optional
OPTIONAL if TRUE then only the file name will be returned, otherwise the full path is returned
Returns:
{String} file path / name for the compiled grammar (returns an empty string, if there is no compile grammar for the specified grammar ID)

{Array} getDirectoryContents(pathname)
This function returns an array of strings with the contents of a directory.
Parameters:
{String} pathname
Path of the directory which contents should be returned
Returns:
{Array} Array of Strings which contains the contents of the directory

{Array} getDirectoryContentsWithFilter(pathname, filter)
This function returns an array of strings with the contents of a directory, giving only those files which match the filter.
Parameters:
{String} pathname
Path of the directory which's contents should be returned
{String} filter
Filter for file-names which may contain a wildcard, e.g.: *.js, * or *.ehtml
Returns:
{Array} Array of Strings which contains the contents of the directory. Or null, if no matching contents could be found.

{Object} getDirectoryStructure()
Returns:
{Object} Directory structure as json object

getLocalScript(scriptUrl, success, fail)
Note: On Android 4.0 jQuery.getScript() is not working properly - so use this function instead!
Similar to the jQuery.getScript() function - appending a url of a javascript-source to the header of the main document.
This function also calls a success-callback if the script was successfully loaded or a fail-callback.
Parameters:
{String} scriptUrl
source of javascript-file
{Function} success
success callback function
{Function} fail
fail callback function

{String} getPartialsPrefix()
Returns:
{String} The Prefix for the file names of partial-files

init(success, errorFunc)
Parameters:
success
errorFunc

{Boolean} isArray(object)
Checks if an object is an Array.

This function can be savely run in arbirtray contexts, e.g.

 var checkArray = mmir.CommonUtils.getInstance().isArray;
if( checkArray(someObject) ){
  ...
Parameters:
{Object} object
the Object for checking if it is an Array
Returns:
{Boolean} true if object is an Array, otherwise false.

<private> {Function} isArrayHelper(obj)
This helper initializes a function for detecting if an Object is an Array. The helper tries to find functions of JavaScript libraries for this; if none can be found, a custom implementation is used. The returned function is used by mmir.CommonUtils#isArray NOTE: The current implementation checks jQuery.isArray for presences
Parameters:
obj
Returns:
{Function} a function that takes one parameter (Object) and returns true if this parameter is an Array (false otherwise)

{Boolean} isRunningOnAndroid()
Detects via the user-agent-string if the application is running on Android.
Returns:
{Boolean} True if application is running on Android, False otherwise

{Boolean} isRunningOnSmartphone()
Should detect - via the user-agent-string - if the application is running on Android, Symbian or iOS; in other words: on a smartphone.
Returns:
{Boolean} True if application is running on smartphone, False otherwise

{Promise} loadAllCordovaPlugins(pluginsPath, cbFunction)
Load all plugins (i.e. JavaScript interfaces for Cordova/Java-Impl. plugins).
Parameters:
{String} pluginsPath Optional
OPTIONAL Path of the plugins which should be loaded, e.g. mmirf/plugins/ If omitted: the default plugin-path is used (see mmir.Constants#getPluginsPath)
{Function} cbFunction Optional
OPTIONAL The function that should be executed after the plugins are loaded. If the execution of following functions is dependent on the present of plugins, they should be triggered from inside the callback-function
Returns:
{Promise} a Deferred.promise (see loadImpl())

{Promise} loadCompiledGrammars(generatedGrammarsPath, cbFunction, ignoreGrammarIds)
Load all compiled grammars (executable JavaScript grammars).
Parameters:
{String} generatedGrammarsPath
Path of the grammars which should be loaded, e.g. gen/grammar/
{Function} cbFunction
The function that should be executed after the plugins are loaded. If the execution of following functions is dependent on the presence of the grammars, they should be triggered from inside the callback-function.
{Array} ignoreGrammarIds Optional
OPTIONAL grammar IDs that should be ignored, i.e. not loaded, even if there is a file available
Returns:
{Promise} a Deferred.promise (see loadImpl())
Requires:
mmir.SemanticInterpreter (must be loaded as dependency "semanticInterpreter" at least once before this function is loaded)

loadDirectoryStructure(success, errorFunc)
Parses the directory structure - paths given by property mmir.CommonUtils-constructor-directoriesToParse - and storing the result in the class-property mmir.CommonUtils-directoryStructure
Parameters:
{Function} success Optional
The function that should be executed after the diretories are parsed - it's best to include all following functions inside the callback-function.
{Function} errorFunc Optional
callback function that is invoked if an error occured during initialization.

{Promise} loadImpl(librariesPath, isSerial, completedCallback, checkIsAlreadyLoadedFunc, statusCallback)
Load implementation files (i.e. JavaScript files) from a directory (if librariesPath is a String) or or a list of files-names (if librariesPath is an Array of Strings).
Parameters:
{String|Array} librariesPath
Path (or list of of the plugins which should be loaded, e.g. mmirf/plugins/ NOTE: The (String) path must be an entry in directories.json! (directories.json is used to generate/"query" the file-list for the path)
{Boolean} isSerial
Set true if the libraries should be loaded serially, i.e. synchronously, that is "one after the other" (later ones may depend on earlier ones). set false if libraries should be loaded in parallel, i.e. "asychronously" (NOTE in this case, the libraries must not depend on each other). NOTE: The loading process as a hole is asynchronous (regardless of parameter isSerial), i.e. loading is completed when completedCallback() is invoked, NOT when this function returns!
{Function} completedCallback Optional
The function that should be executed after the libraries are loaded. If the execution of following functions is dependent on the presence of the libraries, they should be capsuled inside this callback-function.
{Function} checkIsAlreadyLoadedFunc Optional
If provided, this function checks (based on the file-name), if the library is already loaded. The signature for the callback is checkIsAlreadyLoadedFunc(String fileName) return [true|false], i.e. the function may check - based on the file-name - if the library is already loaded. If the function returns true, the library will not be loaded, and loading continues with the next library-file. NOTE: if isSerial is flase, libraries with lower indices in the list may still be loading, when later entries are checked with this callback. In consequence, the "is already loaded"-check may not be accurate, in case parallel loading is used and the library-list contains "duplicate" entries.
{Function} statusCallback Optional
If provided, this function is invoked, when a library was loaded loaded (INFO) or an error occurs. The signature for the callback is statusCallback(String statusLevel, String fileName, String message) where statusLevel is one of info, warning, error, fileName is the file-name for the library that this status message concerns, and message is a message text with details concerning the status
Returns:
{Promise} a Deferred.promise that will be fullfilled when loadImpl() has finished.

loadScript(url, callback)
Similar to the jQuery.getScript() function - appending a url of a javascript-source to the header of the main document.
This function also calls a callback if the script was loaded.
Parameters:
{String} url
source of javascript-file
{Function} callback
callback function
Deprecated:
instead use #getLocalScript()

{Object} parseParamsToDictionary(urlParamsPartStrings)
IMPORTED FROM paramsParseFunc.js

Convert parameter-part of an URL to a "dictionary", containing the parameter keys and values

?id=5&name=heinz&name=kunz

	{
	  id: "5",
	  name: ["heinz", "kunz"],
   
	  //utility functions
	  has: function(key) : Boolean,
	  isMultiple: function(key) : Boolean,// is entry an Array of values
	  getKeys: function() : String[],     // get list of all keys
	}
	

The returnd "dictionary" has the following functions:

Parameters:
{String} urlParamsPartStrings
the parameter-part of the URL, i.e. &...
Returns:
{Object} a "dictionary" for the parameters

resizeFitToSourroundingBox(class_name)
This function iterates over all elements of a specific class and changes the font-size of the contained text to the maximal possible size - while still being small enough to fit in the element.
Parameters:
{String} class_name
Name of the class which inner text should be fitted to the size of the element
Requires:
jQuery

{jQuery.Promise} setToCompatibilityMode(success)
Set to "backwards compatibility mode" (for pre version 2.0). This function re-adds deprecated and removed functions and properties to the CommonUtils instance. NOTE that once set to compatibility mode, it cannot be reset to non-compatibility mode.
Parameters:
{Function} success Optional
a callback function that is invoked, after compatibility mode was set (alternatively the returned promise can be used).
Deprecated:
use only for backward compatibility
Returns:
{jQuery.Promise} a Deffered.promise that is resolved, after compatibility mode was set
Requires:
jQuery.Deferred
mmir.CommonUtils.setToCompatibilityModeExtension
See:
mmir.CommonUtils.setToCompatibilityModeExtension

<private> {String} stripPathName(pathname)
This function is used by mmir.CommonUtils#getDirectoryContents and mmir.CommonUtils#getDirectoryContentsWithFilter to strip the pathname parameter
Parameters:
{string} pathname
The path that should be stripped of "file://" and a beginning or trailing "/"
Returns:
{String} The stripped pathname - devoid of beginning "file://" or "/" and trailing "/"

{String} toJSONStringValue(theObjectValue)
Converts the object to a valid JSON String value. Ensures that the returned value does not contain (un-escaped) double-quotes, so that the returned value can be used as a JSON value, e.g.
 var jsonValue = mmir.CommonUtils.toJSONStringValue(someValue);
 var data = JSON.parse('"theValue":"' + jsonValue + '"');
Parameters:
{Object} theObjectValue
the object to convert to a JSON String value. If NULL or UNDEFINED, an EMPTY String will be returned
Returns:
{String} the String value

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Feb 26 2016 21:44:43 GMT+0100 (Mitteleuropäische Zeit)