summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/lib/exe/js_js_compress.test.php5
-rw-r--r--lib/exe/js.php8
-rw-r--r--lib/scripts/events.js55
3 files changed, 59 insertions, 9 deletions
diff --git a/_test/cases/lib/exe/js_js_compress.test.php b/_test/cases/lib/exe/js_js_compress.test.php
index 48b36af15..f46cbe227 100644
--- a/_test/cases/lib/exe/js_js_compress.test.php
+++ b/_test/cases/lib/exe/js_js_compress.test.php
@@ -19,6 +19,11 @@ class js_js_compress_test extends UnitTestCase {
$this->assertEqual(js_compress($text), 'var foo=6;');
}
+ function test_mlcomcond(){
+ $text = '/*@if (@_win32)';
+ $this->assertEqual(js_compress($text), '/*@if(@_win32)');
+ }
+
function test_slcom1(){
$text = '// an comment';
$this->assertEqual(js_compress($text), '');
diff --git a/lib/exe/js.php b/lib/exe/js.php
index de996a117..75b9b1f1c 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -143,11 +143,11 @@ function js_out(){
js_runonstart('scrollToMarker()');
js_runonstart('focusMarker()');
- // initialize init pseudo event
+/* // initialize init pseudo event
echo 'if (document.addEventListener) {'.NL;
echo ' document.addEventListener("DOMContentLoaded", window.fireoninit, null);'.NL;
echo '}'.NL;
- echo 'addEvent(window,"load",window.fireoninit);'.NL;
+ echo 'addEvent(window,"load",window.fireoninit);'.NL;*/
// end output buffering and get contents
$js = ob_get_contents();
@@ -245,8 +245,8 @@ function js_compress($s){
while($i < $len){
$ch = $s{$i};
- // multiline comments
- if($ch == '/' && $s{$i+1} == '*'){
+ // multiline comments (keeping IE conditionals)
+ if($ch == '/' && $s{$i+1} == '*' && $s{$i+2} != '@'){
$endC = strpos($s,'*/',$i+2);
if($endC === false) trigger_error('Found invalid /*..*/ comment', E_USER_ERROR);
$i = $endC + 2;
diff --git a/lib/scripts/events.js b/lib/scripts/events.js
index 262e5ec2d..31a81f6da 100644
--- a/lib/scripts/events.js
+++ b/lib/scripts/events.js
@@ -67,26 +67,71 @@ fixEvent.stopPropagation = function() {
* on window load at last.
*
* @author based upon some code by Dean Edwards
- * @author Andreas Gohr
- * @see http://dean.edwards.name/weblog/2005/09/busted/
+ * @author Dean Edwards
+ * @link http://dean.edwards.name/weblog/2006/06/again/
*/
window.fireoninit = function() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
+ // kill the timer
+ if (_timer) {
+ clearInterval(_timer);
+ _timer = null;
+ }
- if (typeof window.oninit == 'function') {
+ if (typeof window.oninit == 'function') {
window.oninit();
}
};
/**
- * This is a pseudo Event that will be fired by the above function
+ * Run the fireoninit function as soon as possible after
+ * the DOM was loaded, using different methods for different
+ * Browsers
+ *
+ * @author Dean Edwards
+ * @link http://dean.edwards.name/weblog/2006/06/again/
+ */
+ // for Mozilla
+ if (document.addEventListener) {
+ document.addEventListener("DOMContentLoaded", window.fireoninit, null);
+ }
+
+ // for Internet Explorer (using conditional comments)
+ /*@cc_on @*/
+ /*@if (@_win32)
+ document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
+ var script = document.getElementById("__ie_onload");
+ script.onreadystatechange = function() {
+ if (this.readyState == "complete") {
+ window.fireoninit(); // call the onload handler
+ }
+ };
+ /*@end @*/
+
+ // for Safari
+ if (/WebKit/i.test(navigator.userAgent)) { // sniff
+ var _timer = setInterval(function() {
+ if (/loaded|complete/.test(document.readyState)) {
+ window.fireoninit(); // call the onload handler
+ }
+ }, 10);
+ }
+
+ // for other browsers
+ window.onload = window.fireoninit;
+
+
+/**
+ * This is a pseudo Event that will be fired by the fireoninit
+ * function above.
*
* Use addInitEvent to bind to this event!
*
- * @author Andreas Gohr
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @see fireoninit()
*/
window.oninit = function(){};