Skip to content
This repository was archived by the owner on Aug 6, 2022. It is now read-only.

V.5. Functions

Andrey Bogdanov edited this page Mar 1, 2016 · 30 revisions

Note: Functions that are used internally are not described here.

lord.isAudioType(mimeType)

Returns true if mimeType is one of MIME-types for an audio (starts with audio/). Otherwise returns false.

lord.isAudioType(mimeType)

Returns true if mimeType is one of MIME-types for an image (starts with image/). Otherwise returns false.

lord.isVideoType(mimeType)

Returns true if mimeType is one of MIME-types for a video (starts with video/). Otherwise returns false.

lord.getCookie(name[, defValue])

Returns a cookie with the name name. If the cookie with this name does not exists, returns defValue (if specified), or undefined. The cookie is returned as a string (as it is stored by the browser).

lord.setCookie(name, value, options)

Stored a cookie with name name and value value as a string. If options contains the expires property, the property is converted from a Date object to a string. See this article for details.

lord.deleteCookie(name)

Deletes a cookie with the name name.

lord.getLocalObject(key[, defValue])

Returns the value stored in localStorage under the key key. If there is no such value, defValue is returned, if specified, otherwise undefined is returned. All errors thrown are catched, you do not need to catch them manually. Note: JSON.parse() is applied to the value before it is returned.

lord.setLocalObject(key, value)

Stores value in localStorage under key key. Returns true on success, otherwise returns false. All errors thrown are catched, you do not need to catch them manually. Note: JSON.stringify() is applied to the value before it is stored.

lord.removeLocalObject(key)

Removes the value stored in localStorage under key key. Returns true on success, otherwise returns false. All errors thrown are catched, you do not need to catch them manually.

lord.getSessionObject(key[, defValue])

Returns the value stored in sessionStorage under the key key. If there is no such value, defValue is returned, if specified, otherwise undefined is returned. All errors thrown are catched, you do not need to catch them manually. Note: JSON.parse() is applied to the value before it is returned.

lord.setSessionObject(key, value)

Stores value in sessionStorage under key key. Returns true on success, otherwise returns false. All errors thrown are catched, you do not need to catch them manually. Note: JSON.stringify() is applied to the value before it is stored.

lord.removeSessionObject(key)

Removes the value stored in sessionStorage under key key. Returns true on success, otherwise returns false. All errors thrown are catched, you do not need to catch them manually.

lord.in(arr, val[, strict])

Returns true if the array arr contains the value val. Otherwise returns false. If strict casts to boolean true, the comparison is strict (===), otherwise it is not strict (==).

lord.arr(obj)

Creates an array from the array-like object obj. Returns the array. obj properties must be numeric, and it must have the length property.

lord.hasOwnProperties(obj)

Returns true if the object obj has at least one own property (Object.prototype.hasOwnProperties() method is used to perform the chech). Otherwise returns false.

lord.forIn(obj, f)

Applies the function f to each key-value pair of the object obj, the value being the first argument, and the key being the second one.

lord.mapIn(obj, f)

Creates an array from the object obj by applying the function f to each key-value pair of the object obj, the value being the first argument, and the key being the second one. The array is populated by the results of the function applications. Returns the array.

lord.filterIn(obj, f)

Creates a new object from the object obj by applying the function f to each key-value pair of the object obj, the value being the first argument, and the key being the second one. The new object is populated by those key-value pairs only, for which the function f returns a value which casts to boolean true. Returns the new object. Warning: Pay attention to that this function creates an object, unlike other functions from this group.

lord.toArray(obj)

Creates an array from the valuye of the object obj. Returns the array.

lord.removeChildren(el)

Removes all child nodes from the node el.

lord.removeSelf(el)

Removes the node el from it's parent node.

lord.wrap(el, wrapper)

Wraps the node el with the node wrapper.

Example:

<!--HTML before-->

<div class="parent">
    <span id="theSpan">som text</span>
</div>
/*JS*/

var font = lord.node("font");
font.color = "red";

lord.wrap(lord.id("theSpan"), font);
<!--HTML after-->

<div class="parent">
    <font color="red">
        <span id="theSpan">som text</span>
    </font>
</div>
lord.last(arr)

A shortcut for arr.slice(-1)[0].

Note: Do not use this function. It is very likely to be removed in the future releases (if not yet).

lord.gently(obj, f, options)

Applies the function f to every value of object/array obj. If obj is an array, the index of an element is passed to f as the second argument. Otherwise, the corresponding key is passed.

The application is done by portions with some timeout to prevent UI blocking.

