Global

Methods

activateButton(input, textarea, button)

Enables or disables button if conditions are passed (Inputs are filled)
Parameters:
Name Type Description
input object Input element, expecting to be filled in order the button to be activated
textarea object Textarea element, expecting to be filled in order the button to be activated
button object The button element
Source:
Example
app.dom.activateButton(input, textArea, button);

addClass(className, element) → {string}

Adds class to DOM element
Parameters:
Name Type Description
className string Class name string
element object The element
Source:
Returns:
Type
string
Example
app.dom.element.addClass('className', selector);

addLastItem(item) → {object}

Adds the newly created item to the DOM table.
Parameters:
Name Type Description
item object {id: number, title: "String", content: "String"}
Source:
Returns:
Type
object
Example
this.addLastItem({
      id: id,
      title: itemName,
      content: content
    });

append(elements, parent) → {object}

Appends html elements inside parent selector. Can append one or multiple elements
Parameters:
Name Type Description
elements array Array of html elements
parent object Parent selector
Source:
Returns:
Type
object
Example
app.dom.append([input, textArea, button], form);

button(options, text) → {object}

Creates BUTTON element. Adds element attributes if passed as object parameters
Parameters:
Name Type Description
options object Parameters to be added as element attributes
text string Text for the button label
Source:
Returns:
Type
object
Example
var button = app.dom.button({
   id: 'itemSaveButton',
   class: 'btn btn-primary disabled',
   disabled: true
}, 'Button text');

deleteItem()

Deletes item from the localstorage. Gets all items, deletes one, cleans from `null` values and then saves it again. The id is passed by event data transfer
Source:
Example
app.data.deleteItem();

deleteRow(row)

Deletes item from the view table and sends ID number for the deleting method from database
Parameters:
Name Type Description
row object The event object
Source:
Example
<span onclick="MyDOs.deleteRow(event)">Delete</span>

div(options, callback) → {object}

Creates DIV element. Adds element attributes if passed as object parameters
Parameters:
Name Type Description
options object Parameters to be added as element attributes
callback function Callback function
Source:
Returns:
Type
object
Example
var wrapper = this.dom.div({class: 'item-rows', id: 'itemsListWrapper'});

editItem()

Edits the currently selected item. The data is passed by event data transfer
Source:
Example
app.data.editItem();

editRow(row)

Edits selected item in the view table. Updates the html values and sends item object to database editing method `data.editItem()`
Parameters:
Name Type Description
row object Event object
Source:
Example
<span onclick="MyDOs.editRow(event)">Edit</span>

event(elem, events, fn)

Add event listener. Can add multiple events to single element
Parameters:
Name Type Description
elem object HTML selector
events string String with events or single event
fn function Event function
Source:
Example
app.dom.event(input, 'blur keyup', function () {
  ...
});

getAllItems(key) → {array}

Gets All items from the database
Parameters:
Name Type Description
key string The name of the database table (The LocalStorage key name)
Source:
Returns:
Type
array
Example
this.data.getAllItems('items');

getLastItemId(key) → {number}

Gets last item ID from the database. If no current items are inserted, returns 0
Parameters:
Name Type Description
key string The name of the database table (The LocalStorage key name)
Source:
Returns:
Type
number
Example
this.data.getLastItemId('items'); // 5

id(id) → {object}

Gets DOM element by id
Parameters:
Name Type Description
id string The id of the html element
Source:
Returns:
Type
object
Example
var selector = app.dom.element.id('someElementId');

input(options) → {object}

Creates INPUT element. Adds element attributes if passed as object parameters
Parameters:
Name Type Description
options object Parameters to be added as element attributes
Source:
Returns:
Type
object
Example
var input = app.dom.input({
 id: 'itemNameField',
 placeholder: 'Note Name:',
 class: 'form-control item-name-field',
 maxlength: '30'
});

parse(data) → {array}

Gets JSON and do JSON Parse to Array
Parameters:
Name Type Description
data object The JSON object to be parsed to JavaScript Array
Source:
Returns:
Type
array

save(key, item, callback)

Saves the inserted item in the database. Gets all the items from the localstorage and unshifts the new item, then saves the newly updated object to the localstorage
Parameters:
Name Type Description
key string The name of the database table (The LocalStorage key name)
item object The item object, contains id, title, content...
callback function Callback function to do something after the item is saved, like updating the view etc.
Source:
Example
var itemObj = {
  id: id,
  title: itemName,
  content: content
};
this.data.save('items', itemObj, function () {
  this.addLastItem(itemObj);
});

saveItem(itemName, content)

Sends the item data to the database saving method this.data.save() and executes addLastItem() function to render the item in the view
Parameters:
Name Type Description
itemName string The item title
content string The item content
Source:
Example
app.saveItem(input.value, textArea.value);

textarea(options) → {object}

Creates TEXTAREA element. Adds element attributes if passed as object parameters
Parameters:
Name Type Description
options object Parameters to be added as element attributes
Source:
Returns:
Type
object
Example
var textArea = app.dom.textarea({
   id: 'itemContentField',
   placeholder: 'Description:',
   class: 'form-control item-description-field',
   maxlength: '50'
});

write(data) → {json}

Gets Array JSON Stringify
Parameters:
Name Type Description
data array The javascript Array to be JSON stringified
Source:
Returns:
Type
json