XLink Property in SVG textPath Nodes

Ran into a problem today with attempting to manipulate textPath SVG elements within the DOM. Consider the following, where the variable svg is an SVG element in your DOM: var g = document.createElementNS(“http://www.w3.org/2000/svg”, “g”); var label_container = document.createElementNS(“http://www.w3.org/2000/svg”, “text”); var label = document.createElementNS(“http://www.w3.org/2000/svg”, “textPath”); label.setAttributeNS(“http://www.w3.org/1999/xlink”, ‘xlink:href’, ‘#some-path’); label.appendChild(document.createTextNode(“Hello, World!”)); label_container.appendChild(label); …

Building an iPhone/Android Web App Using the Sliding-Pane Component

In today’s blog, I’m going to show how I used the Sliding-Pane to create a fairly complete iPhone application.   You can download the code here. Background In November, I created a UI component called Sliding-Pane that creates a sliding-type animation on a specific div. The idea came from OSX’s …

How to Get the Name of an Instance of a Class in Javascript

I was using JSONP (note that I prefer CORS but this was a special case where CORS wasn’t possible) and wanted an object that needed to call a method within itself. As you know, JSONP involves adding a script tag to the DOM which will return the JSON data encapsulated …

How to Wrap an Element Within a New Element Using Javascript

Here’s a simple way of wrapping an HTML fragment that exists in the DOM within another element, in this case a div: var wrapper = document.createElement(‘div’); wrapper.id = ‘the-wrapper’; wrapper.appendChild(document.querySelector(‘#the-html-fragment’)); At this point, the HTML fragment that was selected via the #the-html-fragment selector was removed from the DOM and attached …

How to Get the Current Script’s Parent in Javascript

The following is a method of getting the current script’s parent, which may be useful if, for example, you need to append HTML in the same location as the script: var scripts = document.getElementsByTagName(‘script’); parent = scripts[scripts.length – 1].parentNode; The above code maintains the assumption that the currently executing script …

Javascript Object Class Literal vs. Constructor

Something I dug up while learning Javascript a long, long while ago. Here’s is an interesting article on the differences between a literal class declaration and a constructor. Essentially, the main difference is that with a literal class declaration, the object itself as well as its properties and methods are …

WordPress Disqus Popular Threads Widget Using Pure Javascript (Updated)

WpDisqusPt, or WordPress Disqus Popular Threads Widget, is a small script that you can drop into a Text Widget in WordPress. This widget shows which threads on your site are the most commented on, similar to Engadget’s old Most Commented widget. UPDATE 04-12-2013: WpDisqusPt is now on GitHub! https://github.com/ronaldcs/wp-disqus-pt UPDATE …