madrobby / scripty2

scripty2: for a more delicious web
http://scripty2.com/
Other
516 stars 57 forks source link

setContent for a dialog box #10

Open capripot opened 14 years ago

capripot commented 14 years ago

Hi everybody I'm not shure if it correspond to the project philosophy but i think it could be very cool to have a method "setContent" to refresh the content of dialog box. is it a good idea ? i've made some code to illustrate :

setContent: function(new_content) {
    if(new_content){
      this.content = Object.isElement(new_content) ? new_content :
      new Element('div').update(new_content);
    }else{
      new_content = new Element('div');
    }
    this.element.select('.ui-widget-content').first().update(new_content);
},
justinbaker999 commented 13 years ago

Why are you creating a new div element? And why insert it at all if new_content wasn't even supplied as an argument?

capripot commented 13 years ago

A new div because it is designed as it in the original code I think. And I always insert it because I believe it's better to keep the same design.

justinbaker999 commented 13 years ago

The content is inserted in "ui-dialog-content" div, and isn't padded at all by an extra div. Inserting new div's every time the content is change wouldn't really be a good idea.

capripot commented 13 years ago

If you want to insert some text directly, you have to wrap it in a div element, isn't it ?

justinbaker999 commented 13 years ago

Actually, I'm wrong. What you're doing is inserting another div into the content div rather than updating the content inside the content div.

setContent: function(new_content) { if(new_content){ this.element.select('.ui-widget-content').first().update(new_content); } },

Wouldn't that accomplish it?

capripot commented 13 years ago

Yes it's right, but if don't want to insert a div element and just add a message, so just some text like mydialog.setContent("Bonjour world"); i think we have to add a wrapper, it's why I verified if new_content was an element (a div or whatever) or a text node with the first condition.

justinbaker999 commented 13 years ago

No, with the above code I posted it would update the innerHTML of the content. No wrapper needed.

capripot commented 13 years ago

Yes but sometimes there is no "first" in the ".ui-widget-content" div.

justinbaker999 commented 13 years ago

That would mean that no content was supplied originally. Also, wouldn't ".ui-dialog-content" be better? The content div has both classes.

capripot commented 13 years ago

Yes, so you have to had a div no ? ".ui-dialog-content" could be better yes :)

justinbaker999 commented 13 years ago

I would see if the content is blank, and if so, create the dialog-content div and insert it into the dialog's element, otherwise change the value of the dialog-content div