Namespace: html

html

HTML helper functions

Source:

Members

defaults :Object

Default options

Type:
  • Object
Source:

Methods

$toHtml($element) → {String}

The HTML source code of a jQuery element.

Parameters:
Name Type Description
$element jQuery

The target element. If multiple elements match, the first one will be chosen.

Source:
Returns:

The source code of the element

Type
String

attributes(attributes, escape) → {string}

Creates a string of HTML element attributes given as an object. The class attribute should be given as classes.

Parameters:
Name Type Argument Default Description
attributes object
escape boolean <optional>
false

If true, the result will be run through vorple.html.escapeHtmlChars() before returning. The attribute values will be escaped always, so this will double-escape values.

Source:
Returns:
Type
string
Examples
vorple.html.attributes( { id: "foo", classes: "bar" } )
  == ' id="foo" class="bar"'
  
vorple.html.attributes( 
    { id: "foo", class: "bar" },
    { escape: true } )
  == ' id="foo" class="bar"'
 
  

escapeHtmlChars(text) → {string}

Replaces &, <, >, " and ' with corresponding character entity references.

Parameters:
Name Type Description
text string
Source:
Returns:
Type
string
Example
vorple.html.escapeHtmlChars( '<div id="foo">' ) 
    == '&lt;div id=&quot;foo&quot;&gt;'
    

Creates an <a> tag.

The url where the link points to, the content of the link and the optional tag attributes can be given as separate parameters or as a single object { url: ..., content: ..., options: ... }.

If multiple links are given as an array, a choice popup is created with those options when the main link is clicked.

Parameters:
Name Type Argument Description
url string | object | Array.<object>

The url of the link, or an object containing the required data, or an array of links.

content string

The content text of the link.

options object <optional>

Additional attributes added to the tag.

Source:
Returns:

The HTML code for the link tag.

Type
string
Example
 
vorple.html.link( 'foo', 'Bar', { classes: 'baz' } )
    == <a href="foo" class="baz">Bar</a>
    
vorple.html.link({ url: 'foo', content: 'Bar', options: { classes: 'baz' })
    == <a href="foo" class="baz">Bar</a>
    
vorple.html.link(
    [
        { url: 'foo', content: 'bar' },
        { url: 'baz', content: 'xyzzy' }
    ],
    'popup'
);     
    

p()

Shorcut for vorple.html.tag( 'p', content, options ).

Source:
See:

quote(content, quotemarks) → {String}

Wraps text inside quotemarks.

Parameters:
Name Type Argument Description
content String

The content to wrap inside quotes

quotemarks String | Array <optional>

The quotemarks to use. If a string is given, the same string is used as both opening and closing quotes. Two strings can be given as an array. The first string will be used as the opening quote and the second string as the closing quote. Default is vorple.html.defaults.quotemarks (").

Source:
Returns:
Type
String
Example
 vorple.html.quote( 'Hello!', ['-=', '=-'] )
  == '-=Hello!=-'

replaceAttributes($element, newAttributes)

Replaces a jQuery element's attributes with the given new set.

Parameters:
Name Type Description
$element jQuery

Element to change

newAttributes object

New set of attributes

Source:

tag(name, content, options)

Creates an HTML tag with the given content. If content is not given (or it is false/null), the tag is closed with '/ >'.

Parameters:
Name Type Argument Description
name String

Tag name

content String | bool | null <optional>

Content to be wrapped in the tag

options Object <optional>
  • endTag (default "auto"): "auto", "always" or "never". If "auto", the end tag is added only if there is content, otherwise the tag is closed with '/ >'. If "always", the end tag is always added. If "never", only the start tag is given.
Source:
Examples
vorple.html.tag( 'div', 'foo' ) 
  == '<div>foo</div>'
  
vorple.html.tag( 'div', 'foo', { id: 'bar' } );
  == '<div id="bar">foo</div>'

url(filename, path) → {string}

Returns the filename appended to the path name unless the filename is an URL or it's relative to the root (starts with a slash), in which case the filename parameter is returned as is and the path is ignored.

If both the filename and the path are empty or null, a hash (#) is returned.

Parameters:
Name Type Argument Description
filename string <optional>
path string <optional>

Default path to the file, no trailing slash

Source:
Returns:
Type
string
Examples
var url = vorple.html.url( 'img.jpg', '/path/to' ); 
// url == '/path/to/img.jpg'
var url = vorple.html.url( 'images/img.jpg', '/path/to' ); 
// == '/path/to/images/img.jpg'
var url = vorple.html.url( 'http://example.com/img.jpg', '/path/to' ); 
// url == 'http://example.com/img.jpg' 
var url = vorple.html.url( '/images/img.jpg', '/path/to' ); 
// url == '/images/img.jpg'
Vorple Copyright © 2011-2014 the Vorple project
Documentation generated by JSDoc 3.2.2 on Wed May 07 2014 14:47:40 GMT+0300 (EEST) using the DocStrap template.