Attribute key value object [duplicate] - polymer

This question already has answers here:
Getting the list of polymer published properties
(2 answers)
Closed 6 years ago.
I'm looking for a way to determine what attributes a polymer element has without interacting with the attributes directly. I stumbled upon this.attributes accidentally and it does contain all the information that I need It's just not very pretty. I was wondering if there was a simple attributes object that existed already. Something simple like this.
{
"src": "http://stackoverflow.com/image.jpg",
"alt": "stackoverflow"
}
Here's how you'd convert it using underscore, it's a little ugly.
this.attr_obj = _.extend.apply(null, _.map(this.attributes, function(attribute){
var temp = {};
temp[attribute.name] = attribute.value;
return temp;
}));

Found the answer in another post.
It's best to use element.publish to get the list of published properties for an element. (In polymer 1.0 element.properties does the same).
element.getAttribute('attributes) won't include the publish properties that are setup in a publish block.

Related

Copying ListItems with inline image and text formatting from one document to another [duplicate]

This question already has answers here:
List item numbers don't transfer to new document
(1 answer)
AppendListItem with Correct GlyphType
(2 answers)
How can I append bullets and subbullets in Google Apps Script for Google docs when iterating through an array?
(1 answer)
How to copy ListItems from one Google Document to another while preserving numbering?
(2 answers)
What's the preferred way to insert a bulleted list into a Google Doc?
(1 answer)
Closed 2 years ago.
In an attempt to reduce hours of repetitive labor, I've tried to create a Google app script that appends various template documents in sequence. The method for doing this uses Google DocumentApp to append various elements from multiple template documents to a single new document. This works with all element types except List Items.
The DocumentApp copies list items from one GDoc to another but the new bullets appear with no visible glyph/bullet/number and there are various formatting issues. I've tried manually setting the Glyph Type, as recommended by similar SO posts, but the indentation has issues -- when you adjust the indent on the new bullet, it does not follow the usual pattern of shift in/shift out when clicking tab/shift-tab. When simply using appendListItem, the invisible glyph outcome is not consistent.
When copying the template GDocs to a newly created GDoc, the glyphs do not appear. When copying to an already existing GDoc (tested multiple times using docs with unknown and inconsistent usage history), the glyphs sometimes appear. I suspect the issue is with the appendListItem() or .copy() -- both are used in the script:
An excerpt from the script being used:
thisBody.appendListItem(templateBody.getChild(i).copy());
I've spent hours researching workarounds and causes for this issue to no avail. It seems to be a known issue that has not been resolved. Please advise. Is there some mistake I'm making?
Respectfully,
-J
Full code below:
function appendTemplate(templateID) {
var thisDoc = DocumentApp.getActiveDocument();
var thisBody = thisDoc.getBody();
var templateDoc = DocumentApp.openById(templateID); //Pass in id of doc to be used as a template.
var templateBody = templateDoc.getBody();
// Insert a Page Break between sections
thisBody.appendPageBreak();
// Append all body sections
// Reference: https://stackoverflow.com/questions/54817801/google-docs-script-to-insert-another-document
for(var i=0; i<templateBody.getNumChildren();i++){ //run through the elements of the template doc's Body.
switch (templateBody.getChild(i).getType()) { //Deal with the various types of Elements we will encounter and append.
case DocumentApp.ElementType.PARAGRAPH:
thisBody.appendParagraph(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.LIST_ITEM:
thisBody.appendListItem(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.TABLE:
thisBody.appendTable(templateBody.getChild(i).copy());
break;
case DocumentApp.ElementType.INLINE_IMAGE:
thisBody.appendImage(templateBody.getChild(i).copy());
break;
}
}

Rendering to another html page [duplicate]

This question already has answers here:
How can I display a JavaScript object?
(40 answers)
Closed 7 years ago.
I have an object of objects and I want to iterate through the objects and show them in the browser; I have the following code, but it just shows me [object Object][object Object][object Object]; how can I show the actual objects?
my my_obj looks like:
{
"User": {
"description": "A user."
},
"Media": {
"description": "A media ."
}
}
var output = "";
for (var key in my_obj) {
output += my_obj[key];
}
response.send(output);
Thanks
It looks like this question is essentially a duplicate of yours.
The accepted answer for that question uses the console object to print the contents of the object to the JavaScript debugging console in the browser's developer tools (usually accessible with F12). You can typically interact with the object, expanding and collapsing its properties, in the logged output in the console.
console.log(my_obj);
However, this doesn't provide an easy way to print the contents of the object to the webpage. For that, you can follow the above-linked question's highest-voted answer, which uses the JSON object, specifically it's stringify method.
var my_obj_str = JSON.stringify(my_obj);
This method returns a stringified version of your object (i.e. it will appear like an object literal), which can then either be logged to the console like above (although it would be a string, not an interactive object!), or put into the webpage in whatever manner you like putting strings into webpage content.
You might need to use JSON.stringify() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Retrieving map of attributes in DOM 4

Historically in the XML DOM for any Element one can call element.getAttributes() which will return a NamedNodeMap. This map allows you to iterate the Node instances, which in this case are Attr instances describing each attribute.
But when reading MDN's description of the node type enumerated value for Node.ATTRIBUTE_NODE, they say:
An Attribute of an Element. Attributes no longer implement the Node interface as of DOM4.
Are they talking about Attr? But if Attr does not implement Node in DOM 4, what does element.getAttributes() return? A NamedNodeMap of nodes that are not instances of Attr?
Or does Element not have a element.getAttributes() method at all in DOM 4? If not, how does DOM 4 let me iterate through all the attributes? And is the code I'm writing in Java 11 using element.getAttributes() therefore eventually going to be out of date? And the same thing for JavaScript code I write in the browser?
There's various points here.
DOM4 does indeed not contain a getAttributes() method on Element. It does, however, have a property called attributes which on accessing returns a NamedNodeMap.
"NamedNodeMap" seems a slightly misleading name since its items are Attr objects.
MDN is out of date. Earlier versions of the Attr interface in the DOM4 standard did not extend the Node interface, but it was found not to be web-compatible, and so now the current definition of Attr does, just as DOM3 did.

How to handle testing an HTML control that lacks sufficiently unique attributes?

I'm using Coded UI Test to test a web application.
I have a class Locator that I use to stash the specifics needed for CUIT to find a control. To operate on a control, a page object specifies the locator, not the control, and lower-level functions find the control and perform the operation.
Right now, my class has:
Locator name.
One or more attrName/attrValue pairs that can locate the HTML element for the control.
An operator (Contains or EqualTo) that specifies the matching needed.
The problem: Some of the controls I need to operate on don't have enough unique attributes to allow them to be found. (Yes, I know the developers should improve their HTML, but I don't control that.) I have been using a locator to find a nearby element, then "walking" in the DOM to get to the element I want. I hate having this DOM-walking code in my page object, even factored into a function.
A possible solution: I'm considering enhancing class Locator so that it can have either the attrName/attrValue pairs or a reference to a function that has the DOM-walking code. One advantage of this is that the page objects would always use a locator object. Another is that when the HTML is improved, the locator could change from DOM-walking code to attrName/attrValue pairs, which would be transparent to the page object.
Still, I think this may be over-complicated.
Is there a better solution to this problem?
Not sure specifically how your locator works, but could you find the closest parent to that object, let's say an HTML Div with an id of "parent", and then count the tag instances underneath? For example:
HtmlDiv id="parent">
HtmlHyperlink>text1</
HtmlHyperlink>text2</
Would require the following code:
public HtmlHyperlink text2Link
{
get
{
HtmlDiv parentDiv = new HtmlDiv(browser);
parentDiv.SearchProperties["id"] = "parent";
HtmlHyperlink target = new HtmlHyperlink(parentDiv);
target.SearchProperties["TagInstance"] = "2";
}
}
This would find the 2nd hyperlink under the parent object. (Tag instances are not zero based).
Then, you'd just interact with your object as needed:
Mouse.Click(text2Link);
for example.

Places autocomplete by lodging and location types

I want Googles autocomplete suggestion to only list lodgings and locations. I've mostly been trying to get the lodging type to work however no suggestions ever appear.
When I remove ac_options from the autoComplete variable everything works fine but ofcourse none of the suggestions are narrowed down by a specific type.
var ac_options = {
types: ['lodging']
};
var input = document.getElementById(this.options.autoCompleteInputId);
var autocomplete = new google.maps.places.Autocomplete(input, ac_options);
//bind to input field
autocomplete.bindTo('bounds', this.gmap);
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted.
I don't think lodging is valid option, as per following link...
https://developers.google.com/maps/documentation/javascript/places#places_autocomplete
You should try following instead...
https://developers.google.com/maps/documentation/javascript/examples/places-queryprediction
in place of "pizza near" in example use "lodging"...:)