jsPlumb anchors jump to their correct positions only after starting to draw

Standard

This foxed me for a while. I was setting up a connector-based UI using the excellent jsPlumb.

In jsPlumb, you declare elements to hold your endpoints, and then the endpoints are painted onto your elements according to anchors you specify. For example, you could set your anchor to the middle of the left side of your element, with the connector coming our of it towards the left.

This is all quite simple, but I spent hours trying to get it to work — whatever happened, the endpoints appeared in the wrong place. The frustrating part was that they would jump into the correct place after I started to draw connectors. So jsPlumb clearly couldn’t figure out the dimensions of the element when it was declared — only after I had started drawing.

It turns out that the problem was with jQuery UI tabs — the endpoints were inside a tab. Despite the tab being the default one and visible on page load, it was preventing jsPlumb from positioning endpoints correctly.

Once I had figured out that tabs were the culprit, the solution was really simple: Just call jsPlumb.repaintEverything(); whenever the tab is ‘shown’. This way all positions can be re-calculated when the page is set up and all elements are visible and in their final positions. I put the call to repaintEverything in the tabs’ show() event.

Simple dynamic ASP includes

Standard

I always end up never quite believing it when, once again, it dawns on me that I can’t complete a project the way I visualise due to ASP Classic’s lack of support for dynamic includes.

This time, I was creating a CMS-like site, which included mixed HTML/ASP files automatically. I tried pretty much every other solution — including server.execute (no go — doesn’t preserve variables/functions),  and other examples of using ASP’s execute() command to parse files (didn’t work for mixed HTML/ASP).

So, the only thing left was to write my own. It’s fairly simple, and due to ASP/VBScript’s horribly limited feature set, very low-level. It steps through a file one character at a time, and decides if it is in “HTML mode” or “ASP mode” at an given time, and then uses this staus to convert the file into a set of executable lines.

It should handle most things correctly, with the exception of defines, and <!--# -style directives. It handles short ASP write tags (<%= %>) just fine. Variable scope is preserved inside the include file, and variables/functions set inside the include file continue to exist outside it after it is included — in other words, just as they should.

To use it, simply include the file, and use it just as you would in a sane language:

include("relative_path_to_local_file.asp")

The function returns false if the file doesn’t exist, or true otherwise.

If you fix any bugs in this, please let me have them.

Download it here: ASP Dynamic Includes