Dynamically add a css class to cytoscape node on the tap of the node using cytoscape.js - cytoscape.js

I am trying to add class on the tap of the node in cytoscape.js. Here is the link for the complete code:
https://stackblitz.com/edit/angular-kpnys1?file=src%2Fapp%2Fapp.component.ts
ngViewAfterInit function
cy.on("tap", "node", function(evt) {
var node = evt.target;
console.log("tapped " + node.id());
cy.nodes(node).classes("foo");
});
Tap works fine but it does not add any class to the node. Is that possible?

You'll have to use the correct method for that. Currently, your code calls node.classes(), which deletes all previous classes of the node (you basically overwrite the classes array of a node).
What you want to do: Use node.addClass("foo") and add an entry in your stylesheet:
{
selector: ".foo",
css: {
"background-color": "green"
}
}
The dot indicates a class, but you can specify even further. If you want to add the foo class only to parent nodes, change .foo to :parent.foo.
But aside that, your code acutally worked (kind of), the class was present when clicking on a node. Here is the edited version of your stackblitz, I added the mentioned changes and gave one parent element the class "bar". If you click on a parent, the node will change the background-color to green and log its current classes to the console:
stackblitz

Related

In TornadoFX, how can I separate layouts to different classes and then use them in builder?

For example, I want to have a TabPane, but I want to have tabs each in its separate class. Is there a way to make this work with the builder? I want to do something like this:
tabpane {
MyFirstTab()
MySecondTab()
etc.
}
On a general basis you add the root node from another View with the add command:
add(SomeView::class)
You can also inject a View and add it:
val someView: SomeView by inject()
override val root: borderpane {
center {
add(someView)
}
}
add is the same as doing this += someView. What happens here is that the framework find the root node of the View and appends it to the children property of the parent Node. It also knows about special containers like the BorderPane, so it does the right thing when you add something inside the center builder etc.
The TabPane however, takes Tab instances, which are not nodes. You need to add the tab using the tab builder and assign some content to it. The builders are smart enought to understand that if you do add inside a Tab, it should assign to the content property of the Tab. Therefore you can write:
tab("My First Tab") {
add(MyFirstTab::class)
}
Or if you already have an instance of the content you'd like to assign:
tab("My First Tab") {
add(myFirstTab)
}
The MyFirstTab class must be a View or Fragment.

I want JAWS to tell the user what kind of node they are in while navigating the dijit.Tree

We have a dijit.Tree that indicates a node type by using an icon. The icon is a unique indicator that tells the person this node is a "book" or a "DVD" or a "magazine" for example.
dijit renders the icon as a background image in CSS which we know screen readers do not see.
I tried overriding the getTooltip method to provide a tooltip saying "book" or "DVD". It successfully adds the "title" attribute to the "dijitTreeRow". If I mouse over the node, I see the text. This is not ever focused on when the user moves down to get from one node to the next.
When navigating the tree, the up and down arrows traverse the nodes. The span with the visible text is focused on and that string is read. You can see the dotted line focus as well as hear this with JAWS in the most basic of examples: https://dojotoolkit.org/reference-guide/1.10/dijit/Tree.html
What I have not been able to figure out is how to create an indicator that the screen reader will pick up on that will read "Book" alongside "The Great Gatsby".
Does anyone have any tips on how they made this dijit widget accessible for the screen reader when the images are an indicator that should be heard by the blind user?
The tree supports HTML labels, via setting the labelType property on the model you give it.
Assuming you don't want to change the store data (or override the getLabel method), you can reimplement dijit/Tree.getLabel and produce the HTML label, and wrap it with a span with an aria-label.
(code lifted from the dijit.Tree reference).
var myModel = new ObjectStoreModel({
store: myStore,
labelType: "html", // Hack to tell the tree node to render as HTML
query: {id: 'world'}
});
var tree = new Tree({
model: myModel,
getLabel: function(item) {
var label = this.model.getLabel(item);
// dojo.string
return dstring.substitute("<span aria-label='dvd ${0}'>${0}</span>", [label]);
}
});
If your data might contain HTML-ish characters that you don't want to render, escape the characters in getLabel too.

