Mobify.js is a JavaScript framework for adapting websites for tablet and mobile.
Install Node.js if you don’t have it already.
Download the Mobify Client:
sudo npm -g install mobify-client
Create a project scaffold and start the Mobify.js development server:
mobify init myproject
cd myproject
mobify preview
Insert the Mobify.js tag immediately after the opening <head> tag on the website you want to adapt:
<script>
(function(window, document, mjs) {
window.Mobify = {points: [+new Date], tagVersion: [1, 0]};
var isMobile = /ip(hone|od|ad)|android|blackberry.*applewebkit|bb1\d.*mobile/i.test(navigator.userAgent);
var optedOut = /mobify-path=($|;)/.test(document.cookie);
if (!isMobile || optedOut) {
return;
}
document.write('<plaintext style="display:none">');
setTimeout(function() {
var mobifyjs = document.createElement('script');
var script = document.getElementsByTagName('script')[0];
mobifyjs.src = mjs;
script.parentNode.insertBefore(mobifyjs, script);
});
})(this, document, 'http://127.0.0.1:8080/mobify.js');
</script>
Set your browser’s User Agent to “iPhone”:
Navigate to your page. If the demo gods are kind, you’ll see this:
Mobify.js uses a technique called client side adaptation to remix HTML in the browser. The remixed content is interpreted by the browser as if the server had sent it in the first place!
The Mobify.js tag bootstraps the adaptation and loads the Mobify.js file, which performs it. The tag activates in iOS, Android and BlackBerry browsers. By default, the Mobify.js file is loaded from the development server.
The development server is part of the Mobify Client, a command line tool for building Mobify.js projects. It compiles the Mobify.js file dynamically per request. The file contains two parts, the Mobify.js API and site specific adaptations.
Adaptations are expressed as a series of operations on the source DOM, the DOM constructed from the page’s original HTML. HTML Elements can be selected, then rendered with a template. Finally, the rendered template is written to the browser.
{foo} - Variables: Select & Render A Single Variable{foo|bar} - Variable Filters: Pass The Value foo Through Filter bar{#foo} ... {/foo} - Accessing Attributes Of, Or Descending Into The Variable foo{#foo} ... {.} ... {/foo} - Iterate Over The Variable foo{>foo/} - Include The Partial foo Inside The Current Template{+bar} ... {/bar} - Block Placeholders{<bar} ... {/bar} - Block Overrides{?foo} ... {/foo} - Conditional, Check For The Existence Of Variable foo{^foo} ... {/foo} - Conditional, Check For The Non-existence Of Variable foo{%script} ... {/script} - Inline Script Pragma{! Comment !} - Template Comments