CXM_jquery.anubis 2.21 KB
/*
 * Created by PyramIDE.
 * User: Jeremy
 * Date: 21/08/2012
 * Time: 16:52
 * 
 */

read calexium_lib/web/CXM_making_a_web_site.anubis
read tools/printable_tree.anubis
read tools/basis.anubis

/* jQuery Actioner type */
public type JQuery_Actioner_type:
  jqform,
  jqlink,
  jqscript.

/* jQuery Actioner */
public type JQuery_Actioner:
  jQuery_actioner(Actioner_Target target, JQuery_Actioner_type type, String url_or_form_id_or_script).

/* jQuery Selector - http://api.jquery.com/category/selectors/ */
public type JQuerySelector:
  element(HtmlId id),
  element_class(String name),
  childs(HtmlId id).

public define String
  format_jquery_selector
  (
    JQuerySelector selector
  ) =
  if selector is
  {
    element(html_id) then
      if html_id is htmlId(id) then "'#" + id + "'",
      
    element_class(name) then
      "'." + name + "'",
      
    childs(html_id) then
      if html_id is htmlId(id) then  "'#" + id + " > *'"
  }.

/* */
public define Script
  jquery_ready
  (
    String  code  //javascript code to execute when the document is ready
  )=
  script("text/javascript","$(document).ready(function(){"+code+"});").
  
        
/* jQuery default js files */
define List(HTML_Head_Tag)
   jquery_defaults
   =
   [
     js(js_file("/js/jquery/jquery-1.11.3.js")),
     js(js_file("/js/jquery/jquery-ui-1.11.4/jquery-ui.min.js")),
   ].
   
/* Initialize jQuery in compatiblity mode with jQueryUI */
public define List(HTML_Head_Tag)
  jquery_init
  (
   String web_dir,
   String theme_name
  )
  =
    if file_exists(web_dir+"/public/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.min.css") then
      [ css(css_file("/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.min.css")),
        css(css_file("/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.structure.min.css")),
        css(css_file("/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.theme.min.css")) . jquery_defaults ]
    else
      println("Jquery Theme not found "+web_dir+"/public/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.min.css");
      //TODO change to real default jquery ui css
      [ css(css_file("/js/jquery/jquery-ui-1.11.4/theme/"+theme_name+"/jquery-ui.min.css")) . jquery_defaults ]
  .