Difference between revisions of "JavaScript API"

From ElphelWiki
Jump to: navigation, search
(Api)
m (Configuration)
Line 25: Line 25:
 
camera = new Camera('http://192.168.1.3')
 
camera = new Camera('http://192.168.1.3')
  
alert(camera.model_name()) // fetches the data and returns it, the value gets cached
+
camera.model_name(function(model_name) { alert(model_name) } ) // fetches the data and returns it, the value gets cached
  
 
camera2 = new Camera('http://zimba:1234@192.168.1.3', {
 
camera2 = new Camera('http://zimba:1234@192.168.1.3', {
Line 31: Line 31:
 
   model_name: '203'})
 
   model_name: '203'})
  
alert(camera.model_name()) // returns the data directly
+
camera.model_name(function(model_name) { alert(model_name) } ) // returns the data directly
  
 
</pre>
 
</pre>

Revision as of 12:13, 19 November 2005

in English | [[{{{de}}}|deutsch]] | [[{{{fr}}}|français]] | по-русски | автоперевод | 中文版 | 机械翻译


This work is under development

Authors : Khlut, zimbatm

The javascript library is intended to be used in different environments. The usage scenarios are HTML interfaces, which can easily be extended with the library. Interfaces can also be created, by using a simple extension syntax.

Goals

  • Easy to embed in existing HTML
  • Auto-configurable
  • HTML generation

Essay

Configuration

The configuration of a camera goes through a new object's creation.

The object automatically retrieves the data using asyncronous Http requests. Optionally, you can provide the data trough an object to avoid too much queries.

Example:

camera = new Camera('http://192.168.1.3')

camera.model_name(function(model_name) { alert(model_name) } ) // fetches the data and returns it, the value gets cached

camera2 = new Camera('http://zimba:1234@192.168.1.3', {
  api: Api.Axis,
  model_name: '203'})

camera.model_name(function(model_name) { alert(model_name) } ) // returns the data directly

Api

We need a way to make the lib compatible with the different apis and api versions.


Testing that a feature exists :


if (camera.ptz) { // if the function is defined
  document.getElementById('ptz_control').innerHTML = (new Template.Ptz(camera)).source()
}

HTML Generation


Template.Image = function(camera_source) {
  this.template = '<img src="'+camera_source+'" />'
}
Template.prototype = new Template()

image = new Template(camera.picture_path())

document.getElementById('some_element').innerHTML = image.source()