Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
plugin_tutorial_javascript [2014/04/29 23:01]
Christoph M. Becker [jQuery] add link to next page
plugin_tutorial_javascript [2018/10/26 15:33] (current)
Line 26: Line 26:
 /* ]]> */</​script></​code>​ /* ]]> */</​script></​code>​
  
-To actually put the "​script"​ element in the generated output, you often can simply do it the same way as with (X)HTML, i.e. as part of the **return value** of a plugin function or directly by appending to the global **$o** (CMSimple_XH'​s output buffer for the content area). For performance reasons it's often reasonable to write "​script"​ elements at the end of the "​body"​ element. Since CMSimple_XH 1.5.4 there'​s the global variable **[[plugin_interfaces#​bjs|$bjs]]**,​ which you can extend with your "​script"​ element, to do so. Sometimes it's necessary to write your "​script"​ element to the "​head"​ element of the document; therefore you can use the global **$hjs**. Note that appending to $hjs doesn'​t have the desired effect, if done from the template, after the funtion head() was called.+To actually put the "​script"​ element in the generated output, you often can simply do it the same way as with (X)HTML, i.e. as part of the **return value** of a plugin function or directly by appending to the global **$o** (CMSimple_XH'​s output buffer for the content area) ((Note that the latter might have undesireable side-effects,​ see [[http://​cmsimpleforum.com/​viewtopic.php?​f=29&​t=7663#​p41465]])). For performance reasons it's often reasonable to write "​script"​ elements at the end of the "​body"​ element. Since CMSimple_XH 1.5.4 there'​s the global variable **[[plugin_interfaces#​bjs|$bjs]]**,​ which you can extend with your "​script"​ element, to do so. Sometimes it's necessary to write your "​script"​ element to the "​head"​ element of the document; therefore you can use the global **$hjs**. Note that appending to $hjs doesn'​t have the desired effect, if done from the template, after the funtion head() was called.
  
 ===== Triggering JavaScript Execution ===== ===== Triggering JavaScript Execution =====
Line 80: Line 80:
  
 <​code=php>​if (isset($_GET['​myplugin_xhr'​])) { // handle XHR of myplugin <​code=php>​if (isset($_GET['​myplugin_xhr'​])) { // handle XHR of myplugin
 +    while (ob_get_level()) { // purge existing output buffers
 +        ob_end_clean();​
 +    }
     header('​Content-Type:​ text/​plain'​);​ // set the appropriate Content-Type header     header('​Content-Type:​ text/​plain'​);​ // set the appropriate Content-Type header
     echo $plugin_tx['​myplugin'​]['​response'​]; ​ // sent the response     echo $plugin_tx['​myplugin'​]['​response'​]; ​ // sent the response
 
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3
Valid XHTML 1.0 Valid CSS Driven by DokuWiki