/* This is a simple jQuery plugin for showing a simple context menu popup when you click on the help button in Enterprise. */ (function ($, window, document, undefined) { // DIM var settings; // placeholder for settings so it can be accessed by all methods and private functions. // options var defaults = { HelpContextId: '', HelpContextType: 'general', cssClass: '', beforeShow: null }; var methods = { // init method init: function (options) { try { // set settings from passed in options settings = $.extend({}, defaults, options); var topicId = settings.HelpContextId; var helpContextType = settings.HelpContextType; var cssClass = settings.cssClass; // get element to act on. var helpButtons = $(this); // may be more than one. helpButtons.each(function(){ $(this).off('click').click(function (ev) { if ($('ul.helpPopup.helpPopup-menu').length > 0) hideMenu(); else showHelpMenu($(this), topicId, helpContextType, cssClass); ev.stopImmediatePropagation(); return false; }); }); } catch (ex) { console.log('equis.HelpPopup.nls.js init method - Error: ' + ex.message); } } // end methods }; // private functions function showHelpMenu(button, topicId, type, cssClass) { // grab custom class name to apply to elements if in settings. var classesAll = ''; if (cssClass.trim().length > 0) classesAll = ' ' + cssClass; // create menu var menu = $('') .hide() .appendTo('body') .click(function (ev) { hideMenu(); }); // get HelpContext help url var docLink = 'help/index.htm'; var FoundContextId = findHelpContextId(button, type); if (topicId != '') docLink += '?contextid=' + topicId; else if (FoundContextId.length > 0) docLink += '?contextid=' + FoundContextId; // create documentation menu option var documentationLi = $('
  • ').appendTo(menu); var documentationA = $('View Documentation').appendTo(documentationLi); // create help desk menu option var helpDeskLi = $('
  • ').appendTo(menu); var HelpDeskA = $('Get Help').appendTo(helpDeskLi); // create community center menu option var communityCenterLi = $('
  • ').appendTo(menu); var communityCenterA = $('Visit Community Center').appendTo(communityCenterLi); // beforeShow callback if (settings.beforeShow != null && typeof settings.beforeShow == 'function') { // have the "this" in the callback be the button element button.beforeShow = $.proxy(settings.beforeShow); // call the function button.beforeShow.call(menu); } // get width of current menu menu.show(); var menuWidth = menu.width(); menu.hide(); // get position var buttonTop = button.offset().top; var buttonLeft = button.offset().left; var buttonHeight = button.outerHeight(); var buttonWidth = button.outerWidth(); var popupLeft = buttonLeft + buttonWidth - menuWidth - 4; var popupTop = buttonTop + buttonHeight; // create a transparent overlay mask below the menu that clicking will remove the menu and the mask var closeMask = $('
     
    ').appendTo('body').click(hideMenu); // show menu menu.css({ display: 'block', left: popupLeft, top: popupTop }).show(); return false; } // this function finds teh HelpContextId if it is set associated with the element. function findHelpContextId(button, type) { var helpContextTypes = ['widgetSurface', 'widgetEditor', 'dashboardSurface', 'equisDialog']; if (helpContextTypes.indexOf(type) > -1) { var id = ''; // set default if not found // switch on type switch (type) { case 'widgetSurface': // Will look for "Help-Topic-Id" attribute in widget's control.ascx markup // The attribute needs to be in a top level div element in the user control .ascx markup, typically such as the Kalitte required update panel. // get widget user control containing div. // Up and down the tree to the 'div.x-panel-body', the classes are consistent, but then there are no classes consistent classes for the last to level of children. // But they are the first (actually only) div element children at each level. var widgetParent = button.parents('div.x-panel-tl').next('div.x-panel-bwrap').find('div.x-panel-body').children('div:first').children('div:first'); // try to find the topic id in the update panel var element = widgetParent.find('[Help-Context-Id]'); if (element.length > 0) { // found a div (update panel) with a "Help-Context-Id" attribute. id = $(element[0]).attr('Help-Context-Id'); // just grab first (if more than one element have this attribute) } break; case 'widgetEditor': // Will look for help-context-id attribure in widget's editor.ascx markup. Will also do special check if it is ./DashboardEditor/Editor.ascx markup var editorParent = button.parents('div.x-window-tl').next('div.x-window-bwrap').find('iframe').contents().find('#EditorControlContainer'); if (editorParent.children('div.dse-section').length > 0) { // This is a dashboard editor id = '10028'; // this is the topic id for the dashboord editor interface. } else { // This is a widget editor var element = editorParent.find('[Help-Context-Id]'); if (element.length > 0) { id = $(element[0]).attr('Help-Context-Id'); } else { // there is no specific topic Id currently associated with this widget type's editor. (May be there are no widget properties for this widget). id = '10133'; // this is the topci id for the widget editor interface. } } break; case 'dashboardSurface': var attr = button.attr('help-context-id'); if (typeof attr != 'undefined') { // this is a system dashboard id = attr; } break; case 'equisDialog': // Will look for help-context-id attribute in control's .ascx markup for the control that implements EQuIS Dialog var dialogParent = button.parent().parent().next().children('iframe').contents().find('#DialogPanel'); var element = dialogParent.find('[Help-Context-Id]'); if (element.length > 0) { id = $(element[0]).attr('Help-Context-Id'); } break; } return id; } // type not one of the expected helpContextTypes. Just return an empty string. else { return ''; } } function hideMenu() { $('ul.helpPopup.helpPopup-menu').remove(); $('div.helpPopup.helpPopup-closeOverlay').remove(); } $.fn.HelpPopup = function (methodOrOptions) { if (methods[methodOrOptions]) { return methods[methodOrOptions].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof methodOrOptions === 'object' || !methodOrOptions) { // Default to "init" return methods.init.apply(this, arguments); } else { console.error('Method ' + methodOrOptions + ' does not exist on equis.HelpPopup plugin'); } }; }(jQuery, window, document));