Пример #1
0
 public static function IncludeJPlayer()
 {
     ComponentHandler::LoadScriptLibrary('jquery');
     \Core\view()->addScript('js/jquery.jplayer.min.js');
     \Core\view()->addStylesheet('css/skin/jplayer.blue.monday.css');
     //Can has include?
     return true;
 }
Пример #2
0
    public static function IncludeTinyMCE()
    {
        \ComponentHandler::LoadScriptLibrary('jquery');
        /** @var \View $view */
        $view = \Core\view();
        /** @var \UserModel $user */
        $user = \Core\user();
        // I need to include both versions of TinyMCE so that
        // 1) the tinymce object is visible in the global scope at the time of execution and
        // 2) so I can target all inputs by their class name instead of the ID.
        $view->addScript('js/tinymce/tinymce.min.js');
        $view->addScript('js/tinymce/jquery.tinymce.min.js');
        $view->addStylesheet('css/tinymce/overrides.css');
        // Yes, the string needs quotes inside of quotes!  It's to be read by javascript after all.
        $browsable = \Core::IsComponentAvailable('media-manager') && $user->checkAccess('p:/mediamanager/browse');
        $filebrowsercallback = $browsable ? "Core.TinyMCE.FileBrowserCallback" : 'null';
        $loc = \Core\resolve_asset('js/tinymce/tinymce.min.js');
        $content = \Core\resolve_asset('css/tinymce/content.css');
        $pages = \PageModel::GetPagesAsOptions();
        $links = [];
        foreach ($pages as $url => $title) {
            // Trim off the "(...)" at the end of the title.
            // Core adds that as a benefit for knowing
            $links[] = ['title' => html_entity_decode(preg_replace('/(.*) \\([^\\)]*\\)/', '$1', $title)), 'value' => \Core\resolve_link($url)];
        }
        // And json the data.
        $links = json_encode($links);
        // Create the list of plugins
        // Start with standard and tack on any custom ones.
        $plugins = ['advlist', 'anchor', 'autolink', 'charmap', 'code', 'colorpicker', 'contextmenu', 'fullscreen', 'hr', 'image', 'imagetools', 'insertdatetime', 'link', 'lists', 'media', 'pagebreak', 'paste', 'preview', 'searchreplace', 'table', 'textcolor', 'visualblocks', 'visualchars', 'wordcount'];
        $customIncludes = '';
        foreach (self::$CustomPlugins as $name => $src) {
            // The "-" is required to inform TinyMCE not to load the plugin again.
            // It'll be loaded manually via the .load() method as it has a custom URL.
            $plugins[] = '-' . $name;
            // Resolve this src to an absolute URL
            $src = \Core\resolve_asset($src);
            $customIncludes .= 'tinymce.PluginManager.load("' . $name . '", "' . $src . '");';
        }
        // And make them something that javascript can understand.
        $plugins = json_encode($plugins);
        $script = <<<EOD
<script type="text/javascript">

\tCore.TinyMCEDefaults = {
\t\t// Location of TinyMCE script
\t\tscript_url : '{$loc}',

\t\t// General options

\t\tplugins: {$plugins},
\t    toolbar: "undo redo | styleselect | forecolor backcolor bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",

\t\ttheme : "modern",

\t\t// Required to not mungle links.
\t\tconvert_urls: false,

\t\t// Requires to support <script/> tags.
\t\textended_valid_elements : "script[language|type|src]",

\t\t// Core Media Manager integration
\t\tfile_browser_callback: {$filebrowsercallback},

\t\t// Example content CSS (should be your site CSS)
\t\tcontent_css : "{$content}",

\t\t// Drop lists for link/image/media/template dialogs
\t\t//template_external_list_url : "lists/template_list.js",
\t\t//external_link_list_url : "lists/link_list.js",
\t\t//external_image_list_url : "lists/image_list.js",
\t\t//media_external_list_url : "lists/media_list.js",
\t\t link_list: {$links},

\t\t// Replace values for the template plugin
\t\t//template_replace_values : {
\t\t//\tusername : "******",
\t\t//\tstaffid : "991234"
\t\t//}

\t\t__dummy: null
\t};

\t\$(function(){
\t\t{$customIncludes}
\t\t\$('textarea.tinymce').tinymce(Core.TinyMCEDefaults);
\t});
</script>\t
EOD;
        // Add the necessary script
        $view->addScript('assets/js/tinymce/coreplus_functions.js', 'head');
        $view->addScript($script, 'foot');
        // IMPORTANT!  Tells the script that the include succeeded!
        return true;
    }