Archive

Archive for the ‘javascript’ Category

nicEdit Firefox center and right align bug patch.

July 28th, 2010 No comments

If you are using nicEdit on content editable areas instead of the iFrame method, then you may have run across the FireFox bug that prevents you from changing the text alignment on the first line of a content editable element. 

As a work around, change the nicCommand method in nicEdit.js (Line 610 or so), to be this:

nicCommand : function(cmd, args) {
        if ((cmd == 'justifyright') || (cmd == 'justifyleft') || (cmd ==
        'justifycenter') || (cmd == 'justifyfull')) {
              try {
                 document.execCommand(cmd, false, null);
              }
              catch (e) {
                 //special case for Mozilla Bug #442186
                 if (e && e.result == 2147500037) {
                    //probably firefox bug 442186 - workaround
                    var range = window.getSelection().getRangeAt(0);
                    var dummy = document.createElement('div');

                     //To restore the range after collapsing for triple click bug...
                     var restoreSelection = false;
                    dummy.style.height="1px;";

                    //find node with contentEditable

                    //Triple Click selection Problem in mozilla, the selection contains the content editable div, which creates a problem for some reason, so we collapse the selection to the end, and then re-select everything...
                    if(range.startContainer.contentEditable == 'true'){
                        window.getSelection().collapseToEnd();
                        restoreSelection = true;
                    }

                    var ceNode = window.getSelection().getRangeAt(0).startContainer;

                    while (ceNode && ceNode.contentEditable != 'true')
                       ceNode = ceNode.parentNode;

                    if (!ceNode) throw 'Selected node is not editable!';

                    ceNode.insertBefore(dummy, ceNode.childNodes[0]);
                    document.execCommand(cmd, false, null);
                    dummy.parentNode.removeChild(dummy);

                     //RestoreSelection if we changed it...
                     if(restoreSelection){
                        window.getSelection().addRange(range);
                     }
                 } else if (console && console.log) console.log(e);
              }
           } else {
              document.execCommand(cmd, false, args);
      }
    }

JavaScript Primer

September 10th, 2009 No comments

So you want to learn JavaScript huh? Way to go! SOA powered by JavaScript is the future of the web. (Trust me).

What is JavaScript? It’s a scripting language that all modern web browsers run that allows you to manipulate web pages and do sweet stuff.

To get started, first, you need an easy way to run JavaScript. While you could write javascript in an html page and run it, it’s generally easier to be able to run scirpts without making an html page. To do this, install Firebug, and use it’s console. (Just install firebug, click on the little cock-roach icon in the lower left of Firefox, and click the console tab, now reload your window.).

Once you have the firebug console working, type the following into the console, and you should get a popup.

alert('Hello World!');

Here’s a video that shows how to install and use Firebug:

If you want to learn more, head over to w3schools’ JavaScript tutorial.

Categories: html, javascript Tags: