Your easiest fastest way to have a single page web application with no single line of JavaScript code.
Live demo
The demo is just static files, you might want to place this directory in your server document root or just type the following command which will start a simple http server on port 8000, then point your browser on http://localhost:8000/index.html
python -m SimpleHTTPServerel - DOM element$target - a jQuery object of target DOM elementwhere can be one of: closest, inside or doc which means entire documenthow can be one of: prepend, append or replace<a data-toggle="ajax-load" href="/posts/today.json" data-target=".posts">my link</a>
<button type="button" data-toggle="ajax-ops">my button</a>
<div class="me" data-refresh-url="/user/me.json" data-template="user_info"></div>
<div class="posts" data-template="posts_titles"></div>
<div class="posts" data-template="full_posts"></div>you can define
data-toggle
ajax-load - fetched text, HTML content or pure data and apply it to target(s)ajax-ops - fetches json op-codesajax-modal * requires extensiondata-target - the selector to apply the fetched content to itdata-url (which sometimes can be replaced by href or data-refresh-url)data-template - the template to be used to render pure datadata-format - can be text, html or jsondata-how - can be one of: prepend, append or replacetemplates are functions that take json object and return html you can use any template engine but we suggest Handlebars
ajax_ops.flashmsg({html:, text:, type:info|danger, selector:, base_target:$obj, where:closest|inside|''})
ajax_ops.flashmsg({text:'not found', type:'danger');ajax_ops.flashmsg.call(this, {text:'not found', type:'danger', selector:'.modal', where:'closest'});self.flashmsg_opts.selector which is .content:firstonsubmit="return ajax_ops.submit_form(this, params);"
params are optionalparams.target=$objparams.cb=function($target, data){}ajax_ops.loads({html: CONTENT, text: CONTENT, data: JSON, template: NAME, el: ELEMENT, how: prepend|append|replace})
ajax_ops.load({el:element, url:, how: prepend|append|replace, selector:, where:closest|inside|, })ajax_ops.refresh(element|selector, params)
params are optionalparams.whereparams.base_elementajax_ops.load and accepts its params like howajax_ops.refresh('.me')ajax_ops.exec_ops([ [op1, selector1, params1], [op2, selector2, params2],.. ])
removerefreshloadattr {set:{k:v}, unset:[k1,k2]}class {add:[], remove:[], toggle[]}ajax_ops.ops['my_opcode']=function(el, params){}// register templates
ajax_ops.templates=Handlebars.templates;
// nice hack
Handlebars.partials = Handlebars.templates;
// You might want to disable usual links behavior
$('a[data-toggle]').click(function (e) {e.preventDefault()});Copyright 2014 Muayyad Alsadi
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.