Cobler


Getting Started

Dependencies - Cobler.js (COntent BuiLER) depends on sortable.js and adds the ability to drag items around that are defined by JSON objects that can have visual components. This can be used to construct various types of content depending on the individual 'slices' defined. Stock components exist for building forms with Berry.js ad for building out generic content. The stock components rely on several more libraries such as Berry.js, hogan.js, jQuery, and Bootstrap

A minimum setup might look something like this

<!DOCTYPE html>
<html>
  <head>
    <script type='text/javascript' src='http://rubaxa.github.io/Sortable/Sortable.js'></script>
    <script src='assets/js/cobler.js'></script>
  </head>
  <body>
  <div class="myCobler">
  </div>
  </body>
</html>

To get started we just need to initialize our cobler instance with some options

var cb = new Cobler({targets: document.getElementsByClassName('myCobler')})

API

addSource
addCollection
toHTML
toJSON
{editor: true}
destory
clear
deactivate

Options

var options = {
  targets: [document.getElementById('target')]
  items: [[]]
};

targets

An array of elements that are acceptable targets for dragable elements.


items

An array of arrays where the inner arrays contain objects each representing one slice of the cobler.


disabled

If the Cobler instance is disabled then the html representation of each slice is rendered but moving and editing is disabled. This is used to render the result when not editing it.


itemContainer


itemTarget



Collections


addItem



Events

Cobler utilizes a pub/sub event system, an event can be subscribed to by calling the 'on' methed of an instantiated Cobler. cb.on('change', function(e){ console.log(e); }); Events can also be triggered via cb.trigger('change') The following are the internal events that are triggered

activate

triggered when a slice has been selected as the active slice

deactivate

triggered when a slice has been deactivated

change

triggered when the values of any slice are triggered

add

triggered when a slice is added to a collection including being moved from another collection

remove

triggered when a slice is removed from a collection including when being moved to a new collection

reorder

triggered when the order of slices in a collection changes

moved

triggered when a slice is moved in anyway, either order or to a new collection



Type spec

In order for Cobler.js to really be useful in any meaningful way we must define at least one type of 'slice' to be used. Each type of slice used by cobler needs to have its own api filled in to so that it can be interacted with. Often thes slices are packed together for similar goals, i.e. a form builder.


render

The render function recieves no inputs and returns the html for the view of the slice.


toJSON

This function should return the JSON representation of this slice including all information needed to reconstruct it from scratch including the 'widgetType'


edit

This funciton is called when the 'slice' goes into edit mode and should to get back out of edit mode the slice should be updated with new data.


get

Returns data needed to rerender the object this can be a subset of the toJSON function or completely different and does not need to include the 'widgetType'


set

This is a function that is passed an object that should update/initialize the slice


initialize

This function is triggered after the render function and can access the dom of the slice.


container

This is a reference to the outer draggable container that this slice lives inside of.


© Adam Smallcomb 2017