About Indira.js

The main idea of Indira.js is simplifying creation of AJAX-based-application. We got great idea about JS-caching and implemented this in very easy going way.

Everything in Indira.js can be caught via built-in events system. And all behaviors is controlled via HTML5 data attributes.

Indira.js is part of Indira CMS project.
GitHub: Indira.js

Please submit about any bug or suggestion (idea) to GitHub Issues.
Alternative download link: IndiraJS.zip.


Usage

Istallation and AJAXifying
Find out more at docs

Link JavaScript & Setup Config

Right before link Indira.js you need to define variable with name indiraJsConfig, and Object value, see example below.

Read more about config here: Config Object.

Example:

<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>

<script type="text/javascript">
	var indiraJsConfig = {
		loader: 'Loading...',
		defaultLoaderContainer: false,
		defaultOutputElementId: 'inner',
		defaultPostCaching: false,
	};
</script>
<script src="http://youydomain.com/scripts/indira.min.js"
type="text/javascript"></script>
<script src="http://youydomain.com/scripts/vendor/jquery.history.js"
type="text/javascript"></script>

AJAXify

To easily AJAXify your links just add to them data-ajaxify="true" or start theirs ID from go_to_.

Find out more about data attributes.

Example:

<input type="text" id="my_demo_input" />
<a 	id="go_to_some_page" 
	href="http://a.com/some_page.html"
	data-out="quick_view_box"
	data-prevent-follow="true"
	data-load="quick_view_box"
	data-post="{"value": encodeURI($('#my_demo_input').val()) }"
	data-caching="true"
>Some Page</a>
<div id="quick_view_box">
	AJAX request response will be placed here
</div>

Scripts

In downloaded archive you will find next files:

  • Indira.min.js - Packed and minified version in Indira.js
  • Indira.debug.js - This version of Indira.js you may found useful on development stage. In console you will see all logs and states about any function or event. This version we use on website, open JS-console to see what's going on now
  • Indira.js - Standart version

Caching

JS Caching in Indira.js is beautiful. If user going back or to main page of your website it happens in miliseconds, it happens just now! Caching even handle all your filled inputs, and all unsaved changes makes by user on previous pages. By default it's turned on for all your GET-requests, and for POST on your demand.

Caching is not handled by DOM, - that means, - once user goes to next page, the previous one is saved into JS Object and removed from DOM. But you still have access to cached elements and you can change it's content on the fly. This is very useful when user editing something on one page and have to see result on previous. For example we have a table of blog posts and we create new one, after we go back we need to see new row with newly created blog post.

Examples

Open JS-Console in your browser and see all Indira.js actions

Send data via POST-method

Run Demo POST
AJAX request response will be placed here

Code

<input type="text" id="demo_post_input" />
<a 	id="go_to_demo_post" 
	href="/tools/demo_post"
	data-out="out_demo_post"
	data-prevent-follow="true"
	data-load="out_demo_post"
	data-post="{"value": encodeURI($('#demo_post_input').val()) }"
	data-callback="$('#demo_post_input').val('')"
>Run Demo POST</a>
<div id="out_demo_post">
	<span>AJAX request response will be placed here</span>
</div>

Send request to uncorrect URL

Run Fail URL Demo
AJAX response will be not shown on error. Indira.js will handle it and restore previous page state.

Code

<a 	id="go_to_demo_fail_url" 
	....
	href="/some_url/not_exists"
	data-caching="false"
>Run Fail URL Demo</a>
<div id="out_demo_fail_url">
	<span>AJAX response will be not ...</span>
</div>

Caching


Try to change this, after you go to any other page, and text below will be removed from DOM.

In this exaple you will see how DOM is changing while cache is working, also we will change value of this element:
This is element with ID: '#cache_demo_change'. This value will be changed

Code

<a	data-ajaxify="true"
	href="/tools/demo_page/1"
	data-out="out_demo_cache_main"
	data-prevent-follow="true"
	data-load="loading_element_demo_cache_main"
>Page 1</a>
...
Change value of "#cache_demo_change" to: 
<input type="text" id="demo_cache_main_input" />
<button 
	type="button"
	data-ajaxify="true"
	data-post="{"value": encodeURI($("#demo_cache_main_input").val()) }"
	data-link="/tools/demo_change"
	data-load="loading_element_demo_cache_main"
	data-out="cache_demo_change"
	data-prevent-follow="true">
	Change!
</button>
...
<div id="out_demo_cache_main">
	<div>...<strong id='cache_demo_change'>This is element with ID: '#cache_demo_change'. 
	This value will be changed</strong></div>
</div>

Infinite Scroll

Easily create infinite scroll table using data-scroll-load="true" and data-scroll-callback="..." attribute. After user scrolls to bottom for element with this data-scroll-load="true" attribute Indira.js will run code from data-scroll-callback attribute, please check out example below:

Add new, delete and edit rows content.


ID Title Action
1 Title of item 1
2 Title of item 2
3 Title of item 3
4 Title of item 4
5 Title of item 5
6 Title of item 6
7 Title of item 7
8 Title of item 8
9 Title of item 9
10 Title of item 10
11 Title of item 11
12 Title of item 12
13 Title of item 13
14 Title of item 14
15 Title of item 15
16 Title of item 16
17 Title of item 17
18 Title of item 18
19 Title of item 19
20 Title of item 20
21 Title of item 21
22 Title of item 22
23 Title of item 23
24 Title of item 24
25 Title of item 25
26 Title of item 26
27 Title of item 27
28 Title of item 28
29 Title of item 29
30 Title of item 30

Code:

<button 
  class="btn btn-sm btn-default disabled" 
  disabled="disabled" 
  id="loading_element">
    <i class="icon icon-lemon icon-large"></i>
</button>
<button 
  data-ajaxify="true" 
  data-link="/tools/demo_scrolling" 
  data-load="loading_element" 
  data-out="scrolling_container" 
  data-post="{..JSON..}" 
  data-prevent-follow="true">
    Add row
</button>
<button 
  data-ajaxify="true" 
  data-link="/tools/demo_scrolling" 
  data-load="loading_element" 
  data-out="scrolling_container" 
  data-post="{..JSON..}" 
  data-prevent-follow="true">
    Prepend row
</button>

<div id="scrolling_container">
  <table 
    id="scrolling_table" 
    data-scroll-load="true" 
    data-scroll-callback="$("#ajax_load_more_button").trigger("click")">
    <thead>
      <tr>
        <th>
          ...
        </th>
      </tr>
    </thead>
    <tbody id="scrolling_table_tbody">
      <tr id="scrolling_table_tbody_tr_1">
        ...
      </tr>
      //LOAD MORE ROWS BUTTON
      <tr id="load_scrolling_table_tbody">
       <td colspan="100%">
        <button 
          id="ajax_load_more_button" 
          data-link="/tools/demo_scrolling?page=32" 
          data-post="{..JSON..}" 
          data-prevent-follow="true" 
          data-append="true" 
          data-out="scrolling_table_tbody" 
          data-remove="load_scrolling_table_tbody" 
          data-caching="false">
            Show more rows
        </button>
       </td>
      </tr>
    </tbody>
  </table>
</div>