D a m o Namespace: $scp

$scp

This is the global Damo's namespace. Each variable or function that has to be created must be a property/method of the scope $scp. As a convention the core properties and methods of Damo are prefixed with a $. At the contrary, the user's functions or variables shall still be a member of $scp but has no need to be prefixed by a $.
Example
//Damo's datamodel
$scp.$dm = myJson;
//Damo's internal function
$scp.$updateView = function() { ...}

//user's variable
$scp.myNiceVariable = 123;
//user's function
$scp.myAwsomeFunction = function() {
    console.log('hello');
};
Source:

Members


(static) $config

Object for the basic configuration of Damo. Its members are :
  • damperDelay : bigger the app, higher it is (default is 100)
  • sliderDelay : delay for hide/show (default is 200)
  • iterationBreak : need to be increased when there are many nested levels of directives and loops (default is 10)
  • directiveDepth : need to be increased when there are many nested levels of directives (default is 3)
Source:

(static) $directive

Object that record the available directives for damo. Its members are :
  • seed : the name of the root data model of the directive
  • template : the path to the directive's template
Example
$scp.$directive.myDirective =  {
  seed 		: 'book',
  template 	: 'templates/myTemplate.html'
};
...
//html template 'templates/myTemplate.html'
<div class="myStyle">
  <span id="book.price"></span>
</div>
Source:

(static) $dm

The variable where the data model (dm) is stored. It is mandatory and must be defined at the start of the script.
Example
var myJsonDataModel = {
    name : 'My Library',
    books : [
      {
        title : 'Document no 1',
        booked : 1,
        pages : 265,
        history : [
          { date : '2015-10-01' },
          { date : '2015-08-12' },
          { date : '2015-02-07' },
        ]
      },
      {
        title : 'Document no 2',
        booked : 0,
        pages : 308,
        history : [
          { date : '2016-03-02' },
          { date : '2016-02-12' },
          { date : '2016-01-15' },
        ]
      }
    ]
   }
$scp.$dm = myJsonDataModel;
Source:

(static) $filter

Object that record the available filters for damo. Each filter is a function that returns the result of the filtering.
Example
$scp.$filter.formatInt = function(num) {
	return parseInt(num);
};
Source:

(static) $route

Object recording the current route state of damo.
Example
$route : {
    last    : '/',
    current : '/infos',
    next    : null
  }
Source:

(static) $routing

Array that record the possible routes available to damo.
Example
$scp.$routing = [
  {
    url     : '/',
    template   : 'index.html'
  },
  {
    url     : '/infos',
    template   : 'page2.html'
  }
];
Source:

Methods


(static) $ArrayUnique()

Array filter that returns the array with only unique values.
Example
myArray.filter($scp.$ArrayUnique);
Source:

(static) $buildDirectives(scope)

Parse the available directives to set them up if necessary.
Parameters:
Name Type Description
scope object on which the directive parsing takes place. This is a jquery object.
Source:

(static) $buildForms()

The form are enclosed inside a tag having an attribute damo-form="submitFuctionName", where submitFuctionName is a user function that must be executed when the form is submitted. In order to be submitted the html template must also have an element with an attribute damo-formsubmit="submitFuctionName", a button for instance. When 'damo-formsubmit' is clicked the scope first retrieve all the key/value contained, and visible, in the form, and store it in the variable $scp.$submitData. This done, the scope calls the user function $scp.submitFuctionName, where the variable $scp.$submitData is available, and executes it.
Example
//html
<div damo-form="myFormSubmit">
	  ...
   <button damo-formsubmit="myFormSubmit">Submit the form</button> 
</div>

//code :
$scp.myFormSubmit = function() {
    console.log($scp.$submitData);
}
Source:

(static) $buildLoops()

Function that build the html loops from the given template. The idea is to setup a hidden tag describing the the loop, with the attribute damo-startloop. Each time the loop has to be reviewed, this tag is compared with the current status of the loop.
Source:

(static) $changePage(page)

Function that set the required page visible, and the others unvisible.
Parameters:
Name Type Description
page string the name of the page (i.e. routing[x].url) to be loaded
Source:

(static) $concatenePages()

Concatenation of the different templates declared in the $scp.$routing array, to make a unique document.
Source:

(static) $Damo(obj, prog)

Build the application from a given datamodel, or an url where to find the data model, and a function (prog) that will be executed after the first load of the application.
Parameters:
Name Type Description
obj object | string is the Json data model of your application
prog object is the script that shall apply to the view once loaded
Source:

(static) $rxFormat(str) → {string}

String filter that turns a usual string into a regular expression.
Parameters:
Name Type Description
str string the string that has to be transformed
Returns:
str formated to take place as a regular expression
Type
string
Source:

(static) $seekData(filter, param) → {mixed}

Seek for the value of a property in the scope $scp and in the data model $scp.$dm, filtered if necessary.
Parameters:
Name Type Description
filter string The name of the filter that must be used.
param string The string that describe the position of the data in the data model, e.g. shop.stage[3].books[1].price
Returns:
the filtered value
Type
mixed
Source:

(static) $setConditions()

Search for the html tags having an attribute damo-if="condition", evaluates its value, i.e. condition, hand hide/show the concerned tag on the html view.
Example
<div damo-if="myCondition">
...
</div>
Source:

(static) $setDmValues()

Set the values of the html tags select, input and textarea, consistently with the data model $scp.$dm. The tag's ids must be the the json path of the concerned property :
Example
<input id="library.books[0].title">
Source:

(static) $setObjProperty(obj, path, newValue)

Set a property, located by its json path, to a value inside an object.
Parameters:
Name Type Description
obj object is the whole object in which the property must be set
path string is the object path of the branche where the property must be set
newValue string the new value to set up for the property
Source:

(static) $updateLoops()

Update the loops of the application if needed. If an array that displays as a loop is modified, it is necessary to rebuild the loop with the correct elements of the array.
Source:

(static) $updateView()

Update the view. Useful when the datamodel $scp.$dm has been changed in the script and you want to see the result on the view. This update has to be programmatically called, there is no dirty checking that could call it.
Source: