Beispiel #1
0
/**
 * render <!-- JS: PluginName|my.js //Whatever text -->
 */
function renderHeadJS($js)
{
    if (is_array($js) && isset($js[1])) {
        $js = $js[1];
    }
    $js = trim($js);
    if (empty($js)) {
        return '';
    }
    $remote = substr($js, 0, 4) == 'http' ? true : false;
    if (!$remote && (strpos($js, ';') !== false || strpos($js, '//') !== false || strpos($js, '/*') !== false)) {
        $key = md5($js);
        // add the same section only once
        if (empty($GLOBALS['block']['custom_htmlhead'][$key])) {
            $GLOBALS['block']['custom_htmlhead'][$key] = '  <script' . SCRIPT_ATTRIBUTE_TYPE . '>' . LF . SCRIPT_CDATA_START . LF . '	';
            $GLOBALS['block']['custom_htmlhead'][$key] .= $js;
            $GLOBALS['block']['custom_htmlhead'][$key] .= LF . SCRIPT_CDATA_END . LF . '  </script>';
        }
    } elseif ($js == 'initJSLib') {
        initJSLib();
    } elseif ($remote || which_ext($js) == 'js') {
        // decide if plugin or script
        // replace {TEMPLATE}
        $js = str_replace('{TEMPLATE}', TEMPLATE_PATH, $js);
        $GLOBALS['block']['custom_htmlhead'][md5($js)] = getJavaScriptSourceLink(html_specialchars($js));
    } else {
        initJSLib();
        if (strtolower($js) != 'initlib') {
            initJSPlugin($js);
        }
    }
    return '';
}
/**
 * Initialize Frontend Edit DomReady JavaScript
 */
function init_frontend_edit_js()
{
    initJSPlugin('switchClass');
    // based on work and idea by markus@localhorst (http://forum.phpwcms.org/viewtopic.php?f=8&t=19551)
    $GLOBALS['block']['js_ondomready'][] = '		$("a.fe-link").toggle();$("#fe-link").click(function(){$(this).switchClass("enabled","disabled");$("a.fe-link").toggle();});';
}