Skip to content

Commit

Permalink
[TASK] Migrate Tooltip to TypeScript
Browse files Browse the repository at this point in the history
Change-Id: I7de5841838784f5f3062e0657c30b272c0be7670
Resolves: #82607
Releases: master
Reviewed-on: https://review.typo3.org/56224
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Łukasz Uznański <l.uznanski@macopedia.pl>
Tested-by: Łukasz Uznański <l.uznanski@macopedia.pl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
andreaswolf authored and maddy2101 committed Aug 5, 2018
1 parent d1ce4b2 commit 22de216
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
1 change: 1 addition & 0 deletions Build/types/TYPO3/index.d.ts
Expand Up @@ -17,6 +17,7 @@ declare namespace TYPO3 {
export let Severity: any;
export let ShortcutMenu: any;
export let Storage: any;
export let Tooltip: any;
export let Utility: any;
export const lang: any;
export const settings: any;
Expand Down
62 changes: 62 additions & 0 deletions typo3/sysext/backend/Resources/Private/TypeScript/Tooltip.ts
@@ -0,0 +1,62 @@
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

import 'bootstrap';
import * as $ from 'jquery';

/**
* The main tooltip object
*
* Hint: Due to the current usage of tooltips, this class can't be static right now
*/
class Tooltip {
constructor() {
$((): void => {
this.initialize('[data-toggle="tooltip"]');
});
}

public initialize(selector: string, options?: object): void {
options = options || {};
$(selector).tooltip(options);
}

/**
* Show tooltip on $element
*
* @param {Object} $element
* @param {String} title
*/
public show($element: JQuery, title: string): void {
$element
.attr('data-placement', 'auto')
.attr('data-title', title)
.tooltip('show');
}

/**
* Hide tooltip on $element
*
* @param {Object} $element
*/
public hide($element: JQuery): void {
$element.tooltip('hide');
}
}

const tooltipObject = new Tooltip();

// expose as global object
TYPO3.Tooltip = tooltipObject;

export = tooltipObject;
56 changes: 1 addition & 55 deletions typo3/sysext/backend/Resources/Public/JavaScript/Tooltip.js
Expand Up @@ -10,58 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/

/**
* Module: TYPO3/CMS/Backend/Tooltip
* API for tooltip windows powered by Twitter Bootstrap.
*/
define(['jquery', 'bootstrap'], function($) {
'use strict';

/**
* The main tooltip object
*
* @type {{}}
* @exports TYPO3/CMS/Backend/Tooltip
*/
var Tooltip = {};

/**
* Initialize
*/
Tooltip.initialize = function(selector, options) {
options = options || {};
$(selector).tooltip(options);
};

/**
* Show tooltip on $element
*
* @param {Object} $element
* @param {String} title
*/
Tooltip.show = function($element, title) {
$element
.attr('data-placement', 'auto')
.attr('data-title', title)
.tooltip('show');
};

/**
* Hide tooltip on $element
*
* @param {Object} $element
*/
Tooltip.hide = function($element) {
$element.tooltip('hide');
};

$(function() {
Tooltip.initialize('[data-toggle="tooltip"]');
});

// expose as global object
TYPO3.Tooltip = Tooltip;

return Tooltip;
});
define(["require","exports","jquery","bootstrap"],function(t,o,i){"use strict";var e=new(function(){function t(){var t=this;i(function(){t.initialize('[data-toggle="tooltip"]')})}return t.prototype.initialize=function(t,o){o=o||{},i(t).tooltip(o)},t.prototype.show=function(t,o){t.attr("data-placement","auto").attr("data-title",o).tooltip("show")},t.prototype.hide=function(t){t.tooltip("hide")},t}());return TYPO3.Tooltip=e,e});

0 comments on commit 22de216

Please sign in to comment.