Welcome to mirror list, hosted at ThFree Co, Russian Federation.

attributes.js « directives « common « angularjs « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c59d71cc2366dfe13043a11add8e840463552e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*!
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

/**
 * If the given text or resolved expression matches any text within the element, the matching text will be wrapped
 * with a class.
 *
 * Example:
 * <div piwik-autocomplete-matched="'text'">My text</div> ==> <div>My <span class="autocompleteMatched">text</span></div>
 *
 * <div piwik-autocomplete-matched="searchTerm">{{ name }}</div>
 * <input type="text" ng-model="searchTerm">
 */
(function () {
    angular.module('piwikApp.directive').directive('piwikAttributes', piwikAttributes);

    piwikAttributes.$inject = ['$sanitize'];

    function piwikAttributes(piwik, $sanitize) {

        return {
            link: function (scope, element, attrs) {
                if (!attrs.piwikAttributes || !angular.isString(attrs.piwikAttributes)) {
                    return;
                }

                function applyAttributes(attributes)
                {
                    if (angular.isObject(attributes)) {
                        angular.forEach(attributes, function (value, key) {
                            if (angular.isObject(value)) {
                                value = JSON.stringify(value);
                            }

                            // replace line breaks in placeholder with big amount of spaces for safari,
                            // as line breaks are not support there
                            if (key === 'placeholder' && /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
                                value = value.replace(/(?:\r\n|\r|\n)/g, (new Array(200)).join(' '));
                            }

                            if (key === 'disabled') {
                                element.prop(key, value);
                            } else {
                                element.attr(key, value);
                            }
                        });
                    }
                }

                applyAttributes(JSON.parse(attrs.piwikAttributes));

                attrs.$observe('piwikAttributes', function (newVal) {
                    applyAttributes(JSON.parse(newVal));
                });

            }
        };
    }
})();