3196e86e24ba30478a68589ed69526ee72a4a094
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / contexthelp.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Steffen Kamper <steffen@typo3.org>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 Ext.ns('TYPO3', 'TYPO3.CSH.ExtDirect');
28
29 /**
30 * Class to show tooltips for links that have the css t3-help-link
31 * need the tags data-table and data-field (HTML5)
32 */
33 TYPO3.ContextHelp = function() {
34
35 /**
36 * Tooltip
37 * @type {Ext.ToolTip}
38 */
39 var tip;
40
41 /**
42 * Cache for CSH
43 * @type {Ext.util.MixedCollection}
44 */
45 var cshHelp = new Ext.util.MixedCollection(true);
46
47 return {
48 /**
49 * Constructor
50 */
51 init: function() {
52 tip = new Ext.ToolTip({
53 title: 'TYPO3 CSH',
54 html: '',
55 anchorToTarget: true,
56 width: 160,
57 renderTo: Ext.getBody(),
58 cls: 'typo3-csh-tooltip',
59 dismissDelay: 3000, // auto hide after 3 seconds
60 showsDelay: 2000, // show after 2 seconds
61 listeners: {
62 'render': function(){
63 this.body.on('click', function(e){
64 e.stopEvent();
65 top.TYPO3.ContextHelpWindow.open(this.cshLink);
66 }, this);
67 }
68 }
69
70 });
71 Ext.select('div').on('mouseover', TYPO3.ContextHelp.showToolTipHelp, TYPO3.ContextHelp, {delegate: 'a.t3-help-link'});
72 Ext.select('div').on('click', TYPO3.ContextHelp.openHelpWindow, TYPO3.ContextHelp, {delegate: 'a.t3-help-link'});
73 },
74
75 /**
76 * Shows the tooltip, triggered from mouseover event handler
77 *
78 * @param {Event} event
79 * @param {Node} link
80 */
81 showToolTipHelp: function(event, link) {
82 event.stopEvent();
83 var table = link.getAttribute('data-table');
84 var field = link.getAttribute('data-field');
85 var key = table + '.' + field;
86 var element = Ext.fly(link);
87 var response;
88
89 tip.target = element;
90
91 if (response = cshHelp.key(key)) {
92 tip.body.dom.innerHTML = response.description;
93 tip.cshLink = response.id;
94 tip.setTitle(response.title);
95 tip.showBy(element, 'tl-tr');
96 } else {
97 TYPO3.CSH.ExtDirect.getContextHelp(table, field, function(response, options) {
98 cshHelp[table + '.' + field] = response;
99 tip.body.dom.innerHTML = response.description;
100 tip.cshLink = response.id;
101 tip.setTitle(response.title);
102 cshHelp.add(response);
103 tip.showAt(event.getXY());
104 }, this);
105 }
106 },
107
108 /**
109 * Opens the help window, triggered from click event handler
110 *
111 * @param {Event} event
112 * @param {Node} link
113 */
114 openHelpWindow: function(event, link) {
115 var id = link.getAttribute('data-table') + '.' + link.getAttribute('data-field');
116 event.stopEvent();
117 top.TYPO3.ContextHelpWindow.open(id);
118 }
119 }
120
121 }();
122
123 /**
124 * Calls the init on Ext.onReady
125 */
126 Ext.onReady(TYPO3.ContextHelp.init, TYPO3.ContextHelp);