Class: View

View

new View(options, data)

Main View class of Spark Framework. It is basically a div element. But it's configurable to be any kind of element. It's event driven. This means you can attach and listen custom events with your data. It also supports native DOM events.

Parameters:
Name Type Argument Description
options Object <optional>

Class options.

data * <optional>

Class data

Source:

Extends

Members

<static> EventTypes

A transposed map of goog.events.EventType

Source:

Methods

addClass(cssClass)

Adds new class name to element.

Parameters:
Name Type Description
cssClass string

New class name for the element.

Source:

appendToDocumentBody()

Appends view into document's body.

Source:

appendView(view)

Appends a new view into this view's element as a child.

Parameters:
Name Type Description
view spark.core.View

A spark.View instance to append.

Source:

<private> bindEvents_()

This method is responsible from binding DOM events to the element of this view. It uses native DOM event names which is all lowercase. If your options has an event name and a callback function in events object View will bind and listen those events automatically.

Source:

<private> createDomElement_()

Creates the element with the configuration passed to constructor.

Source:

destroy()

Destroys the view. It will unlisten all binded events including the DOM events and destroy all child views finally remove the element from document.

Source:

disable()

Disable view.

Source:

emit(eventName, data)

Dispatches an event and calls all listeners listening for events of this event. See also goog.events.Listenable.prototype.dispatchEvent

Parameters:
Name Type Argument Description
eventName string

Name of the event.

data * <optional>

Data which will passed to listeners

Inherited From:
Source:

enable()

Enable view.

Source:

freeze()

Freezes object to prevent adding new properties, updating or deleting existing properties.

Inherited From:
Source:

getAttribute(name)

Native getAttribute wrapper.

Parameters:
Name Type Description
name string

Atrribute name.

Source:

getChildren() → {Array.<spark.core.View>}

Returns the child views.

Source:
Returns:

DOM element of this view.

Type
Array.<spark.core.View>

getClass() → {string}

Returns class name of the element.

Source:
Returns:

Class name.

Type
string

getClassList() → {Array}

Returns class list of the element.

Source:
Returns:

List of class names.

Type
Array

getCssClass(options, optionalClass)

Helper method to set css class to options set.

Parameters:
Name Type Argument Description
options Object

Class options.

optionalClass string <optional>

Optinal CSS class which will added to default.

Source:

getData() → {*}

Returns class data.

Inherited From:
Source:
Returns:

Class data.

Type
*

getDomId() → {string|null}

Returns the DOM id if exists, otherwise it will return null.

Source:
Returns:
Type
string | null

getElement() → {Element}

Returns the DOM element.

Source:
Returns:

DOM element of this view.

Type
Element

getHeight() → {number}

Returns the height of the element.

Source:
Returns:

View element height.

Type
number

getOption() → {*}

Returns value of a key in options object.

Inherited From:
Source:
Returns:

Value of key or null.

Type
*

getOptions() → {Object}

Returns all options object.

Inherited From:
Source:
Returns:

Options object.

Type
Object

getUid() → {string}

Return unique id.

Inherited From:
Source:
Returns:

Unique id of this component.

Type
string

getWidth() → {number}

Returns the width of the element.

Source:
Returns:

View element width.

Type
number

hasClass(cssClass) → {boolean}

Returns true if element has that class name.

Parameters:
Name Type Description
cssClass string

Name of the class which will be tested.

Source:
Returns:

Whether element has a class name or not.

Type
boolean

isDestroyed() → {boolean}

Returns the object's destroy state.

Inherited From:
Source:
Returns:

Whether the object is destroyed or not.

Type
boolean

isDisabled()

Returns the current disabled state of the button.

Source:

off()

Override Object::off to remove events binded to DOM element.

Source:

on()

Override Object::on to support two way binding for DOM events.

Source:

once()

Override Object::once to support two way binding for DOM events.

Source:

removeAttribute(name)

Native removeAttribute wrapper.

Parameters:
Name Type Description
name string

Atrribute name.

Source:

removeClass(cssClass)

Remove a class name from the element.

Parameters:
Name Type Description
cssClass string

Name of the class which will be removed.

Source:

removeFromDocument() → {boolean}

Removes element from DOM if it is in DOM.

Source:
Returns:

Whether element removed from document or not.

Type
boolean

render(target)

Renders element into another View instance or a DOM element. Be aware that this method only appends the element of this class into another element. If the parent element is not in DOM, this method will not append the parent into DOM. Also you can use this method with renderTo option. If you pass renderTo as a View instance or DOM element, View will call render method by default.

Parameters:
Name Type Description
target spark.core.View | Element

Target view or element to be rendered.

Source:

setAttribute(name, value)

Native setAttribute wrapper.

Parameters:
Name Type Description
name string

Atrribute name.

value string

Attribute value.

Source:

setClass(cssClass)

Sets the class name of element. This will override existing class names. Use @addClass if you want to add new class name to the element.

Parameters:
Name Type Description
cssClass string

Class name.

Source:

setData(data)

Sets data of this class.

Parameters:
Name Type Description
data *

Data passed to class.

Inherited From:
Source:

setDomId(domId)

Sets DOM id.

Parameters:
Name Type Description
domId string

Id of the element.

Source:

setHeight(height)

Sets height of this view's DOM element.

Parameters:
Name Type Description
height string | number

Height of the element. It can be string with 'px' value or just number.

Source:

setOptions(options)

Sets options object of this class.

Parameters:
Name Type Description
options Object

Options object.

Inherited From:
Source:

setTemplate(template)

Basic templating support for Spark Framework. Currently templates can include variable tags like in Mustache templates. This can be changed in the future versions of the framework.

Variable tags should start with {{ and end with }}. That's borrowed from Mustache. Tags are not whitespace sensitive, so {{name}} and {{ name }} is the same.

Template should also be a function. Just make sure that function returns a string which will be the template. setTemplate will call the template function by passing the data of this View. So you can use class data in your template function. This will allow framework to easily integrate other template engines.

Spark Framework will use Closure Templates as it's default template engine. This is because to maintain the compiled code size advantage. I am also considering to support Mustache and Handlebar templates in Spark.

Parameters:
Name Type Argument Description
template string | function <optional>

HTML string of the element or function which will return the html string. Function will be called with class data. FIXME: Fix annotation for template variable, it should be {string|Function}

Source:

<private> setUid_()

Sets uid.

Inherited From:
Source:

setWidth(width)

Sets width of this view's DOM element.

Parameters:
Name Type Description
width string | number

Width of the element. It can be string with 'px' value or just number.

Source:

toggle()

Toggle view state. Disable if enabled, enable if disabled.

Source:
Spark Framework by Fatih Acet
Copyright © 2014 - Fatih Acet
Documentation generated by JSDoc 3.2.2 on 2015-07-19T22:09:35+00:00 using the DocStrap template.