Prevent my Elm app from crashing when a 3rd party changes the DOM - elm

I have an Elm app. A while ago I realized that my app was crashing locally when I used FontAwesome icons. I came to understand that it happened because I chose SVG icons and therefore FontAwesome was modifying the DOM. That conflicted with Elm's VDOM mechanism.
This was easy to fix--I migrated to the CSS version of FontAwesome that uses pseudo elements. Recently some users complained that the app in production freezes and they showed screenshots of states that were not matching the log data I had. It took a while until I realized that all these users had Google Translate automatically translated the page for them. Google Translate clearly alters the DOM, so I'm not surprised that it made Elm crash.
How can I prevent my Elm app from crashing? Is there a way to be notified if a 3rd party changes the DOM? So that I could even notify the user that they have an extension that interferes with the app.

I had the same problem as you and solved it by migrating to the Elm-FontAwesome library. Basically all you have to do is replace this syntax:
i [ Svga.class "fas fa-check" ] []
with this one:
Icon.viewIcon Icon.check
You can have a look to the example project for more details: https://github.com/Lattyware/elm-fontawesome-example

Have a look here - How we made Elm and Google Translate work together.
Their approach is to hijack the Elm replaceData method that is called by Elm during dom updates using the function below. You would run this just before giving Elm control of the dom.
HTMLFontElement.prototype.replaceData =
function replaceData(_0, _1, string) {
this.parentNode.replaceChild(
document.createTextNode(string),
this
);
};
Apparently, "Google Translate replaces every text node in the DOM with a tag containing at least one more tag – one for each sentence". For example:
<span>Insurello. Rätt ersättning till alla</span>
is translated into
<span><font><font>Insurello. </font><font>The right compensation for everyone</font></font></span>
This method avoids attempting to edit the span and instead replace it with a new one. Once the node is added, Google Translate will translate that text.

I don't know about preventing the crashes, but I think you should be able to register changes to the DOM with the current mutation observer API.
Before that were several deprecated mutation events like DOMSubtreeModified that could also help, but well they are deprecated.

This problem is very closely linked to that of Google Maps or Google Places Autocomplete in Elm. The solution I've used in the past is to provide a childless div with an id I can point to from JavaScript.
Because the div is childless, Elm does not look under the hood to check whether it has changed internally.
Check out this blog post or google "maps in elm" for instructions on how to do this
-- EDIT --
Ive read the question better and this will probably not work for Google translate issues as it changes all text in the entire DOM. Ill leave it here incase the question brings otger people who have more regular problems caused when a 3rd party changes the DOM

Related

How do I modify Docusaurus appearances of the blog from a component library?

Creating Modified Blog Entries
I am new to React, and very much to Docusaurus, however, I've managed to get a decent looking DS site going. I am trying to capture some simple snippets to as "blog entries", just small factual snippets, etc. simple project summaries. I’ve hit the limit of the Docusaurus.config options and not sure how to expand the out of box components.
How do I begin to alter and edit Docusaurus to change the Blog page to be like "Cards" in component-speak? Ive seen some example in Infima, but not sure how to bridge that gap?
How can I easily replicate the Announcement Bar to also be at the bottom, like a Banner?
Thank You!
One possible arena for you to use is Bootstrap — specifically React-Bootstrap. They have a card component you could use where you link individual blog entries to that card. If you're comfortable with JavaScript, there's probably an automation you can build there, but hand-coded text is somewhat part and parcel with static-site generators.
If you want a different solution with the CSS code in your src file outright, CSSCodeLab has a React Card layout entry with an attached source code file. Some hand-coded text required, and not automatically integrated with a separate blog setup, but YMMV.
Otherwise Docusaurus' Showcase page does provide the card formatting. The source code for the page (coded at index.tsx) as well as the components are available.

Make input in program input value at website

I want a function in my JavaFX 2.0 program that takes user input and forwards it to a websites textfield, and then get the value the website returns. The website would be a site to check if the warranty for a spesific program is valid.
All the user would need to input is reg. ID and maybe program brand.
I'm just looking for ideas on how to do this, links or even code would be superb. I suspect it won't require that much code, but hey.. i've been surprised before!
Thanks! :)
A possible implementation algorithm:
Load the warranty check page in the WebView.
Monitor the webEngine.documentProperty to check for when the load has finished.
When the load has finished, use webEngine.executeScript to set the text field to the
required value and submit the form.
EITHER
a. monitor the webEngine.documentProperty some more, and, when the document has loaded, inspect the document (using either JavaScript or Java) to see if the warranty is valid.
OR
b. change the resultant warranty display page to call back into Java and notify your app of the warranty status.
Some background info
If you have control over the website page contents, then your implementation may turn out easier. But I think you should still be able to get the result you want without modifying the website.
There were some additions to the recent JavaFX 2.1 release to facilitate callbacks from Javascript to Java. The webview documentation you want to read is the sections "Processing JavaScript Commands" using the webEngine.executeScript method and "Making Upcalls from JavaScript to JavaFX" using JSObject.setMember.
You might want to also take a look at a Sample DatePicker for JavaFX using jQuery UI example I wrote. It demonstrates various methods for loading html into a WebView, invoking functions on the WebView from Java and getting the results of user interactions with the WebView back into Java. Not exactly what you are looking for, but perhaps the ideas in it may help.
Another option you have is just to:
Accept the registration id in a JavaFX control.
Create a java.net.URL and post to the webserver from your java app directly without using a WebView.
Parse the response from the webserver to extract out whether the warranty is valid.
This is the approach I might take for such a task - eliminating the use of WebView completely.

Standalone video control example for Google TV jQuery Library?

