// ac.js // Loading... // loader.js function ac_loader_add(id, base) { var elem = document.getElementById(id); if (elem !== null) { var img = document.createElement("img"); img.src = base + "media/loader.gif"; img.id = id + "_loader"; ac_dom_remove_children(elem); elem.appendChild(img); } } function ac_loader_rem(id) { var elem = document.getElementById(id); var img = document.getElementById(id + "_loader"); if (elem !== null && img !== null) { elem.removeChild(img); } } function ac_loader_show(txt) { // cleanup previous if ( ac_error_visible() ) ac_error_hide(); if ( ac_result_visible() ) ac_result_hide(); if ( !txt ) { $('ac_loading_text').innerHTML = nl2br(jsLoading); } else { $('ac_loading_text').innerHTML = nl2br(txt); } $('ac_loading_bar').className = 'ac_block'; } function ac_loader_hide() { $('ac_loading_bar').className = 'ac_hidden'; } function ac_loader_visible() { return $('ac_loading_bar').className == 'ac_block'; } function ac_loader_flip() { ac_dom_toggle_class('ac_loading_bar', 'ac_hidden', 'ac_block'); } // ui.js var ac_ui_prompt_width = "300px"; var ac_ui_prompt_top = "0px"; var ac_ui_prompt_left = "0px"; // Create an input box for our "prompt". Label is what you want the box to say above the // input element. Cb is the callback function. // // Builder has some problems with parsing functions or javascript for its events. // Particularly, I've noticed, it has some problems with strings in cb. The safest method // I've experienced is make cb look like "func()", where func() is the actual callback. function ac_ui_prompt_make(label, vbl) { // need to clear out vbl if (!ac_ui_prompt_echeck(vbl)) return; eval(sprintf("%s = null;", vbl)); var elab = Builder._text(label); var einp = Builder.node("input", { style: "border: 1px solid black; font-size: 10px", id: "ac_ui_prompt_input" }); var esub = Builder.node("input", { type: "button", onclick: sprintf("%s = $('ac_ui_prompt_input').value; ac_ui_prompt_free()", vbl), value: "Submit", style: "font-size: 10px" }); var ediv = Builder.node("div", { id: "ac_ui_prompt_div", style: sprintf("font-family: Verdana, San-Serif; text-align: center; border: 1px solid #cccccc; background: #eeeeee; padding: 5px; font-size: 10px; position: absolute; width: %s; top: %s; left: %s", ac_ui_prompt_width, ac_ui_prompt_top, ac_ui_prompt_left) }); ediv.appendChild(elab); ediv.appendChild(Builder.node("br")); ediv.appendChild(einp); ediv.appendChild(Builder._text(" ")); ediv.appendChild(esub); document.body.appendChild(ediv); } function ac_ui_prompt_free() { var elem = $("ac_ui_prompt_div"); if (elem !== null) document.body.removeChild(elem); } function ac_ui_prompt_echeck(str) { return str.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/); } function ac_ui_prompt(label, vbl, waitfor) { var val; if (waitfor == "" || !ac_ui_prompt_echeck(waitfor)) val = "ok"; // anything will do else val = eval(waitfor); if (val !== null) ac_ui_prompt_make(label, vbl); else { window.setTimeout(function() { ac_ui_prompt(label, vbl, waitfor); }, 500); } } function ac_ui_prompt_waitdo(vars, func) { for (var i = 0; i < vars.length; i++) { if (!ac_ui_prompt_echeck(vars[i])) return; var val = eval(vars[i]); if (val === null) { window.setTimeout(function() { ac_ui_prompt_waitdo(vars, func); }, 500); return; } } func(); } /* var _a = null; var _b = null; var _c = null; ac_ui_prompt("a", "_a", ""); ac_ui_prompt("b", "_b", "_a"); ac_ui_prompt("c", "_c", "_b"); ac_ui_prompt_waitdo(["_a", "_b", "_c"], function() { alert("done!"); }); */ /* ANCHORS */ function ac_ui_anchor_set(newAnchor, data) { ac_anchor_old = newAnchor; window.location.hash = newAnchor; } function ac_ui_anchor_get() { return window.location.hash.substr(1); } function ac_ui_anchor_changed() { var newAnchor = ac_ui_anchor_get(); if ( newAnchor != ac_anchor_old ) { if ( typeof(runPage) == 'function' ) runPage(); } } function ac_ui_anchor_init() { historyTimer = setInterval(ac_ui_anchor_changed, 200); } var ac_anchor_old = ac_ui_anchor_get(); var historyTimer = null; /* Functions that trigger session ping method Usages: - admin side: ac_ui_session_ping_admin(); // every 10 minutes - public side: ac_ui_session_ping_public(); // every 10 minutes */ // set session ping function ac_ui_session_ping_admin() { setInterval( function() { ac_ajax_call_cb('../ac_global/api/public/ping.php', 'sessionping', null); }, 10 * 60 * 1000 // every 10 minutes ); } // set session ping function ac_ui_session_ping_public() { setInterval( function() { ac_ajax_call_cb('ac_global/api/public/ping.php', 'sessionping', null); }, 10 * 60 * 1000 // every 10 minutes ); } /* REAL SIMPLE HISTORY */ var ac_rsh = null; function ac_rsh_listener(newLocation, historyData) { // do something var msg = 'A history change has occurred!\n\n\nNew Location:\n' + newLocation + '\n\nHistory Data:\n' + historyData; alert(msg); //ac_loader_show(nl2br(msg)); } function ac_ui_rsh_init(listenerFunction, firstTimeRun) { // initialize rsh ac_rsh = window.dhtmlHistory.create( { toJSON: function(o) { return Object.toJSON(o); }, fromJSON: function(s) { return s.evalJSON(); } } ); // set fallback function in case function ain't provided if ( typeof(listenerFunction) != 'function' ) { listenerFunction = ac_rsh_listener; } // prototype-style adding envent observers Event.observe( window, 'load', function() { dhtmlHistory.initialize(); dhtmlHistory.addListener(listenerFunction); if ( firstTimeRun && dhtmlHistory.isFirstLoad() ) { listenerFunction(dhtmlHistory.currentLocation, null); } } ); } function ac_ui_rsh_save(newLocation, historyData) { dhtmlHistory.add(newLocation, historyData); } /* AJAX API CALLS SUPPORTING FUNCTIONS (needs standardization, naming at least) */ // define default english strings if translatables are not provided var jsAreYouSure = 'Are You Sure?'; var jsAPIfailed = 'Server call failed for unknown reason. Please try your action again...'; var jsLoading = 'Loading...'; var jsResult = 'Changes Saved.'; var jsResult = 'Error Occurred!'; // define vars used var resultTimer = false; // used in API call functions var processingDelay = 10; // seconds! used in API call functions (how long to wait?) var printAPIerrors = false; // if false, will do alert(!), if {} it will discard, if function it will pass message as param or true DOM ref to print there (innerHTML) // this function notifies about droppedd api call (after time interval has passed) // it will stop the loading bar and print out the error if listed function ac_ui_api_stop() { if ( resultTimer ) { window.clearTimeout(resultTimer); // we don't need this, done elsewhere resultTimer = false; } else { return; } if ( typeof(printAPIerrors) == 'function' ) { printAPIerrors(jsAPIfailed); } else if ( typeof(printAPIerrors) == 'object' ) { printAPIerrors.innerHTML = jsAPIfailed; } else { alert(jsAPIfailed); } ac_loader_hide(); } // this function should be called right prior to ac_ajax_* function ac_ui_api_call(customMessage, delay) { if ( !delay ) delay = processingDelay; resultTimer = window.setTimeout(ac_ui_api_stop, delay * 1000); ac_loader_show(customMessage); } // this function should be called right at the end of ajax callback function function ac_ui_api_callback() { // reset the timer if ( resultTimer ) { window.clearTimeout(resultTimer); resultTimer = false; } // if processing is shown, hide it, since we got our response back ac_loader_hide(); } /* RESULT/ERROR MESSAGES (THE SAME AS LOADER BAR FROM loader.js) */ function ac_result_show(txt) { // cleanup previous if ( ac_loader_visible() ) ac_loader_hide(); if ( ac_error_visible() ) ac_error_hide(); if ( !txt ) { $('ac_result_text').innerHTML = nl2br(jsResult); } else { $('ac_result_text').innerHTML = nl2br(txt); } $('ac_result_bar').className = 'ac_block'; window.setTimeout(ac_result_hide, 6 * 1000); } function ac_result_hide() { $('ac_result_bar').className = 'ac_hidden'; } function ac_result_visible() { return $('ac_result_bar').className == 'ac_block'; } function ac_result_flip() { ac_dom_toggle_class('ac_result_bar', 'ac_hidden', 'ac_block'); } function ac_error_show(txt) { // cleanup previous if ( ac_loader_visible() ) ac_loader_hide(); if ( ac_result_visible() ) ac_result_hide(); if ( !txt ) { $('ac_error_text').innerHTML = nl2br(jsError); } else { $('ac_error_text').innerHTML = nl2br(txt); } $('ac_error_bar').className = 'ac_block'; window.setTimeout(ac_error_hide, 6 * 1000); } function ac_error_hide() { $('ac_error_bar').className = 'ac_hidden'; } function ac_error_visible() { return $('ac_error_bar').className == 'ac_block'; } function ac_error_flip() { ac_dom_toggle_class('ac_error_bar', 'ac_hidden', 'ac_block'); } // menu init function ac_ui_menu_init() { //if ( document.getElementsByClassName('trapperr').length == 0 ) initjsDOMenu(); } /* KEY STOPPERS */ // usage: $('inputID').onkeypress = ac_ui_stopkey_enter; function ac_ui_stopkey_enter(evt) { var evt = ( evt ? evt : ( event ? event : null ) ); if ( !evt ) return true; var node = ( evt.target ? evt.target : ( evt.srcElement ? evt.srcElement : null ) ); // 13 == ENTER if ( evt.keyCode == 13 && node.type == "text" ) { // nope, don't submit return false; } } function ac_ui_tab_reset(ul) { var rel = $(ul); if ( !rel ) return; var li = rel.getElementsByTagName('li'); for ( var i = 0; i < li.length; i++ ) { if ( li[i].id && li[i].id.substr(0, 9) == 'main_tab_' ) { li[i].className = "othertab"; var tabname = li[i].id.substr(9); var tab = $(tabname); if ( tab ) { tab.className = 'ac_hidden'; } } } } // str.js /* function ac_str_trim(str) { return str.replace(/^\s*(\S+)\s*$/, "$1"); } */ function ac_str_trim(str, chars) { return ac_str_ltrim(ac_str_rtrim(str, chars), chars); } function ac_str_ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function ac_str_rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } function ac_str_repeat(str, times) { var out = ""; while (times--) out += str; return out; } function ac_str_shorten(text, chars) { if ( !chars || chars == 0 ) return text; var textLength = text.length; text += ' '; text = text.substr(0, chars); var lastSpacePos = text.lastIndexOf(' '); if ( lastSpacePos != -1 ) text = text.substr(0, lastSpacePos); if ( textLength > text.length ) text += '...'; return text; } function ac_str_array(str) { var ary = new Array(); for (var i = 0; i < str.length; i++) { if (str[i] == '&') { var tmp = ""; while (i < str.length) { tmp += str[i++]; if (str[i-1] == ';') break; } ary.push(tmp); } else { ary.push(str[i]); } } return ary; } function ac_array_has(ary, val) { for (var i = 0; i < ary.length; i++) { if (ary[i] == val) return true; } return false; } function ac_array_extract(str) { var ary = new Array(); var tmp = str.split("||"); for (var i = 0; i < tmp.length; i++) { var ent = tmp[i].split("=", 2); ary[ent[0]] = ent[1]; } return ary; } function ac_str_array_len(ary) { for (var i = 0, c = 0; i < ary.length; i++) c += ary[i].length; return c; } function ac_str_array_substr(ary, off, len) { var tmp = ""; for (var i = off; i < ary.length; i++) { if (i >= len) break; tmp += ary[i]; } return tmp; } function ac_str_url(rel) { var ary = rel.split("/"); var url = window.location.href.replace(/\/[^\/]*$/, ""); for (var i = 0; i < ary.length; i++) { if (ary[i] == "..") url = url.replace(/\/[^\/]*$/, ""); else url += "/" + ary[i]; } return url; } function ac_ary_last(ary, begin) { var nary = new Array(); for (var i = begin, j = 0; i < ary.length; i++, j++) { nary[j] = ary[i]; } return nary; } function ac_str_rand_password(len) { var out = ""; while (len--) { out += ac_str_rand_passchar(); } return out; } function ac_str_rand_passchar() { var floor = Math.floor(Math.random() * 10.0); var chr; if (floor > 6) { chr = Math.floor(Math.random() * 10.0); chr = chr.toString(); } else { var off = Math.floor(Math.random() * 100.0) % 26; chr = "a".charCodeAt(0) + off; chr = String.fromCharCode(chr); } return chr; } function ac_sprintf(fmt, args) { var out; var argi; out = ""; argi = 0; for (var i = 0; i < fmt.length; i++) { var fmtc = fmt.charAt(i); switch (fmtc) { case "\\": i++; break; case "%": if (argi < args.length) { fmtc = fmt.charAt(i+1); out += ac_sprintf_spec(fmtc, args[argi]); i++; argi++; } else { out += fmtc; } break; default: out += fmtc; break; } } return out; } function ac_sprintf_spec(ch, arg) { switch (ch) { case "d": case "f": return arg.toString(); case "s": default: return arg; } return ""; } // This code is in the public domain. Feel free to link back to http://jan.moesen.nu/ function sprintf() { if (!arguments || arguments.length < 1 || !RegExp) { return; } var str = arguments[0]; var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/; // ' var a = b = [], numSubstitutions = 0, numMatches = 0; while (a = re.exec(str)) { var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4]; var pPrecision = a[5], pType = a[6], rightPart = a[7]; //alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision); numMatches++; if (pType == '%') { subst = '%'; } else { numSubstitutions++; if (numSubstitutions >= arguments.length) { //alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).\n\nString in question:\n' + str); return; } var param = arguments[numSubstitutions]; var pad = ''; if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1); else if (pPad) pad = pPad; var justifyRight = true; if (pJustify && pJustify === "-") justifyRight = false; var minLength = -1; if (pMinLength) minLength = parseInt(pMinLength); var precision = -1; if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1)); var subst = param; if (pType == 'b') subst = parseInt(param).toString(2); else if (pType == 'c') subst = String.fromCharCode(parseInt(param)); else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0; else if (pType == 'u') subst = Math.abs(param); else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param); else if (pType == 'o') subst = parseInt(param).toString(8); else if (pType == 's') subst = param; else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase(); else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase(); } str = leftpart + subst + rightPart; } return str; } /* * This is the function that actually highlights a text string by * adding HTML tags before and after all occurrences of the search * term. You can pass your own tags if you'd like, or if the * highlightStartTag or highlightEndTag parameters are omitted or * are empty strings then the default tags will be used. */ function ac_str_highlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) { // the highlightStartTag and highlightEndTag parameters are optional if ((!highlightStartTag) || (!highlightEndTag)) { highlightStartTag = ""; highlightEndTag = ""; } // find all occurences of the search term in the given text, // and add some "highlight" tags to them (we're not using a // regular expression search, because we want to filter out // matches that occur within HTML tags and script blocks, so // we have to do a little extra validation) var newText = ""; var i = -1; var lcSearchTerm = searchTerm.toLowerCase(); var lcBodyText = bodyText.toLowerCase(); while (bodyText.length > 0) { i = lcBodyText.indexOf(lcSearchTerm, i+1); if (i < 0) { newText += bodyText; bodyText = ""; } else { // skip anything inside an HTML tag if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) { if ( // skip anything inside a