当前位置: 首页>>代码示例>>PHP>>正文


PHP JFilterOutput::stringJSSafe方法代码示例

本文整理汇总了PHP中JFilterOutput::stringJSSafe方法的典型用法代码示例。如果您正苦于以下问题:PHP JFilterOutput::stringJSSafe方法的具体用法?PHP JFilterOutput::stringJSSafe怎么用?PHP JFilterOutput::stringJSSafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JFilterOutput的用法示例。


在下文中一共展示了JFilterOutput::stringJSSafe方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: highlighter

 /**
  * Highlight some words via Javascript.
  *
  * @param   array   $terms      Array of words that should be highlighted.
  * @param   string  $start      ID of the element that marks the begin of the section in which words
  *                              should be highlighted. Note this element will be removed from the DOM.
  * @param   string  $end        ID of the element that end this section.
  *                              Note this element will be removed from the DOM.
  * @param   string  $className  Class name of the element highlights are wrapped in.
  * @param   string  $tag        Tag that will be used to wrap the highlighted words.
  *
  * @return  void
  *
  * @since   2.5
  */
 public static function highlighter(array $terms, $start = 'highlighter-start', $end = 'highlighter-end', $className = 'highlight', $tag = 'span')
 {
     $sig = md5(serialize(array($terms, $start, $end)));
     if (isset(static::$loaded[__METHOD__][$sig])) {
         return;
     }
     // Include core
     static::core();
     // Include jQuery
     JHtml::_('jquery.framework');
     JHtml::_('script', 'system/highlighter.js', false, true);
     foreach ($terms as $i => $term) {
         $terms[$i] = JFilterOutput::stringJSSafe($term);
     }
     $document = JFactory::getDocument();
     $document->addScriptDeclaration("\n\t\t\tjQuery(function (\$) {\n\t\t\t\tvar start = document.getElementById('" . $start . "');\n\t\t\t\tvar end = document.getElementById('" . $end . "');\n\t\t\t\tif (!start || !end || !Joomla.Highlighter) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\thighlighter = new Joomla.Highlighter({\n\t\t\t\t\tstartElement: start,\n\t\t\t\t\tendElement: end,\n\t\t\t\t\tclassName: '" . $className . "',\n\t\t\t\t\tonlyWords: false,\n\t\t\t\t\ttag: '" . $tag . "'\n\t\t\t\t}).highlight([\"" . implode('","', $terms) . "\"]);\n\t\t\t\t\$(start).remove();\n\t\t\t\t\$(end).remove();\n\t\t\t});\n\t\t");
     static::$loaded[__METHOD__][$sig] = true;
     return;
 }
开发者ID:brenot,项目名称:forumdesenvolvimento,代码行数:34,代码来源:behavior.php


注:本文中的JFilterOutput::stringJSSafe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。