The jQuery VideoControl is documented here:
https://developers.google.com/tv/web/lib/jquery/#gtv.jq.VideoControl
It takes a set of VideoParms. That are not specified.
It is used in the sample templates on this page:
https://developers.google.com/tv/web/docs/gtv-templates
I've taken apart the templates, but I'm having difficulty creating a simple example of a standalone video control. In the templates, the sidenav and carousel code are tied to how the videocontrol works. There is a relationship between the keyController and behavior (behaviorZones) that I can not find an explanation for.
Is there a standalone example somewhere? What needs to be setup with keycontroller, css, and behavior to get this going?
I'm not aware that there is a standalone videocontrol.js sample but it should be possible to set it up. Most of the necessary pieces are inside videocontrol.js, in particular in the videocontrol's constructor and this function: gtv.jq.VideoControl.prototype.makeControl.
keycontroller mapping is used to handling key inputs and some of the CSS are dynamically controlled within JS so there might be errors if you just rip them apart straight from the Template. You'd have to debug it using a solid tool like Chrome Developer Tools. You can watch tutorials of this tool here: http://www.youtube.com/results?search_query=chrome+developer+tools&oq=chrome+develop&aq=0&aqi=g3g-m2&aql=&gs_sm=3&gs_upl=1972l4015l0l6142l14l11l0l0l0l0l207l1476l3.5.3l11l0
Otherwise please send your error traces and/or code snippet for debugging help.
S

Very confused by a binding issue between a Cocoa app and a Movie Loader patch in Quartz Composer

I've been programming for a while, but just recently decided to start developing for Mac OS X. I feel like I've come to grips with the basics of Objective-C and Cocoa development over the past week. I'm planning on making graphics apps, and as such am currently in the process of learning how to control Quartz compositions through a Cocoa app. I went through the tutorial that apple offers (with the Mac Engravings composition), and was able to create that just fine. In order to make sure that I truly understood what I learned, I decided to create my own composition and link it to a slightly more complicated Cocoa application.
Essentially, I have a composition that loads a movie or image through a Movie Loader patch, at which point it applies various filters to the frames before outputting it. In my Cocoa app, I've written code (or rather copied and pasted from other apple examples) that lets a user pick a file using an NSOpenPanel object. The filepath of the file they pick gets placed in a text-box that I placed in the app's window using Interface Builder. I binded the value of said text-box to the "Movie_Location" key in my composition, which is a published input in the Movie Loader patch that I'm using. However, no matter what I do, movies and images aren't loaded into this composition no matter what I try. The only thing that gets displayed is the default image that I have saved in that input from Quartz Composer (or nothing if I leave it blank before publishing).
I've added a Clear Color patch to the composition and binded that to a colorwell in my UI, and that successfully changes the color in my display, so I know that the composition and my Cocoa app are communicating. I've spent numerous hours at this point trying to figure out what's going on, and I've just about given up. Does the Movie Loader have any weird behaviors that I'm not aware of, or is there something obvious that I seem to be missing? I'd really appreciate any help or advice from anybody.
Thanks for reading through this...
Best,
Sami
There are two things I can think of as reasons why it is doing this:
The file path isn't formatted incorrectly. Try checking backslashes, colons, etc.
The box isn't updating the value. Try literally clicking in the text field and hitting enter.
That's all I can think of without seeing your quartz composition and/or code.
EDIT:
Check the other continuous box, in the general properties.
I figured this out yesterday. spudwaffle's second idea is what was going on. If I were to type a filepath in and hit enter, it would work just fine. I got this to work properly by just removing the bind and instead using the setValue:keyInPath: function that a patch controller offers. That said, is there some way to force a text-box to update? I remember seeing a "continuously update" or something like that button within the bind sub-menu in the inspector, but my code didn't work with that checked either.
Thanks to those of you that tried to help me! I really appreciate it.
Best,
Sami

Problems Embedding Video using FCK Editor

I am using FCK Editor 2.6.4 and having problems trying to embed a (non-YouTube) video into a content area.
I found this previous question / post:
[EDIT -- as a new user, I am only able to post one link in this post. The post in question is titled, "Can I embed video using FCK Editor?")
and have investigated all of the proposed solutions, but none of them work properly:
1 -- Using the "Embed Flash" button in the control panel almost works. However, the video I am attempting to add contains a querystring with parameters, like this:
http://static.animoto.com/swf/w.swf?w=swf/vp1&e=1275795594&f=mGQklEgxXKs9vfEIdGnWsA&d=132&m=p&r=w&i=m&ct=Homes%20in%20Eagle%20Creek&cu=http://hometoindy.com/eagle-creek-real-estate.php&options=
and in using the Flash embed tool, it encodes all of the "&" characters to "& amp;", thus breaking them. If it were just for me, I could manually change them back, but clients who use this will not know how to do that.
2 -- I have installed the YouTube video plugin, and it works great... for YouTube. But it cannot be used to embed non-YouTube videos (it automatically changes the URL to YouTube, no matter what).
3 -- I have installed the EmbedMovies plugin, but it throws a javascript error when attempting to add a video file (such as the above) to a page. (The EmbedMovies plugin page on SourceForge says it has been updated for FCK Editor 2.6, but it does not work.)
4 -- Pasting directly into the editor window (of course) does not work. The only way I've been able to make this work is by pasting into the Source panel, and this is not a good option for clients who are not familiar with HTML.
So, is there a good, working plugin for FCK editor that will allow me to quickly and easily embed a video such as the one above into a content area? I don't need to be able to see or preview it in the editor window; I just need it to work when the page is loaded on the front end.
Thanks!
Given the question you found, and scarcity of answers to that, chances are that the plugin you want does not exist.
If your videos are actually from one, though non-standard, source, I can only repeat my advice from that topic - write your own plugin. I have code of plugin I wrote linked there, it should be easy to change it to accomodate your needs.