An open API service indexing awesome lists of open source software.

https://github.com/kiralt/bjax

Ajax link system for modern website. Convert any link in your page to ajax link.
https://github.com/kiralt/bjax

ajax ajax-form ajax-library ajax-link jquery

Last synced: about 1 month ago
JSON representation

Ajax link system for modern website. Convert any link in your page to ajax link.

Awesome Lists containing this project

README

        

# Welcome to Bjax 1.0.2

Ajax link system for modern website. Convert any link in your page to ajax link.

Demo online: http://bjax.6te.net/demo/

**V2 development in progress. VanilaJS, fast & lightweight with form support. [Check it out](https://github.com/KiraLT/Bjax/tree/v2)**

## Features

* Converts any link to ajax link.
* Loads whole page with ajax.
* Loads part of page with ajax.

## Requirements

* jQuery.
* HTML5 browser.

## Usage

### Download manually

Download the latest version: https://github.com/KiraLT/Bjax/releases

### Download using Bower

```
bower install bjax
```

Link to the JS file:

```html

```

Add the CSS file (or append contents to your own stylesheet):

```html

```

To initialize:

```javascript
// bind on data-bjax attributes (recommended)
$('[data-bjax]').bjax();

// bind on each link
$('a').bjax();

// or with custom settings
$('[data-bjax]').bjax({
target: '#content',
element: '#content'
});
```

## Settings

Key | Default | Values | Description
--- | --- | --- | ---
url_attribute | data-href or href | String | URL attribute
url | undefined | String | custom url
replace_attribute | data-replace | String | Replace attribute
replace | true | Boolean | Change page URL after bjax load
element_attribute | data-el | String | Element attribute
element | html | String | Element to load
target_attribute | data-target | String | Target attribute
target | html | String | Load target

## HTML attributes

`data-target`- jQuery selector

Load content to specified target.

**Example HTML:**

```html


Load here

```

`data-el`- jQuery selector

Load only specified element.

**Example HTML:**

```html
Load here
```

`data-replace`- boolean

Change URL after load dynamicaly.

**Example HTML:**

```html
Home
```

`data-url`- string

Custom load URL. Will be used instead of href attribute.

**Example HTML:**

```html
Home
```

## API `Bjax`

You can instantiate the Bjax also through a classic way:

```javascript
// Collect settings from element
new Bjax($('[data-bjax']));

// Set settings manually
new Bjax({
'target': '#target',
'element': '#element',
'url': '/page'
});

// Mixed
new Bjax($('[data-bjax']), {
'target': '#target',
'element': '#element'
});
```

Bind bjax manually:

```javascript
$('[data-bjax]').on('click', function(e){
new Bjax(this);
e.preventDefault();
});

// Live bind
$(document).on('click', '[data-bjax]', function(e){
new Bjax(this);
e.preventDefault();
});
```

Onclick attribute

```html
Link
```

# Bjax 2.0.0 (coming soon)

## Links
```js
new Bjax($('#my_a'), {
'target': '#content',
'element': '#content',
'loader': 'default'
});
```

## Forms

```js
new Bjax($('#my_form'), {
'target': '#content',
'element': '#content',
'method': 'post',
'loader': 'default'
});
```

## Events

```js
var bjax = new Bjax($('#my_a'));
bjax.on('loader:start', function() {
$('body').addClass('dim')
}).on('loader:end', function() {
$('body').removeClass('dim')
});
```

## Custom rendering

```js
new Bjax($('#my_a'), {
'target': '#content',
'element': '#content'
}).on('render', function(content) {
return '' + content + '';
})
```

## Custom loaders

```js
Bjax.registerLoader('modern', MyModernLoader);
```

*More customization*

## Custom builds

* jQuery
* zepto.js
* vanillaJS