Extracting text from a DOM element

on February 23rd, 2009 at 1:53pm , 1 responses

I’ve just been asked the following question by a friend:

in javascript - how do i get the text of an html-element, which doesn't include text of all the children? firefox only

 

Every html DOM element has a collection of direct children, called childNodes. Each node has a type, and text nodes (those are text portions that are part of an element’s inner content) have ‘3’ for their type.

 

So, the following code is the solution:

function extractFirstLevelTextFrom(elm) {
   var text = '';
   for (var i =0; i < elm.childNodes.length; ++i) {
      if (elm.childNodes[i].nodeType==3) 
          text += elm.childNodes[i].nodeValue;
   }
   return text;
}

Monorail Routing and the Homepage routing rule

on February 10th, 2009 at 11:39am , 18 responses

Scenario:

You are building a Monorail web site, and want to setup a route from the application's path to a given action (usually home/index)

 

The problem:

The pattern "/" does not work, so

RoutingModuleEx.Engine.Add(
    new PatternRoute("Home", "/")
        .DefaultForArea().IsEmpty
        .DefaultForController().Is("Home")
        .DefaultForAction().Is("Index")
    );

will fail to serve http://yoursite/

Same will happen if you're using the Code Generator for setting up rules.

[PatternRoute("Homepage", "/")]
public void Index() { ... }

will fail just the same

 

The fix:

Use the pattern "/[controller]", like that:

RoutingModuleEx.Engine.Add(
    new PatternRoute("Home", "/[controller]")
        .DefaultForArea().IsEmpty
        .DefaultForController().Is("Home")
        .DefaultForAction().Is("Index")
    );

or if you're using the Code Generator:

[PatternRoute("Homepage", "/[controller]")]
public void Index() { ... }

 

Future fix:

I'm considering adding a useful HomepageRoute that will derive from PatternRoute and will have all the needed conventions for easily setting up the homepage rule. Hopefully will be in trunk by this weekend. This will allow a simpler default syntax:

RoutingModuleEx.Engine.Add(
    new HomepageRoute()
    );

or (using the code generator):

[HomepageRoute]
public void Index() { ... }

Convention over Configuration.

If you can see this post then …

on February 5th, 2009 at 4:53pm 6 responses
  1. The blog appear to work correctly on the new server

    and
  2. The DNS change is going well enough

    and
  3. You can start commenting again

I hope that the new server will prove more stable.

My blog is moving to a new server

on February 5th, 2009 at 4:47pm 0 responses

Some interruptions etc. might occur, so please be patient. I hope it’ll be allright soon enough.

 

Please do not leave any comments meanwhile as they might not make it through to the new server.

Stuff from the Monorail presentation

on February 2nd, 2009 at 8:09pm , , , 3 responses

Here is the promised presentation from the talk I gave yesterday, for the Web Developers Community at Microsoft offices in Ra'anana.

 

 

 

The sources for the demo I showed are hosted on github.  If you're not using git (and you should give it a try if that is the case), you can grab a zip of the latest snapshot from that site (there's a 'download' button). Git is worth using if only for the great service given by github.

http://github.com/kenegozi/monorail-aspview-demo/tree/master

 

As for the slides - I tried using scribd and SlideShare, both attempts ended up not too well. I'll try to get a better format later on.

 

 

I'd like to thank Noam King, the organiser of the WDC group, for having me as a speaker.  I'd also like to thank Damien Guard who have created the Envy Code R font which I used during the presentation.


Follow

Statistics

Posts count:
447
Comments:
951