Exemplo n.º 1
0
    /**
     * Add jQuery highlight plugin.
     *
     * @param  string  $selector  The selector to make highlight.
     * @param  string  $text      The text to mark.
     * @param  array   $options   The options of this script.
     *
     * @see  http://bartaz.github.io/sandbox.js/jquery.highlight.html
     *
     * @return  void
     */
    public static function highlight($selector = '.hasHighlight', $text = null, $options = array())
    {
        $asset = static::getAsset();
        if (!static::inited(__METHOD__)) {
            JQueryScript::core();
            $asset->addJS('jquery/jquery.highlight.js');
        }
        if (!static::inited(__METHOD__, func_get_args()) && $selector && $text) {
            if (is_array($text)) {
                $text = implode(' ', $text);
            }
            $defaultOptions = array('element' => 'mark', 'className' => 'windwalker-highlight');
            $options = $asset::getJSObject(ArrayHelper::merge($defaultOptions, $options));
            $js = <<<JS
// Highlight Text
jQuery(document).ready(function(\$)
{
\t\$('{$selector}').highlight('{$text}', {$options});
});
JS;
            $asset->internalJS($js);
        }
    }
 /**
  * Method to test merge
  *
  * @covers \Windwalker\Helper\ArrayHelper::merge
  *
  * @return void
  */
 public function testMerge()
 {
     $data1 = array('green' => 'Hulk', 'red' => 'empty', 'human' => array('dark' => 'empty', 'black' => array('male' => 'empty', 'female' => 'empty', 'no-gender' => 'empty')));
     $data2 = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('female' => 'Black Widow', 'male' => 'Loki')));
     $expected = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'green' => 'Hulk', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('male' => 'Loki', 'female' => 'Black Widow', 'no-gender' => 'empty')));
     $expected2 = array('ai' => 'Jarvis', 'agent' => 'Phil Coulson', 'green' => 'Hulk', 'red' => array('left' => 'Pepper', 'right' => 'Iron Man'), 'human' => array('dark' => 'Nick Fury', 'black' => array('male' => 'Loki', 'female' => 'Black Widow')));
     $this->assertEquals($expected, ArrayHelper::merge($data1, $data2));
     $this->assertEquals($expected2, ArrayHelper::merge($data1, $data2, false));
 }