/**
* Modify JSON representation string in Javascript object
* @param string Json_string String that we will format in Javascript object
**/
function js_support_json_format(Json_string) {
var Json_string = JSON.stringify(Json_string); //Convert a value to JSON String, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified
var Json = JSON.parse(trim(Json_string)); //Convert to JSON
var Object = eval("(function(){return " + Json + ";})()"); //Convert a JSON into an object
return Object; //Return Javascript object
}
/**
* Display loading message
* @param string tabs The id of tab that we will display loading message
*/
function js_support_loading_msg(tabs) {
var loading_html = '
'; //Loading message
document.getElementById(tabs).innerHTML = loading_html; //display loading message in tab
}
/** Find out the difference between two time values
* @param string StartTime Value of Start Time
* @param string EndTime Value of End Time
*/
function js_support_time_diff(StartTime, EndTime) {
StartTime = StartTime.split(":"); //Split Start time
EndTime = EndTime.split(":"); //Split End Time
var Startmin = StartTime[1] * 60; //Convert start minutes to second
var Endtmin = EndTime[1]*60; //Convert end minutes to seconds
var diff = ((Endtmin+EndTime[2]) - (Startmin+StartTime[2])) * 1000; //Find out the differentation
return parseInt(diff); //Divide the demical part
}
/**
* Enable or disable input field
* @param id id of input that we want to enable or disable
*/
function js_support_control_input(id) {
$(document).ready(function(){
//Check if button is disable
if ($(id + '_ctrl').hasClass("green")) {
//Set disable attribute to false
$(id).prop("disabled", false);
//Enable Disable button
$(id + '_ctrl').attr('class', 'btn red');
$(id + '_ctrl').html('Disable');
}
else {
//Check if button is enable
$(id).prop("disabled", true);
//Disable enable button
$(id + '_ctrl').attr('class', 'btn green');
$(id + '_ctrl').html('Enable')
}
});
}
/** Control width of a div for responsive reason
* @param string id the id of div that we want to change the width
* @param string width the value of width that we want to set
*/
function js_support_control_width(id, width) {
//Set the width of responsive width
document.getElementById(id).style.width = width + "px";
var html = document.getElementById(id).innerHTML;
$(document).ready(function(){
$("div")
.find(".midd_img")
.css({
"width": width
})
});
}
/** Enable tab menu using javascript (Activate selected li and tab container)
* @param string TabContainerID ID of tab that container that contains all tab
* @param string TabActivateID
*/
function js_support_enable_tab_menu(TabContainerID, TabActivateID) {
//enable the selected tab container
$(TabContainerID + " div.tab-pane").each(function () {
// Remove active class from all tab
$(this).removeClass('active');
//Enable the selected
if ($(this).is('#' + TabActivateID)) {
$(this).addClass('active');
}
});
// Enable the selected li menu
$(TabContainerID + " ul li").each(function () {
$(this).removeClass('active');
});
//Set Tab ContainerID
$(TabContainerID + ' li:has(a[href="#' + TabActivateID + '"])').addClass('active');
}
/** Execute script (usually is used after an ajax success return )
* @param element object $container The $container interface represents an object of a Document
*/
function js_support_exec_script($container) {
//Get scripts tags from a node
var $scripts = $container.querySelectorAll('script')
var runList = []
var typeAttr
[].forEach.call($scripts, function ($script) {
typeAttr = $script.getAttribute('type')
// only run script tags without the type attribute
// or with a javascript mime attribute value
if (!typeAttr || runScriptTypes.indexOf(typeAttr) !== -1) {
runList.push(function (callback) {
insertScript($script, callback)
})
}
})
//Insert the script tags sequentially
//To preserve execution order
seq(runList, scriptsDone)
}