[BUGFIX] Disable the "new shortcut" button
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / ContextHelp.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * Module: TYPO3/CMS/Backend/ContextHelp
16 * API for context help.
17 */
18 define(['jquery', 'TYPO3/CMS/Backend/Popover', 'bootstrap'], function($) {
19
20 /**
21 * The main ContextHelp object
22 *
23 * @type {{ajaxUrl: *, localCache: {}, helpModuleUrl: string, trigger: string, placement: string, selector: string}}
24 * @exports TYPO3/CMS/Backend/ContextHelp
25 */
26 var ContextHelp = {
27 ajaxUrl: TYPO3.settings.ajaxUrls['context_help'],
28 localCache: {},
29 helpModuleUrl: '',
30 trigger: 'click',
31 placement: 'auto',
32 selector: '.t3-help-link'
33 };
34
35 /**
36 * Initialize context help trigger
37 */
38 ContextHelp.initialize = function() {
39 ContextHelp.helpModuleUrl = (typeof top.TYPO3.settings.ContextHelp !== 'undefined') ? top.TYPO3.settings.ContextHelp.moduleUrl : null;
40 if (TYPO3.ShortcutMenu === undefined && top.TYPO3.ShortcutMenu === undefined) {
41 // @FIXME: if we are in the popup... remove the bookmark / shortcut button
42 // @TODO: make it possible to use the bookmark button also in popup mode
43 $('.icon-actions-system-shortcut-new').closest('.btn').hide();
44 }
45 var title = ' ';
46 if (typeof top.TYPO3.LLL !== 'undefined') {
47 title = top.TYPO3.LLL.core.csh_tooltip_loading;
48 } else if (opener && typeof opener.top.TYPO3.LLL !== 'undefined') {
49 title = opener.top.TYPO3.LLL.core.csh_tooltip_loading;
50 }
51 var $element = $(this.selector);
52 $element
53 .attr('data-loaded', 'false')
54 .attr('data-html', true)
55 .attr('data-original-title', title)
56 .attr('data-placement', this.placement)
57 .attr('data-trigger', this.trigger);
58 TYPO3.Popover.popover($element);
59
60 $(document).on('show.bs.popover', ContextHelp.selector, function(evt) {
61 var $me = $(this),
62 description = $me.data('description');
63 if (typeof description !== 'undefined' && description !== '') {
64 TYPO3.Popover.setOptions($me, {
65 title: $me.data('title'),
66 content: description
67 });
68 } else if ($me.attr('data-loaded') === 'false' && $me.data('table')) {
69 ContextHelp.loadHelp($me);
70 }
71
72 // if help icon is in DocHeader, force open to bottom
73 if ($me.closest('.t3js-module-docheader').length) {
74 TYPO3.Popover.setOption($me, 'placement', 'bottom');
75 }
76 });
77 $(document).on('shown.bs.popover', ContextHelp.selector, function(evt) {
78 var $popover = $(evt.target).data('bs.popover').$tip;
79 if (!$popover.find('.popover-title').is(':visible')) {
80 $popover.addClass('no-title');
81 }
82 });
83 $(document).on('click', '.tipIsLinked', function(e) {
84 $('.popover').each(function() {
85 var $popover = $(this);
86 if ($popover.has(e.target).length) {
87 ContextHelp.showHelpPopup($popover.data('bs.popover').$element);
88 }
89 });
90 });
91 $(document).on('click', 'body', function (e) {
92 $(ContextHelp.selector).each(function () {
93 var $triggerElement = $(this);
94 // the 'is' for buttons that trigger popups
95 // the 'has' for icons within a button that triggers a popup
96 if (!$triggerElement.is(e.target) && $triggerElement.has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
97 TYPO3.Popover.hide($triggerElement);
98 }
99 });
100 });
101 };
102
103 /**
104 * Open the help popup
105 *
106 * @param {Object} $trigger
107 */
108 ContextHelp.showHelpPopup = function($trigger) {
109 var configuration = top.TYPO3.configuration.ContextHelpWindows || top.TYPO3.configuration.PopupWindow;
110 try {
111 var cshWindow = window.open(
112 ContextHelp.helpModuleUrl +
113 '&tx_cshmanual_help_cshmanualcshmanual[table]=' + $trigger.data('table') +
114 '&tx_cshmanual_help_cshmanualcshmanual[field]=' + $trigger.data('field'),
115 'ContextHelpWindow',
116 'height=' + configuration.height + ',width=' + configuration.width + ',status=0,menubar=0,scrollbars=1'
117 );
118 cshWindow.focus();
119 TYPO3.Popover.hide($trigger);
120 return cshWindow;
121 } catch(e) {
122 // do nothing
123 }
124 };
125
126 /**
127 * Load help data
128 *
129 * @param {Object} $trigger
130 */
131 ContextHelp.loadHelp = function($trigger) {
132 var table = $trigger.data('table');
133 var field = $trigger.data('field');
134 // If a table is defined, use ajax call to get the tooltip's content
135 if (table) {
136 // Load content
137 $.getJSON(ContextHelp.ajaxUrl, {
138 params: {
139 action: 'getContextHelp',
140 table: table,
141 field: field
142 }
143 }).done(function(data) {
144 var title = data.title || '';
145 var content = data.content || '<p></p>';
146 TYPO3.Popover.setOptions($trigger, {
147 title: title,
148 content: content
149 });
150 $trigger
151 .attr('data-loaded', 'true')
152 .one('hidden.bs.popover', function() {
153 TYPO3.Popover.show($trigger);
154 });
155 TYPO3.Popover.hide($trigger);
156 });
157 }
158 };
159
160 ContextHelp.initialize();
161 TYPO3.ContextHelp = ContextHelp;
162 return ContextHelp;
163 });