Monthly Archives: December 2006

Woohoo my bluetooth headset is working again with vista

I could download the bluetooth stack from toshiba and my headset works

I got the drivers here: Toshiba bluetooth stack for vista

A scriptaculous multi file selector class

For nblogr I wanted to provice a way to upload multiple files but just display one input field at a time.  So I worked out the following javascript class.

Usage :

new NBlogr.MultiSelector( element(id), maxNumberOfFiles or -1 for unlimited );

The MultiSelector class:

NBlogr.MultiSelector = Class.create();
NBlogr.MultiSelector.prototype = {
    initialize : function(file, max){
        this.options = {
            max : -1,
            container:null,            file:null        };

        this.options.file = $(file);        this.id = 0;
        this.count=0;
        this.initializeContainer();
        if(max){
            this.options.max = max;
        }
        else{
            this.options.max = -1;
        }
    },
    initializeContainer : function(){
        if(this.options.file){
            var ele = this.options.file;
            this.options.container = Builder.node('div',{id:ele.id + '_container',
                style:'background:transparent;display:inline;width:250px;font-size:small'});

            ele.parentNode.insertBefore(this.options.container,ele);
            this.options.container.appendChild(ele);

            if(!this.list){
                this.list = Builder.node('div',{id:ele.id+'_list',style:'display:block'});
            }
            this.options.container.appendChild(this.list);
            this.initializeFile(ele);
        }
    },
    initializeFile:function(element){        

        if( element && element.tagName == 'INPUT' && element.type == 'file' ){
            element.name = 'file_' + element.id;
            element.id = 'file_' + element.id++;

            Event.observe(element,'change',this.addFile.bindAsEventListener(this));

            if( this.max != -1 && this.count >= this.max ){
                element.disabled = true;
            };
            this.count++;
        } else {
            alert( 'Error: not a file input element' );
        };
    },
    addFile:function(ev){
        var ele = Event.element(ev);

        var new_element = document.createElement( 'input' );
        new_element.type = 'file';
        ele.parentNode.insertBefore( new_element, ele );
        this.initializeFile( new_element );
        this.addListRow( ele );
        ele.style.position = 'absolute';
        ele.style.left = '-1000px';

        if(ev) Event.stop(ev);
    },
    removeFile:function(ev){
        var ele = Event.element(ev); 

        ele.parentNode.parentNode.removeChild( ele.parentNode );
        this.options.file.disabled = false;
        this.count--;        

        if(ev) Event.stop(ev);
    },
    addListRow : function( element ){
        var new_row_button = Builder.node('a',{href:'javascript:;;',
            title:'Remove this file from the list'},'Remove');
        var new_row = Builder.node('div',{element:element},[$F(element) + ' | ', new_row_button]);
        Event.observe(new_row_button,'click',this.removeFile.bindAsEventListener(this));
        this.list.appendChild( new_row );

    }
};

Fraudulent postal mails from domain registrar

Today we got a mail from central registration service .com telling us that we need to pay 966 USD for www.vandyck.co.nz
Now I’m very sure it’s my domain name and not registered with these guys.

The company poses as a New York based company but the letter is sent from Prague. 

I just blog about it because it looks kind of official and maybe other people might not discard it.

When will I be able to put a spam filter on my regular mailbox ?

Finally back to nblogr

I can finally spend a couple of days on nblogr. I hope I get enough done to have a releasable version after this time.

Wtf ?? Ajax and the hidden cost of use

In it world Sean McGrath has been talking about Ajax and the hidden cost of use.

I got to this post through Jon Udell, who has a post about ajax and automation.

Anyway the sort of arguments that Sean is using make me think he has yet to complete a good ajax application.

A common buzzword in the industry is the concept of a “front end”. In an ideal world, the front end just handles all the graphical user interface stuff while the back end does all the real work. In this ideal world, you can just bypass the front end and work with the back end directly when you want to integrate applications. Sadly, we do not live in this ideal world.

I’m going of a rant here because I thought that the whole discussion AJAX is it good vs bad? was closed about a year ago.

He obviously hasn’t seen any of the Castle or ruby implementations who do just that. For example I can unit test my complete controllers base with out running a browser.

Unless i’m really sure that an application will be used in one type of browser or it’s successor and this browser is ajax capable.. then and only then the user interface will rely on javascript for the interaction.

People then go why don’t you cache values and have javascript work it out for you the next time this gives a perceived performance benefit. There are 2 main reasons for it :

1 separation of concerns the only decision an UI can make is should I show this red or green based on a value of the object etc. But nothing else.

