ad3689de5ce33e9d83396c968999968fd5305482
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Popover.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/Popover
16 * API for popover windows powered by Twitter Bootstrap.
17 */
18 define(['jquery', 'bootstrap'], function($) {
19
20 /**
21 * the main popover object
22 *
23 * @type {{}}
24 * @exports TYPO3/CMS/Backend/Popover
25 */
26 var Popover = {
27 };
28
29 /**
30 * Initialize
31 */
32 Popover.initialize = function(selector) {
33 selector = selector || '[data-toggle="popover"]';
34 $(selector).popover();
35 };
36
37 /**
38 * Popover wrapper function
39 *
40 * @param {Object} $element
41 */
42 Popover.popover = function($element) {
43 $element.popover();
44 };
45
46 /**
47 * Set popover options on $element
48 *
49 * @param {Object} $element
50 * @param {Object} options
51 */
52 Popover.setOptions = function($element, options) {
53 options = options || {};
54 var title = options.title || '';
55 var content = options.content || ' ';
56 $element
57 .attr('data-original-title', title)
58 .attr('data-content', content)
59 .attr('data-placement', 'auto')
60 .popover(options);
61 };
62
63 /**
64 * Set popover option on $element
65 *
66 * @param {Object} $element
67 * @param {String} key
68 * @param {String} value
69 */
70 Popover.setOption = function($element, key, value) {
71 $element.data('bs.popover').options[key] = value;
72 };
73
74 /**
75 * Show popover with title and content on $element
76 *
77 * @param {Object} $element
78 */
79 Popover.show = function($element) {
80 $element.popover('show');
81 };
82
83 /**
84 * Hide popover on $element
85 *
86 * @param {Object} $element
87 */
88 Popover.hide = function($element) {
89 $element.popover('hide');
90 };
91
92 /**
93 * Destroy popover on $element
94 *
95 * @param {Object} $element
96 */
97 Popover.destroy = function($element) {
98 $element.popover('destroy');
99 };
100
101 /**
102 * Toggle popover on $element
103 *
104 * @param {Object} $element
105 */
106 Popover.toggle = function($element) {
107 $element.popover('toggle');
108 };
109
110 Popover.initialize();
111 TYPO3.Popover = Popover;
112 return Popover;
113 });