Possible options:

  • delay The delay between data portions processing. Default: undefined (no delay).
  • n Count of elements to be processed at one time. Default: 1.
  • promise If casts to boolean true, it is assumed that f returns a promise, so .then() will be called on it's result every time. Default: false.

Returns a promise that resolves when all processing is finished.

lord.regexp(s)

Parses a string representation of a RegExp. Returs the resulting RegExp.

Example:

var rxParsed = lord.regexp("/^(test)\s(text)/gi");
/*Equivalent to:*/
var rxNative = /^(test)\s(text)/gi;
lord.id(id)

A shortcut for document.getElementById(id).

lord.query(query[, parent])

A shortcut for (parent || doucment).querySelectorAll(query). The only difference is that the result is always an instance of Array.

lord.queryOne(query[, parent])

A shortcut for (parent || doucment).querySelectorAll(query).

lord.name(name[, parent])

A shortcut for lord.query("[name='" + name + "']").

lord.nameOne(name[, parent])

A shortcut for lord.queryOne("[name='" + name + "']").

lord.addClass(element, classNames)

Adds CSS class(es) classNames to the element element. classNames must be a string. Multiple classes are passes like so: "class1 class2".

Example:

var el = lord.id("theElement");
lord.addClass(el, "coolElement"); //Adds .coolElement class
lord.addClass(el, "even cooler element"); //Adds .even, .cool, and .element classes
lord.hasClass(element, className)

Returns true if the element element has CSS class className. Otherwise returns false.

lord.removeClass(element, classNames)

Removes CSS class(es) classNames from the element element. classNames must be a string. Multiple classes are passes like so: "class1 class2".

Example:

var el = lord.id("theElement");
lord.removeClass(el, "coolElement"); //Removss .coolElement class
lord.removeClass(el, "even cooler element"); //Removes .even, .cool, and .element classes
lord.node(type[, text])

A shortcut for document.createElement(type). If the value of type is "text", a shortcut for document.createTextNode(text || "").

lord.toCenter(element[, sizeHintX[, sizeHintY[, border]]])

Places the element element at the center of the window. If sizeHintX or sizeHintY are not valid numbers, element.offsetWidth and element.offsetHeight values are used. If border is a valid number, it's doubled value is added to element's width and height when calculating the position.

lord.reloadPage()

A shortcut for document.location.reload(true).

lord.showPopup(text[, options])

Creates an instance of lord.PopupMessage with the values text and options being passed to it's constructor. Then, calls the created object's .show() method and returns the object.

lord.showNotification(title[, body[, icon]])

Requests permission to show desktop notifications, then shows a notification with title, body and icon values being passed to it's constructor.

lord.text(id)

A wrapper for lord.model("tr").tr[id]. Returns a translation with identifier id, if exists. Otherwise, returns the identifier itself.

lord.deviceType([expected])

If expected is a string, retunrs true if current device type matchs that string (either "desktop" or "mobile"). If expected casts to boolean false, returns the device type as a sting.

Example:

lord.deviceType("mobile") //true on mobile devices, false on desktop devices
lord.deviceType() //"mobile" on mobile devices, "desktop" on desktop devices
lord.showDialog(body, options)

TODO

lord.generateImageHash(imageData, sizeX, sizeY)

Generates a special hash for the ArrayBuffer imageData. sizeX and sizeY must be valid numbers (image dimensions). The algorithm is taken form the Dollchan Extension Tools script.

lord.getPlainText(node)

Returns the plain text contents of the element node without the HTML markup. End of lines are treated as expected, unlike the native .textContent. This method is much slower than .textContent, though.

Note: The code for this function was found somwhere on the Internet, I did not write it myself.

lord.activateTab(a)

Used in conjunction with.

lord.notificationsEnabled = function()
lord.soundEnabled = function()
lord.playSound = function()
lord.hash = function(hash)
lord.data = function(key, el, bubble)
lord.scriptWorkaround = function(parent)
lord.addTemplate = function(name, html)
lord.template = function(templateName, model, noparse)
lord.createDocumentFragment = function(html)
lord.createStylesheetLink = function(href, prefix)
lord.createScript = function(src, prefix)
lord.compareRegisteredUserLevels = function(l1, l2)
lord.compareRatings = function(r1, r2)
lord.model = function(modelName)
lord.get = function(what, enableCache)
lord.api = function(entity, parameters, prefix)
lord.post = function(action, formData, progressBarContext, progressBarOptions)
lord.now = function()
lord.settings = function()
lord.setSettings = function(model)
lord.checkError = function(result)
lord.handleError = function(error)
lord.toMap = function(arr, keyGenerator)
lord.readAs = function(blob, method)
lord.series = function(arr, f)

Clone this wiki locally