2 you want live data not data that is almost live (i’m taling about a system where minutes matter in the workflow) :)

Think now of web-based applications you most like to use. How are their front ends and back ends? Well, historically, they have been quite cleanly separated. After all, a web browser only has limited capabilities. Behind the scenes it is really only capable of sending two commands GET and POST to things called URLs. Everything else (slight simplification!) happens at the back end.
Ah, but that was then and this is now. Now we have AJAX and JSON and Flash and the Google Web Toolkit and Windows Presentation Foundation and…
All these things help us to make web applications easier to use. In so doing, the clean separation between front end and back end gets more and more blurred. With every blurring of the separation, application integration becomes more complex.

I guess somebody is really missing the point here a UI is just a shell over lots of services that can do the job with or without the UI on it.  All the real work is to be done in the service layer or deeper down in you app.

I think Windows Presentation Foundation says it all in its name already Presenation only whatever is not related to the presenation of your data in the UI shouldn’t be there.

What I think is going on here is that he’s affraid to take the plunge because the arguments he uses are arguments I had against building a full ajax site about 2 years ago.  I’ve set them aside.. and just do it now.

I must say that using castle has been a tremendous help for me into getting things done in the same timeframe as i would have with the classic model.

For instance I’m about to finish a project that  in a clasic model would have consisted out of 70+ very dataintensive forms. The result of using ajax a.o. technologies now has the application down to 5 forms

I still had to write the 70+ views and but not nearly as many search functions etc.  I do ajax on the AHA  principle (which means I send html snippets) because JSON and building dom nodes breaks backwards compatibility and would have slowed down development a lot.

To get to the automation bit .. I think ajax makes it much more easy to interact with the backend then the classic model would have done. There are many more options to choose from (which is kind of a dissease of our time.. too many options) and you have a much finer grained control over what passes through the pipeline in terms of bits and bytes. just pull up any http request listener and you’ll have all the things you need to replay your actions vs. parse forms and go through the html to figure out the fields etc.

Ok that’s it for my morning rant.  I just thought somebody needed to put his views into context. I have to give him that technology certainly didn’t come to a standstill over the last year so it’s getting increasingly difficult to keep up.

I’ve known a couple of really good people to give up the game this year because it’s all moving too fast in some respects or not how they want it to move. In my opinion things are indeed moving very fast at the moment.. but that’s what makes it so exciting :D

DevExpress is giving away their controls

DevExpress is giving away 40 controls for free. The only thing you need to do is register on their site and you’ll get an email with the controls.

Over 40 Controls – Free of Charge

Scriptaculous accordion widget

Today I needed an accordion widget. I searched the internet but didn’t really find one that was based  on scriptaculous and did what i wanted it to do and how i wanted.

You need scriptaculous for this widget. Example markup is shown in the comments. Just add the javascript to a page and it will find the accordion just fine.

I thought I’d share the code:

 

