I am writing a software for a website where people can manage the website content. The interface is similar to Windows with all those windows floating around, click-able components, type-ab开发者_JAVA技巧le text fields, etc. The admin interface is written in JavaScript, HTML and CSS. I'm wondering what kind of architecture should I apply to my admin system before it's too late (I've written some minor code so far).
For example, for the PHP back-end I'm using MVC, but what should I use for the client-side JavaScript admin system?
If you were developing an GWT application, you would automatically have an architecture. For custom JS, with AJAX calls a two-tier architecture would be more than sufficient. However, I prefer going the event-driven way, where I have a layer full of listeners and another layer of handlers. I use closures for the most part and use custom page-ids. Works like a charm. I rarely separate the AJAX calls out, owing to the single-threaded aspect of JS.
P.S: I had to use the term layers for lack of better alternative.
You can use an MVC on the browser too.
But it may be overkill.
The minimum you can do is to separate the HTML(view) and the JS(logic) code.
We use a javascript templating engine (PURE) for our JS app, but there are plenty of other available on the web.
jQuery and jQuery UI are a good start.
Have a look at JavaScriptMVC. It's an MVC framework for front end JavaScript applications. Version 2 is jQuery based so you'll get the power of that fantastic library into the bargain
精彩评论