Code Monkey home page Code Monkey logo

frame's Introduction

FRAME.js

Ajax and modals pattern with pushState update, enjoy the power of google+ like navigation

Ajax load into a main div and updates browser history with pushState Ajax load modal Open in new tab will work if you take care

Requeriments:

  • Jquery >= 1.8
  • Bootstrap >= 3.0 (only if you plan to use modals)

Configuration:

Add this javascript on your html code ( after jquery definition )

    $(document).ready(function (){
        Frame.init();
    });

Or the full config (just overiding default)

    $(document).ready(function (){
        Frame.init(
        	{
        		//Classes that points the elements
        		'ajax-marker'    : 'ajax',
        		'modal-marker'   : 'modalist',
        		'confirm-marker' : 'confirm',

        		'history-update' : true,

        		//Ids for main and mainloader
        		'ajax-frame'     : 'main',
        		'ajax-loader'    : 'mainloader',
        		'modal-frame'    : 'theModal',
        	}
        );
    });

Use:

Ajax links into a container:

Easy just add the ajax-marker class (or default value ajax), frame.js wil catch the click event and load into ajax-frame

	<a class="btn **ajax**" href="test2.html">

Or if you do not need browser history for the link add the attribute history="false"

	<a class="btn **ajax**" href="test2.html" **history="false"** >
Bonus

Add a loader, design a nice loader and add the id mainLoader or define it at ajax-loader

	<div id="mainloader"><img src='loading.gif' alt='' /></div>
	<div id="main"></div>

Modal links:

It is very add the modal-marker class (or default value modalist), frame.js wil catch the click event and show the url in a modal box

	<a class="btn **modalist**" href="ajax-center.html">

Programatically close the modal

	Frame.closeModal();

Or use bootstrap way inside the modal

	<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
New, full size pictures

Add pictures links very easy with a full size modal view

    <a class="modalist" href="path/to/fullsize.png">
        <img src="path/to/thumbnail.png">
        <label> Click me to enlarge</label>
    </a>

Confirm links:

Add a confirm message (like alerts, I know they are ugly but I promise making them nicer) and still having the ajax and modal behavior.

As usual in frame.js ;), add the class confirm or the confirm-marker if you overide it, set the message with the attribute confirm-message="MESAGE"

Confirm and redirect
	<a class="btn confirm" href="test2.html" confirm-message="Sure X ?">
Confirm and load ajax
	<a class="btn confirm ajax" href="test2.html" confirm-message="Sure X ?" >
Confirm and load, forgetting the history
	<a class="btn confirm ajax" href="test2.html" confirm-message="Sure X ?" history="false" >
Confirm and show modal
	<a class="btn confirm modalist" href="ajax-center.html" confirm-message="Sure X ?">

githalytics.com alpha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.