-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* See license.txt for terms of usage */ | ||
|
||
"use strict"; | ||
|
||
module.metadata = { | ||
"stability": "experimental" | ||
}; | ||
|
||
const { Trace, TraceError } = require("../core/trace.js"); | ||
const { Domplate } = require("../core/domplate.js"); | ||
const { Rep } = require("./rep.js"); | ||
const { Reps } = require("./reps.js"); | ||
const { Locale } = require("../core/locale.js"); | ||
|
||
// Domplate | ||
const { domplate, SPAN, TAG, FOR } = Domplate; | ||
const { OBJECTLINK } = Rep.tags; | ||
|
||
/** | ||
* @rep | ||
*/ | ||
var NamedNodeMap = domplate(Rep, | ||
/** @lends NamedNodeMap */ | ||
{ | ||
className: "NamedNodeMap", | ||
|
||
tag: | ||
OBJECTLINK( | ||
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["), | ||
FOR("prop", "$object|longPropIterator", | ||
SPAN({"class": "nodeName"}, "$prop.name"), | ||
SPAN({"class": "objectEqual", role: "presentation"}, "$prop.equal"), | ||
TAG("$prop.tag", {object: "$prop.object"}), | ||
SPAN({"class": "objectComma", role: "presentation"}, "$prop.delim") | ||
), | ||
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]") | ||
), | ||
|
||
shortTag: | ||
OBJECTLINK( | ||
SPAN({"class": "arrayLeftBracket", role: "presentation"}, "["), | ||
FOR("prop", "$object|shortPropIterator", | ||
SPAN({"class": "nodeName"}, "$prop.name"), | ||
SPAN({"class": "objectEqual", role: "presentation"}, "$prop.equal"), | ||
TAG("$prop.tag", {object: "$prop.object"}), | ||
SPAN({"class": "objectComma", role: "presentation"}, "$prop.delim") | ||
), | ||
SPAN({"class": "arrayRightBracket", role: "presentation"}, "]") | ||
), | ||
|
||
supportsObject: function(grip, type) { | ||
return (grip.kind == "MapLike" && grip.preview); | ||
}, | ||
|
||
longPropIterator: function(object) { | ||
return this.propIterator(object, 100); | ||
}, | ||
|
||
shortPropIterator: function(object) { | ||
return this.propIterator(object, Options.get("ObjectShortIteratorMax")); | ||
}, | ||
|
||
propIterator: function (object, max) { | ||
max = max || 3; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SebastianZ
Member
|
||
|
||
var props = []; | ||
for (var i=0; i<object.length && i<max; i++) { | ||
var item = object.item(i); | ||
var name = item.name; | ||
var value = item.value; | ||
|
||
var rep = Firebug.getRep(value); | ||
var tag = rep.tag; | ||
|
||
props.push({tag: tag, name: name, object: value, equal: "=", delim: ", "}); | ||
} | ||
|
||
if (object.length > max) { | ||
var index = max - 1, more = object.length - max + 1; | ||
if (index < 1) { | ||
index = 1; | ||
more++; | ||
} | ||
|
||
props[index] = { | ||
object: more + " " + Locale.$STR("firebug.reps.more") + "...", | ||
tag: FirebugReps.Caption.tag, | ||
name: "", | ||
equal: "", | ||
delim: "" | ||
}; | ||
} | ||
else if (props.length > 0) { | ||
props[props.length-1].delim = ""; | ||
} | ||
|
||
return props; | ||
}, | ||
}); | ||
|
||
// Registration | ||
Reps.registerRep(NamedNodeMap); | ||
|
||
// Exports from this module | ||
exports.NamedNodeMap = NamedNodeMap; |
3 comments
on commit de26e8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid the property iterator duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'd like to avoid that too. Please create a new issue.
Honza
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this default, or if you for some reason want to keep it for some more generic propIterator function, use
function (object, max = 3)
instead.