$(function(){ /******************************* helpLinks.js ******************************* * Based on * - Template: stdNatCen.htm * - CSS: helpLinks.css ** * REVISIONS * - V1.0 27/02/2015 Initial Release * - V1.1 01/06/2015 CHANGED custom log functions ********* LOCAL ADJUSTMENT ************************************************* //BD170915:: Prevent selecting response while clicking the info text // in stdToggleDialogOnEvent() AND stdToggleSmallHelp() ***************************************************************************/ logHelpLinksINFO('L#000 HelpLink.js V1.0 --- CONSOLE.LOG == FALSE'); //HIDE visible (not yet activated) dialogs $('[id*="HELP-QDLdialog"]').filter(':visible').addClass('hidden'); // + + + + + ACTIVATE EACH HELP LINK WITH DIALOG RENDERED BY DC + + + + + // //OLD render-code $('[id*="HELP-QDLtrigger"]').each(function(){ //Add title $(this).attr('title','The link has not been activated. Please wait a moment.'); //Transform help-text to (pop-up) dialog stdPrepareDialog('#'+$(this).attr('id'),'#'+$(this).attr('id').replace('-QDLtrigger','-QDLdialog')); //REMOVE THE
BEFORE LINK $(this).prev('br').remove(); //REMOVE title from link Add class $(this).removeAttr('title').addClass('cursor-pointer').wrap('
'); }); //New render-code (XS and XL) $('.dc-rendered-help-set').each(function(){ //Transform help-text to (pop-up) dialog stdPrepareDialog('#'+ $('[id*="dc-rendered-help-trigger"]',this).attr('id'),'#'+ $('[id*="dc-rendered-help-dialog"]',this).attr('id')); //REMOVE title and ADD class from trigger $('p.helper-link',this).removeAttr('title').addClass('cursor-pointer'); }); // + + + + + TRANSFORM EACH LONG-HELP ELEMENT TO ACTIVE HELP LINK WITH DIALOG + + + + + // $('.long-help').each(function(l_index){ stdTransformToHelpDialog(this,l_index); }); // + + + ADD tabindex to all help-links + + + // stdHandleTabIndex($('.small-help, [id^="dc-rendered-help-trigger"], [id^="help-dialog-trigger"], [id*="HELP-QDLtrigger"]')); // + + + Toggle (small) help-links on click-event + + + // $('.help-link,.small-help').on('click', stdToggleSmallHelp); // + + + Toggle (long) help-links on click-event + + + // $('[id^="dc-rendered-help-trigger"]').on('click',{renderedBy: 'dc'}, stdToggleDialogOnEvent); $('[id^="help-dialog-trigger"]').on('click',{renderedBy: 'js'}, stdToggleDialogOnEvent); // + + + Toggle old-render-code help-links on click-event + + + // $('[id*="HELP-QDLtrigger"]').on('click',{renderedBy: 'dc'}, stdToggleDialogOnEvent); //TOGGLE help-status-icon on click-event $('.ui-button').on('click',stdHandleUiButton); });//END: document ready function stdHandleTabIndex(pmAllHelps){ logHelpLinksLog('L#63 stdHandleTabIndex()'); var i; for(i=0; i=0) ? src : src.replace('.png','-focus.png') ; $('.passive-link',this).attr('src',src); } //EXISTING active-link icon if($('.active-link',this).attr('src')!=undefined) { //Add '-focus.png' if it doesn't exist src = $('.active-link',this).attr('src'); src = (src.indexOf('-focus')>=0) ? src : src.replace('.png','-focus.png') ; $('.active-link',this).attr('src',src); } }).on('blur',function(){ $(this).removeClass('focusedByTab'); var src = $('.passive-link',this).attr('src').replace('-focus.png','.png'); $('.passive-link',this).attr('src',src); src = $('.active-link',this).attr('src').replace('-focus.png','.png'); $('.active-link',this).attr('src',src); }); } function stdCleanStr(pmStr){ /************************* stdCleanStr() ************************* * Remove
and
tags from the beginning and end of the given string (pmStr) * RETURN clean string ** * pmStr (string) ****************************************************************/ logHelpLinksLog('L#127 stdCleanStr()'); //REMOVE
at the beginning of the string pmStr = pmStr.replace(/^
/, ''); //REMOVE
at the end of the string pmStr = pmStr.replace(/<\/div>$/, ''); //REMOVE
and
and
at the beginning of the string pmStr = pmStr.replace(/^
/, ''); pmStr = pmStr.replace(/^/, ''); pmStr = pmStr.replace(/^
/, ''); //REMOVE
and
and
at the end of the string pmStr = pmStr.replace(/
$/, ''); pmStr = pmStr.replace(/$/, ''); pmStr = pmStr.replace(/
$/, ''); return pmStr; }//END: stdCleanStr() function stdHandleUiButton(pmEvent){ /************************* stdHandleUiButton() ************************* * GET the help-link (dom-object) through the help-text id in target's parent * TOGGLE the icons of the help-link (IF they exist) ** * pmEvent (event) ** * BD150107.V1.0 ****************************************************************/ logHelpLinksLog('L#158 stdHandleUiButton()'); var e_target = pmEvent.srcElement || pmEvent.target; var e_parent = $(e_target).closest('.ax-dialog'); var help_txt = $('.ui-dialog-content',e_parent); var help_txt_id = (help_txt!=undefined)?$(help_txt).attr('id'):''; //TRANSFORM help_txt id to help_link id (on basis of id-syntax) var t_link_id = ''; if( (help_txt_id!=undefined)? help_txt_id.indexOf('QDLdialog')>=0 : false) { t_link_id = '#' + help_txt_id.replace("QDLdialog","QDLtrigger"); } else if( (help_txt_id!=undefined)? help_txt_id.indexOf('dc-rendered-help')>=0 : false) { t_link_id = '#' + help_txt_id.replace("dialog","trigger"); } else { t_link_id = '#' + help_txt_id + '-trigger'; } //TOGGLE icons of help_link (DOM-OBJECT) stdToggleHelpIcons($(t_link_id)); }//END: stdHandleUiButton() function stdPrepareDialog(pmTriggerId,pmDialogId) { /************************ stdPrepareDialog() ************************ * INITIALIZE help-text-dialog with given id (pmDialogId) * - not visible at first * REMOVE className 'hidden' from the help-text-dialog * - visibility is handled by dialog() now ** * pmTriggerId (string) the id of the help-link (INCLUDING #) * pmDialogId (string) the id of the help-text-dialog (INCLUDING #) ****************************************************************/ logHelpLinksLog('L#197 stdPrepareDialog()'); //INITIALIZE $(pmDialogId).dialog({ autoOpen:false, //NOT visible at first closeOnEscape: true, closeText:'Close', dialogClass: "ax-dialog", //CUSTOM ClassName added to dialog minHeight: 10, position: { my: "center+0 top+10", //Position to help-link of: $(pmTriggerId), //Position against help-link collision: "fit" //Shift the element away from the edge of the window When the positioned element overflows the window }, width: '80%' }); //REMOVE the className 'hidden' $(pmDialogId).removeClass('hidden'); }//END: stdPrepareDialog() function stdToggleDialogOnEvent(pmEvent) { /******************************** stdToggleDialogOnEvent() ******************************** * ONLY EXECUTE IF RENDEREDBY-VALUE IS DEFINED * TRANSFORM trigger-id to dialog-id on basis of the given 'renderedBy'-value * TOGGLE dialog with dialog-id ** * pmEvent (event) with extra pmEvent.data.renderedBy ********************************************************************************/ logHelpLinksLog('L#228 stdToggleDialogOnEvent()'); if(pmEvent.data.renderedBy!=undefined) { var dialog_id = '#' + $(this).attr('id').replace("-trigger",(pmEvent.data.renderedBy == 'dc')?"-dialog":"").replace('-QDLtrigger','-QDLdialog'); stdToggleDialog(dialog_id); stdToggleHelpIcons(this); } else { //LOG ERROR logDebugLog('helpLinks L#199 MISSING rederedBy value'); } pmEvent.preventDefault(); //BD170915:: Prevent selecting response while clicking the info text }//END: stdToggleDialogOnEvent() function stdToggleDialog(pmId) { /************************ stdToggleDialog() ************************ * CHECK if the dialog is open (visible) * CLOSE the dialog if it's open * OPEN the dialog if it's closed ****************************************************************/ logHelpLinksLog('L#251 stdToggleDialog()'); //DIALOG IS OPEN (visible) if($(pmId).dialog("isOpen")) { //CLOSE the dialog $(pmId).dialog("close"); } //DIALOG IS CLOSED (hidden) else { //OPEN the dialog $(pmId).dialog("open"); } }//END: stdToggleDialog() function stdToggleHelpIcons(pmObj){ /******************************** stdToggleHelpIcons() ******************************** * This function toggles icons at the start of help-link IF they exist (L#142) ** * pmObj (dom-object) the clicked help-link ** * BD150107.V1.0 *************************************************************************************/ logHelpLinksLog('L#227 stdToggleHelpIcons()'); //INIT var help_icons = $('img.help-status-icon',pmObj); //ALL help-status-icon images in this link var help_active_icon = {}; var help_passive_icon = {}; var class_name = ''; //HAS ICON-IMG if($(help_icons).length>0) { //GET ACTIVE AND PASSIVE ICON(S) -- SET EACH IN ASSOCIATED VARIABLE $(help_icons).each(function(i,e){ class_name = ($(e).attr('class')!=undefined)?$(e).attr('class'):''; //SET active-icon if(class_name.toLowerCase().indexOf('active-link')>=0 && $.isEmptyObject(help_active_icon)) { help_active_icon = e; } //SET passive-icon else if(class_name.toLowerCase().indexOf('passive-link')>=0 && $.isEmptyObject(help_passive_icon)) { help_passive_icon = e; } }); //BOTH ICONS EXIST if(!$.isEmptyObject(help_active_icon) && !$.isEmptyObject(help_passive_icon)) { //TOGGLE BOTH ICONS $(help_active_icon).toggle(); $(help_passive_icon).toggle(); } } }//END: stdToggleHelpIcons() function stdToggleSmallHelp(pmEvent) { /******************************** stdToggleSmallHelp() ******************************** * This function toggles help-text and help-link icons (IF they exist) ** * BD150107.V1.0 *************************************************************************************/ logHelpLinksLog('L#323 stdToggleSmallHelp()'); //TOGGLE help-link-icons stdToggleHelpIcons(this); //TOGGLE help-text $('span,div',this).toggle('slow'); pmEvent.preventDefault(); //BD170915:: Prevent selecting response while clicking the info text }//END: stdToggleSmallHelp() function stdTransformToHelpDialog(pmDomEl,pmIndex){ /************************ stdTransformToHelpDialog() ************************ * pmDomEl (object) Dom Element * pmIndex (integer) ***************************************************************************/ logHelpLinksLog('L#339 stdTransformToHelpDialog()'); //SPLIT this element || there should be 2 var help = $(pmDomEl).html(); help = (help.indexOf('HELPTXT:')>=0) ? help.split('HELPTXT:') : help.split('
'); //EXISTING help-link & help-text if(help.length == 2) { //SET the cleaned strings in the variables var help_title = stdCleanStr(help[0]); var help_text = stdCleanStr(help[1]); //REPLACE original help-txt (pmDomEl) with help-title || including an 'id' to use in the function to show the help-text (dialog) $(pmDomEl).replaceWith(''); //PLACE the help-text after the help-link || including an 'id' to use in the function to show the help-text (dialog) $('#help-dialog-trigger' + pmIndex).after(''); //Transform help-text to (pop-up) dialog stdPrepareDialog('#help-dialog-trigger' + pmIndex,'#help-dialog' + pmIndex); //SHOW help-link after all elemenet are in place $('#help-dialog-trigger' + pmIndex).show('slow'); }//END: EXISTING help-link & help-text //NO VALID SYNTAX USED else { //LOG ERROR TO CONSOLE logDebugLog("L#24(helpLinks) ERROR: No valid help-link syntax (.long-help object)"); logDebugLog(pmDomEl); }//END: NO VALID SYNTAX USED }//END: stdTransformToHelpDialog() // + + + LOG FUNCTIONS + + + // //DEFINE IF THE LOGS SHOULD APPEAR IN CONSOLE function logHelpLinksINFO(pmMsg) { if (true) { consoleLog('HELPLINK:: ' + pmMsg); } } function logHelpLinksDebugLog(pmMsg) { if (true) { consoleLog('DEBUG HELPLINK:: ' + pmMsg); } } function logHelpLinksDebugObj(pmObj) { if (true) { consoleDir(pmObj); } } function logHelpLinksLog(pmMsg) { if (false) { consoleLog('HELPLINK:: ' + pmMsg); } } function logHelpLinksObj(pmObj) { if (false) { consoleDir(pmObj); } } //Log string(s) to console IF the console exist if(typeof window.consoleLog != 'function') { window.consoleLog = function(e){ if(window.console && window.console.log){ window.console.log(e); } } } //Log object(s) to console IF the console exist if(typeof window.consoleDir != 'function') { window.consoleDir = function(e){ if(window.console && window.console.dir){ window.console.dir(e); } } } // - - - LOG FUNCTIONS - - - //