PDA

View Full Version : JS model view controller with JS



NeoDreamer
August 18th, 2009, 04:51 PM
I have this custom popup function which accepts an object:



function popup(obj) {
$('message').getElementsBySelector('strong')[0].update(messageObject.title);
$('message').getElementsBySelector('span')[0].update(messageObject.message);

if ($('message').visible())
Effect.Fade('message', {duration: this.popupFadeTime});
else
Effect.Appear('message', {duration: this.popupFadeTime});
}


It's used all over my site to popup different messages. For example:



popup({title: 'error has occurred', message: '<strong>required <i>field</i></strong>'});


Isn't is wrong to put the HTML tags (view) in javascript (controller)? How do I separate view and controller when I need this generic popup function that can display any sort of HTML?

jwilliam
August 19th, 2009, 04:08 AM
I don't see a problem with what you have there... but then again, I don't really look at javascript as part of the controller. JS is generally used to manipulate the DOM, which would be part of the view. I think of the controller as... say, the PHP (or whatever language you're using) which processes data from the model and generates the (x)html.

However, I'll admit that I'm not an expert on this topic, so I'd love to hear what others have to say on the subject.