Share » Learn » eZ Publish » ezjscore: eZ Publish JavaScript and...

ezjscore: eZ Publish JavaScript and Ajax framework

Wednesday 23 December 2009 10:45:21 am

  • Currently 4 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Template operators

has_access_to_limitation:

has_access_to_limitation( <string $module> ,
                          <string $function> ,
                          <array $limitations> )

PHP:

ezjscAccessTemplateFunctions::hasAccessToLimitation()

This function lets you check if a user has access to a certain limitation. It returns "true" if the user has access to the ones specified.

Example use:

has_access_to_limitation( 'ezjscore', 'call', 
                    hash( 'FunctionList', 'ezstarrating_rate' ) 
                        )

Note: Future releases of ezjscore will support adding an array of values to check – that is, being able to change 'ezstarrating_rate' above to array( 'ezstarrating_view', 'ezstarrating_rate' )

 

ezscript:

ezscript( array|string $scripts
         [, string $type='text/javascript'
          [, string $language='javascript'
           [, string $charset='utf-8'
            [, int $pack_level=2]]]] )

PHP:

ezjscPacker::buildJavascriptTag()

Packs several JavaScript files together and generates the script tag with the "src" attribute set to the packed file. $pack_level is an integer from 0 to 3, where 0 is disabled; 1 is just merging the files to one file; 2 is merging and simple white space removal; and 3 is merging and more complex white space removal using JSMIN. If you use 3, then make sure your JavaScript files are valid according to JSLint. To override the $pack_level globally, use the ezjscore.ini[eZJSCore]Packer setting.

 

ezscript_require:

ezscript_require( array|string $scripts
                 [, string $type='text/javascript'
                  [, string $language='javascript'
                   [, string $charset='utf-8'
                    [, int $pack_level=2]]]] )

Like ezscript(), but stores script files to be loaded using the persistent_variable.js_files template variable* instead of generating the script tag unless ezscript_load() is already called.

Optional parameters will not have any effect unless ezscript_load() is already called; then, the files are packed and the script tag is directly generated, typically when used in pagelayout and included templates.
* If the current view template does not support this (everything other than the content/view view, which loads node/view/*.tpl), then ezjscPackerTemplateFunctions::$persistentVariable is used instead.

 

ezscript_load:

ezscript_load( [ array|string $scripts
                [, string $type='text/javascript'
                 [, string $language='javascript'
                  [, string $charset='utf-8'
                   [, int $pack_level=2]]]]] )

Works like ezscript(), except that the optional $script parameter is prepended to the list of script files already saved with ezscript_require() before they are packed and the script tag is generated.

 

ezscriptfiles:

ezscriptfiles( array|string $scripts
              [, int $pack_level=2
               [, bool $ignore_loaded=false]] )

PHP:

ezjscPacker::buildJavascriptFiles()

Works like ezscript(), except instead of generating script tag(s), it will return an array of URLs and scripts to use. You can detect if an array element is a script URL or a JavaScript string by checking if it ends with '.js'. When $ignore_loaded is set to true(), it will ignore files already required with ezscript_require().

 

ezcss:

ezcss( array|string $css_files
      [, string $media='all'
       [, string $type='text/css'
        [, string $rel='stylesheet'
         [, string $charset='utf-8'
          [, int $pack_level=3]]]]] )

PHP:

ezjscPacker::buildStylesheetTag()

Packs several stylesheet files together, fixes relative URLs and links, and generates the link tag with the "href" attribute set to the packed file. $pack_level is an integer from 0 to 3, where 0 is disabled, 1 is just merging the files to one file, 2 is merging and simple white space removal and 3 is merging and more complex white space removal. To override $pack_level globally, use the ezjscore.ini[eZJSCore]Packer setting.

 

ezcss_require:

ezcss_require( array|string $css_files
              [, string $media='all'
               [, string $type='text/css'
                [, string $rel='stylesheet'
                 [, string $charset='utf-8'
                  [, int $pack_level=3]]]]] )

Like ezcss(), but stores stylesheet files to be loaded using the persistent_variable.css_files template variable* instead of generating a link tag unless ezcss_load() is already called. Optional parameters will not have any effect unless ezcss_load() is already called; then, the files are packed and the link tag is directly generated, typically when used in pagelayout and included templates.

* If the current view template does not support this (everything other than the content/view view, which loads node/view/*.tpl), then ezjscPackerTemplateFunctions::$persistentVariable is used instead.

 

ezcss_load:

ezcss_load( [ array|string $css_files
             [, string $media='all'
              [, string $type='text/css'
               [, string $rel='stylesheet'
                [, string $charset='utf-8'
                 [, int $pack_level=3]]]]]] )  

Works like ezcss(), except that the optional $css_files parameter is prepended to the list of stylesheet files already saved with ezcss_require() before they are packed and the link tag is generated.

 

ezcssfiles:

ezcssfiles( array|string $css_files
           [, int $pack_level=3
            [, bool $ignore_loaded=false]] ) 

PHP:

ezjscPacker::buildStylesheetFiles()

Works like ezcss(), except instead of generating link tag(s), it will return array of URLs and CSS rules. You can detect if each array element is a stylesheet URL or a CSS rule by checking if it ends with '.css'. Setting $ignore_loaded to true() will make it ignore files already required with ezcss_require().

 

json_encode:

json_encode( <mixed $data> )

PHP:

json_encode()

Encodes simple variables to a JSON string. Use node_encode() if you want to encode node(s) or content object(s).

 

xml_encode:

xml_encode( <mixed $data>) 

PHP:

ezjscAjaxContent::xmlEncode()

Encodes simple variables to an XML string. Use node_encode() if you want to encode node(s) or content object(s).

 

node_encode:

node_encode( <object|array $nodes>
            [, <hash $params>
             [, <string $type=json>]])

PHP:

ezjscAjaxContent::nodeEncode()

Encode node(s) or content object(s) to either JSON, XML, or to a simplified array structure (type=false()) .

$params (optional):

  • dataMap <array>: List of datamap attributes to load and encode.
  • fetchPath <bool>: Fetches the nodes in the path of the actual node
  • fetchChildrenCount <bool> : Returns .children_count for the node
  • dataMapType <array>: List of datamap types to load and encode.
  • ImagePreGenerateSizes <array>: Image sizes to pre-generate in case you
    specify an image attribute in dataMap or dataMapType.
    Default is array('small').

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)