Sencha Touch DataView and highlighting a row when selected

I have a dataview list inside a container which is displaying items correctly inside the view. However, whenever I click on an item it isn't getting highlighted.
I've added this to the view containing the DataView list:
onItemTap: function (container, target, index, e) {
var me = this;
me.callParent(arguments); // WARNING: without this call, the row will not become selected
}
I've read that the item won't get selected if I don't have the above. I can see this event being fired ok too. If I debug through the Sencha Touch source code, I can see the CSS class x-item-selected is being added to the DIV wrapping the list item, but there is no highlighting of the row. This works fine on normal lists so what am I missing?
Updated CSS which seems to work.
.x-dataview .x-data-item.x-item-selected
{
border-top-color: #006bb6;
background-image: -webkit-linear-gradient(top, #0398ff, #007ad0 3%, #005c9d);
color: white;
}
By default Sencha Touch Dataview doesn't provide any highlighting. Add a background or something to .x-item-pressed or .x-item-selected class and you will get the desired effect.
How about setting the selectedCls in the config block?
see the following link for detailed information
http://docs.sencha.com/touch/2.2.1/#!/api/Ext.dataview.List-cfg-selectedCls

DojoX Mobile ListItem load HTML via AJAX and then remove from DOM

Let's say in a view I have a DojoX Mobile ListItem that is pulling an HTML view fragment into the DOM via AJAX and then transitioning to that view. Assume this is all working fine.
Now, I go back to the initial view that had that ListItem on it and click some other button that destroys that view node from the DOM. If I now click on that ListItem that previously loaded that view node into the DOM (which has now been removed), it will try to transition to a view that doesn't exist. It doesn't know that it has been removed.
Is there some type of way to tell a ListItem that it needs to fetch the HTML again because what was previously fetched no longer exists? I am not seeing anything about doing this in any documentation anywhere. I don't think a code sample is really necessary here, but I can provide a minimal one if necessary.
I went a different route and left the view exist in the DOM, and simply made a function that clears all sensitive data out of the view.
Okay, in this case, i guess you could hook the onShow function of your ListItem container(or any other onchange event). Create a listener for said handle to evaluate if your item needs reloading. Following is under the assumtion that it is the item.onclick contents showing - and not the label of your item which contains these informations
Or better yet, do all this during initialization so that your ListItem container will be an extended with custom onClick code.
Seems simple but may introduce some quirks, where/when/if you programatically change to this item, however here goes:
function checkItem() {
// figure out if DOM is present and if it should be
if( isLoggedIn() ) {
this.getChildren().forEach(function(listitem) {
if( dojo.query("#ID_TO_LOOK_FOR", listitem.domNode).length == 0 ) {
// this references the listItem, refresh contents.
// Note: this expects the listitem to be stateful, have no testing environment at time being but it should be
listitem.set("url", listitem.url);
}
});
}
}
Preferably, set this in your construct of the container for your ListItems
var listItemParent = new dojox.mobile.RoundRectList({
onShow : checkItem,
...
});
Or create listener
var listItemParent = dijit.byId('itemRegistryId');
// override onClick - calling inheritance chain once done
dojo.connect(listItemParent, "onClick", listItemParent, checkItem);

Dojo query on specific ContentPane in TabContainer

I have a TabContainer with different tabs (ContentPanes). I am loading each type dynamically when the user selects something from a tree. I would like to be able to run a certain JS function on the newly loaded ContentPane/Tab. So something in this form:
dojo.forEach(
dojo.query("select"),
function(selectTag) {
selectTag.disabled = true;
}
);
However, I only want to process this on the newly loaded ContentPane/Tab... so let's say given a ContentPane/Tab Dojo Object, how do I do a forEach/query on its content only?
Thanks
You can give dojo.query a second argument telling it in which DOM node to start looking. So if you have a ContentPane with id "fooTab", you can do:
dojo.forEach(dojo.query("select", "fooTab"),
function(selectTag) {
....
}
);
Now, technically, "fooTab" is the "dijit ID", but the dijit's/ContentPane's outermost DOM node will also have an id "fooTab". Perhaps not the kosher way, but it works.