caa8bdb4ead55f717a545589f0428b2b8d63ecfb
[yaffs-website] / web / modules / contrib / devel / webprofiler / js / app / helpers.js
1 (function (drupalSettings) {
2
3   Drupal.webprofiler.helpers = (function () {
4
5     "use strict";
6
7     var escapeRx = function escapeRegExp(string) {
8         return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
9       },
10
11       repl = function replaceAll(string, find, replace) {
12         if (typeof string != 'string') {
13           return '';
14         }
15         return string.replace(new RegExp(escapeRx(find), 'g'), replace);
16       },
17
18       shortLink = function (clazz) {
19         if (!clazz) {
20           return null;
21         }
22         clazz = repl(clazz, '/', '\\');
23         var parts = clazz.split("\\"), result = [], size = (parts.length - 1);
24
25         _.each(parts, function (item, key) {
26           if (key < size) {
27             result.push(item.substring(0, 1));
28           } else {
29             result.push(item);
30           }
31         });
32         return result.join("\\");
33       },
34
35       abbr = function (clazz) {
36         if (!clazz) {
37           return null;
38         }
39
40         return '<abbr title="' + clazz + '">' + shortLink(clazz) + '</abbr>';
41       },
42
43       ideLink = function (file, line) {
44         if (!file) {
45           return null;
46         }
47
48         line = line || 0;
49
50         file = file.replace(drupalSettings.webprofiler.ide_link_remote, drupalSettings.webprofiler.ide_link_local);
51
52         return drupalSettings.webprofiler.ide_link.replace("@file", file).replace("@line", line);
53       },
54
55       classLink = function (data) {
56         var link = ideLink(data['file'], data['line']), clazz = abbr(data['class']), method = data['method'], output = '';
57
58         output = clazz;
59         if (method) {
60           output += '::' + method;
61         }
62
63         if (link) {
64           output = '<a href="' + link + '">' + output + '</a>';
65         }
66
67         return output;
68       },
69
70       printTime = function (data, unit) {
71         unit = unit || 'ms';
72         data = Math.round((data + 0.00001) * 100) / 100;
73         return data + ' ' + unit;
74       },
75
76       frm = function (obj, level) {
77         level = level || 0;
78         var str = '<ul class="list--unstyled list--level-' + level + ' list--flat">', prop;
79         if (typeof obj != 'object') {
80           return obj;
81         }
82         for (prop in obj) {
83           if (isInt(prop)) {
84             str += '<li>' + frm(obj[prop], level + 1) + '</li>';
85           } else {
86             str += '<li><span class="list-item--bold">' + prop + '</span>: ' + frm(obj[prop], level + 1) + '</li>';
87           }
88         }
89         return str + '</ul>';
90       },
91
92       isInt = function (value) {
93         var x;
94         return isNaN(value) ? !1 : (x = parseFloat(value), (0 | x) === x);
95       };
96
97     return {
98       frm: frm,
99       ideLink: ideLink,
100       shortLink: shortLink,
101       classLink: classLink,
102       printTime: printTime
103     }
104
105   })();
106
107 }(drupalSettings));