/** * Method to get the field input markup for password. * * @return string The field input markup. */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $auto = (string) $this->element['autocomplete'] == 'off' ? ' autocomplete="off"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $meter = (string) $this->element['strengthmeter'] == 'true'; $threshold = $this->element['threshold'] ? (int) $this->element['threshold'] : 66; $script = ''; if ($meter) { Asset::script('system/passwordstrength.js', true, true); $script = '<script type="text/javascript">new Form.PasswordStrength("' . $this->id . '", { threshold: ' . $threshold . ', onUpdate: function(element, strength, threshold) { element.set("data-passwordstrength", strength); } } );</script>'; } return '<input type="password" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $auto . $class . $readonly . $disabled . $size . $maxLength . ' autocomplete="off" />' . $script; }
/** * 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 */ 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(self::$loaded[__METHOD__][$sig])) { return; } Asset::script('assets/jquery.highlighter.js', true, true); $terms = str_replace('"', '\\"', $terms); $options = "{\n\t\t\t/*startElement: start,\n\t\t\tendElement: end,*/\n\t\t\tclassName: '" . $className . "',\n\t\t\twordsOnly: false,\n\t\t\telement: '" . $tag . "'\n\t\t}"; App::get('document')->addScriptDeclaration("\n\t\t\tjQuery(document).ready(function(\$){\n\t\t\t\t\$('body').highlight([\"" . implode('","', $terms) . "\"], " . $options . ");\n\t\t\t});\n\t\t"); self::$loaded[__METHOD__][$sig] = true; return; }