Skip to content

Commit 2b26fc3

Browse files
committed
shortenValueGrip has been introduced in Fx38, support also Fx36
1 parent c2f135a commit 2b26fc3

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/jquery-renderer.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {})
1414
const { Widgets } = devtools.require("devtools/webconsole/console-output");
1515
const { VariablesView } = Cu.import("resource:///modules/devtools/VariablesView.jsm", {});
1616

17+
// Platform
18+
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
19+
1720
const XHTML_NS = "http://www.w3.org/1999/xhtml";
1821

1922
/**
@@ -57,7 +60,10 @@ var JQueryRenderer = {
5760
emptySlots = 0;
5861
}
5962

60-
let shortVal = this.message.shortenValueGrip(item);
63+
// shortenValueGrip API has been introduced in Firefox 38
64+
let shortVal = this.message.shortenValueGrip ?
65+
this.message.shortenValueGrip(item) : shortenValueGrip();
66+
6167
let elem = this.message._renderValueGrip(shortVal, { concise: true });
6268
this.element.appendChild(elem);
6369

@@ -122,6 +128,29 @@ var JQueryRenderer = {
122128
}
123129
};
124130

131+
// Helpers
132+
133+
/**
134+
* Can be removed when Firefox 38 (Fx38) is the minimum required version.
135+
*/
136+
function shortenValueGrip(grip) {
137+
let MAX_STRING_GRIP_LENGTH = 36;
138+
let ELLIPSIS = Services.prefs.getComplexValue("intl.ellipsis",
139+
Ci.nsIPrefLocalizedString).data;
140+
141+
let shortVal = grip;
142+
if (typeof(grip)=="string") {
143+
shortVal = grip.replace(/(\r\n|\n|\r)/gm," ");
144+
if (shortVal.length > MAX_STRING_GRIP_LENGTH) {
145+
shortVal = shortVal.substring(0, MAX_STRING_GRIP_LENGTH - 1) + ELLIPSIS;
146+
}
147+
}
148+
149+
return shortVal;
150+
}
151+
152+
// Registration
153+
125154
Widgets.ObjectRenderers.add(JQueryRenderer);
126155

127156
// Exports from this module

0 commit comments

Comments
 (0)