Skip to content

client plugin

Frank van Viegen edited this page Sep 23, 2015 · 2 revisions

This module exposes functions to fetch contextual data, such as the executing user agent, which happening the plugin is running in and its members. Also, it includes functions to invoke server-side rpc code.

Functions

time()

Returns the current server time as an UNIX epoch in seconds. Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	time = new Date (Plugin.time() * 1000)
	Dom.text "Current time is " + time.toString()

Date()

Provides a coffeescript date object containing the current server time. Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	Dom.text "Current time is " + Plugin.Date().toString()

colors()

This returns an object containing several colorcodes used to style your plug-in.

Colors are currently:

  • highlight: #ba1a6e
  • highlightText: #ffffff
  • bar: #0077cf
  • barText: #ffffff

Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	Dom.div !->
		Dom.style
			color: Plugin.colors().highlight	

		Dom.text "+ Add reply"
		Dom.onTap !->
			Modal.prompt ("Your reply"), (d) !->
				Modal.show ("Thank you!")

code()

Code indicating the happening/plugin instance.

agent() (env)

Hash containing agent specifics and version numbers. Keys: ios, android. Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	a = Plugin.agent()
	if a.ff
		Dom.text "You are running on Firefox v" + a.ff
	else if a.chrome
		Dom.text "You are running on Chrome v" + a.chrome
	else 
		Dom.text "You are running on " + a.pre

api (env)

Returns the API level used.

openUrl(url) (env)

Opens given the URL in a new tab, not unlike window.open(url) Note that the URL will be relative to the current URL unless a protocol is given (i.e. 'http://')

intent(opts) (env)

Allows the usage of Android intents. To open up external apps for example. More information: Chrome developer

name() (env)

Returns the name of the Plug-in instance

ownerId() (env)

Returns the id of the person who initiated the plug-in

Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	Dom.text "This plug-in is started by " + Plugin.userName(Plugin.ownerId())

created() (env)

Returns an epoch timestamp from when this plug-in instance has been created.

Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	delta = Math.floor (Plugin.time() - Plugin.created())/3600
	Dom.text "This plug-in is running for \#{delta} hours."

build() (env)

Returns the number of builds this plug-in's development has seen thus far.

groupAvatar (env)

Obtains the group image key. The only practical usage of this is to feed it into Ui.avatar:

	Plugin = require 'plugin'
	Ui = require 'ui'
	Ui.avatar Plugin.groupAvatar()

Note, this renders an empty avatar when the group avatar is set to random.

groupName() (env)

Returns the group name as a string.

userInfo(id=memberId()) (env)

Summons a modal revealing the information about the user.

memberId() (env)

Returns the id of current user within the current group.

userName(id=memberId()) (env)

Returns the screen name for user.

userAvatar(id=memberId()) (env)

Returns the key of avatar for user, or false if there's none. The only practical usage of this is to feed it into Ui.avatar:

	Plugin = require 'plugin'
	Ui = require 'ui'
	Ui.avatar Plugin.userAvatar()

isAdmin(id=memberId()) (env)

Returns a boolean indicating the user is flagged as admin.

userIsBanned(id=memberId()) (env)

Returns a boolean indicating the user is banned.

isAdmin(id=memberId()) (env)

Returns a boolean indicating the user is flagged as admin.

assertAdmin() (env)

Throws an error when the current user is not an admin.

happeningId() (env)

ID of current happening.

users() (env)

Read only observable hash with all member details. Hash keys are user ids. Each item has name, avatar key, admin bool and joined join time.

resourceUri(name)

This provides an url to an external file.

Example:

	Plugin = require 'plugin'
	Dom = require 'dom'
	Dom.img !->
		Dom.prop 'src', Plugin.resourceUri("cat.png")

Basic topics

API reference

  • API Reference
    • Client
      • [client plugin](client plugin)
      • [client dom](client dom)
      • [client obs](client obs)
      • [client db](client db)
      • [client server](client server)
      • [client page](client page)
      • [client ui](client ui)
      • [client form](client form)
      • [client icon](client icon)
      • [client modal](client modal)
      • [client photo](client photo)
      • [client photoview](client photoview)
      • [client time](client time)
      • [client share](client share)
      • [client map](client map)
      • [client geoloc](client geoloc)
    • Server
      • [server event](server event)
      • [server plugin](server plugin)
      • [server http](server http)
      • [server db](server db)
      • [server photo](server photo)
      • [server time](server time)
  • Example UI elements

Advanced topics

Clone this wiki locally