/**
 * @author Ivan Porto Carrero
 *
 *
 * Styles:
 * *******
 * .accordeon{
 *         border: 1px solid #1F669B;

 *        font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
 *        font-size: 11px;
 *        overflow:auto;
 *    }
 * h5 {
 *     font-size:12px;
 *    padding: 3px 5px 3px 5px;
 *     margin: 0;
 *     border-style: solid none solid none;
 *     border-top-color:#BDC7E7;
 *     border-bottom-color:#a1bbe4;
 *    border-width: 1px 0px 1px 0px;
 *    color:#fff;
 *    background-color: #63699C;
 *    cursor:pointer;
 * }
 * .panel_header{
 *     color:#878285;
 *     background-color: #63699C;
 *     background:url(images/shade.gif) 0 0 repeat-x;
 * }
 * .panel{
 *     margin: 0;
 *    padding-bottom:0;
 *    border: none;
 * }
 * .panel_body{padding:5px;}
 *
 *
 * Markup:
 * *******
 *
 *
*
*
Accordian 1 Title
*
*
Content goes here
*
*
*
*
Accordian 2 Title
*
*
Content goes here
*
*
*
*
Accordian 3 Title
*
*
Content goes here
*
*
*
*
Accordian 4 Title
*
*
Content goes here
*
*
*
*/
Accordeon = Class.create(); Accordeon.prototype = { initialize:function(element, options){ this.options = { onBeforeSwitch:null, onAfterSwitch:null, activePanel:null, panelClass:'panel', headerClass:'panel_header', bodyClass: 'panel_body', activePanelClass:'active', showAnim:false }; Object.extend(this.options,options||{}); this.accordeon = $(element); this.accordeon.panels = new Array(); var pnls = $A(this.accordeon.childNodes); pnls.each( function(pnl){ var ele = $(pnl); var headers = ele.getElementsByClassName(this.options.headerClass); if(headers.length > 0){ var header = headers[0]; ele.header = header; Event.observe(header,'click', this.onChange.bindAsEventListener(this)) } var bodies = ele.getElementsByClassName(this.options.bodyClass); if(bodies.length > 0){ var body = bodies[0]; ele.body = body; body.hide(); } if(ele.tagName.toLowerCase() == 'div' && Element.hasClassName(ele,this.options.panelClass)){ this.accordeon.panels.push(ele); } }.bind(this) ); this.setActivePanel(pnls[0],false); }, onChange:function(ev){ var ele = Event.element(ev); var parents = ele.ancestors(); var panel; parents.each( function(elm){ var obj = $(elm); if(obj.hasClassName(this.options.panelClass)){ panel = obj; return; } }.bind(this) ); this.setActivePanel(panel,true); }, setActivePanel:function(panel,showAnim){ if(this.onBeforeSwitch) this.onBeforeSwitch(); if(this.activePanel && this.activePanel.id != panel.id ){ var hideAnim = null; if(this.options.showAnim) new Effect.toggle(this.activePanel.body,'blind',{duration:0.3}); else this.activePanel.body.hide(); this._activatePanel(panel,showAnim,hideAnim); } else if (!this.activePanel){ this._activatePanel(panel,showAnim); } if(this.onAfterSwitch) this.onAfterSwitch(); }, _activatePanel:function(panel,showAnim,panelToHide){ panel.body.addClassName(this.options.activePanelClass); if(showAnim && this.options.showAnim){ new Effect.toggle(panel.body,'blind',{duration:0.3}); } else{ panel.body.show(); } this.activePanel = panel; } }; Accordeon.Widget = Class.create(); Accordeon.Widget.prototype = { initialize:function(options){ this.options={ containerClass:null }; Object.extend(this.options,options||{}); this.accordeons = new Array(); $$('.' + this.options.containerClass).each( function(accordeon){ this.accordeons.push(new Accordeon(accordeon,this.options)); }.bind(this) ); } }; Event.observe(window,'load',function(){ var options = { panelClass:'panel', headerClass:'panel_header', bodyClass: 'panel_body', activePanelClass:'active', showAnim:true, containerClass:'accordeon' }; new Accordeon.Widget(options); }.bindAsEventListener(this));

Prototype based fix for transparent png’s

Yet another fix for transparent png images. This one is based on prototype and doesn’t need any external image to force the transparency.

To use it give the image elements that contain a transparent png a class name of png and it should fix it up.

function fixPng(img)
{
    try {
        var arVersion = navigator.appVersion.split(“MSIE”);
        var version = parseFloat(arVersion[1]);
        if ((version >= 5.5) && (version < 7) && (document.body.filters)){
            var pngImage = $(img);
            var visible = pngImage.visible();
            if(!visible) pngImage.show();
            var width = pngImage.getWidth();
            var height = pngImage.getHeight();
            if(!visible) pngImage.hide();
            var imgId = pngImage.id ? “id=’” + pngImage.id + “‘ “ : “”;
            var imgClass = pngImage.className ? “class=’” + pngImage.className + “‘ “ : “”;
            var imgTitle = pngImage.title ? “title=’” + pngImage.title    + “‘ “ : “title=’” + pngImage.alt + “‘ “;
            var imgStyle = “display:inline-block;” + pngImage.style.cssText;
            var replacement = + imgId + imgClass + imgTitle
                                    + ” style=\”" + “width:” + width
                                    + “px; height:” + height
                                    + “px;” + imgStyle + “;”
                                    + “filter:progid:DXImageTransform.Microsoft.AlphaImageLoader”
                                    + “(src=\’” + myImage.src + “\’, sizingMethod=’scale’);\”>
;
            pngImage.outerHTML = replacement;
        }
    } catch(e) {}
};
Event.observe(window,‘load’,function(){$$(‘img.png’).each(function(png){fixPng(png)}});
//Event.onDOMReady(function(){$$(‘img.png’).each(function(png){fixPng(png)});});

del.icio.us tags:

If you’re serious about javascript

Sorry for spamming your readers today. But this is an absolute must see

http://ajaxian.com/archives/douglas-crockford-video-advanced-javascript

One of my best friends is joining MS

One of my best friends is joining Microsoft in belgium.

He has a blog concerning marketing and advertising campaigns.

You can read all about it here : View his blog post…

Page 1 of 212