Javascript micro-API

Some useful variables and functions are accessible by your javascript in a raw text component.

Variables

ws_mode: the current access mode

0 for lambda visitor, WS_EDIT, WS_PREVIEW, WS_EXPLORE, or WS_DEBUG, for edition modes.
ws_currentPageName: the name of the page displayed in the menu
ws_user_lang: the language of the actual page
ws_page_langs: the available languages for the actual page


Example:

<script type="text/javascript">
if (!ws_mode){   <================= CALL THE VISIT COUNTER ONLY IN SIMPLE VISIT MODE .... your counter code...
}
</script>

Files associated with raw text

HTML attributes data-attached_files and data-server_files of the raw text are designed to build an array of filenames.


Example:

<script id="myScriptId">

(function(){

var container = document.getElementById('myScriptId').parentNode;

var originalFilenames = eval('[' + container.getAttribute('data-attached_files') + ']');

var realFilenames = eval('[' + container.getAttribute('data-server_files') + ']');

var innerHTML = container.innerHTML;

for (i = 0; realFilenames [i]; i++)

  innerHTML += '<img src="data/rawdata/' + realFilenames[i] + '" alt="' + originalFilenames[i] + '">';

container.innerHTML = innerHTML;

})();

</script>

Display popup

ws_popupElement(id, style, days): get an element of the site by its id (a string like '<page>/<id>') and put it in a popup window stylized by a CSS string style. The window will not be redisplay during days (days=-1 to force each time display).

Asynchronous functions

ws_request(url, callBack): ask for an asynchronous processing, with HTML response received by callBack(response)
ws_htmlRequest(url, domRecipient, callBack): get some HTML from an url , put it in innerHTML of a DOM element, then execute  callBack(response) if any
ws_getElementById(id, bufId, callBack): get an element of the site by its id (a string like '<page>/<id>'), put it in innerHTML of a DOM element with id bufId, then execute  callBack(response) if any

Example: a basic slider (http://basic-slider.com) with 3 slides defined as 3 blocks in another page to allow comfortable edition

<link rel="stylesheet" href="basic-jquery-slider.css">
<script src="jquery-1.6.2.min.js"></script>
<script src="basic-jquery-slider.min.js"></script>

<div id="container">
 <div id="banner">
  <ul class="bjqs">
          <li><dd id="actu01"></dd></li>
          <li><dd id="actu02"></dd></li>
          <li><dd id="actu03"></dd></li>
  </ul>
 </div>
</div>
   
<script type="text/javascript">
    ws_getElementById("news-home/Z502a12caf0dbe", "actu01");
    ws_getElementById("news-home/Z506c2ac8bee2e", "actu02");
    ws_getElementById("news-home/Z502a1ebae1238", "actu03");

        $(document).ready(function() {
          // Let some time to get the slides before animation
          setTimeout("$('#banner').bjqs({animation: 'slide'});", 1000);
       });
</script>