code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function checkbox($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, $options) + array('hiddenField' => true);
$value = current($this->value());
$output = "";
if (empty($options['value'])) {
$options['value'] = 1;
} elseif (
(!isset($options['checked']) && !empty($value) && $value === $options['value']) ||
!empty($options['checked'])
) {
$options['checked'] = 'checked';
}
if ($options['hiddenField']) {
$hiddenOptions = array(
'id' => $options['id'] . '_', 'name' => $options['name'],
'value' => '0', 'secure' => false
);
if (isset($options['disabled']) && $options['disabled'] == true) {
$hiddenOptions['disabled'] = 'disabled';
}
$output = $this->hidden($fieldName, $hiddenOptions);
}
unset($options['hiddenField']);
return $output . sprintf(
$this->Html->tags['checkbox'],
$options['name'],
$this->_parseAttributes($options, array('name'), null, ' ')
);
} | Creates a checkbox input widget.
### Options:
- `value` - the value of the checkbox
- `checked` - boolean indicate that this checkbox is checked.
- `hiddenField` - boolean to indicate if you want the results of checkbox() to include
a hidden input with a value of ''.
- `disabled` - create a disabled input.
@param string $fieldName Name of a field, like this "Modelname.fieldname"
@param array $options Array of HTML attributes.
@return string An HTML text input element.
@access public
@link http://book.cakephp.org/view/1414/checkbox | checkbox | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function radio($fieldName, $options = array(), $attributes = array()) {
$attributes = $this->_initInputField($fieldName, $attributes);
$legend = false;
if (isset($attributes['legend'])) {
$legend = $attributes['legend'];
unset($attributes['legend']);
} elseif (count($options) > 1) {
$legend = __(Inflector::humanize($this->field()), true);
}
$label = true;
if (isset($attributes['label'])) {
$label = $attributes['label'];
unset($attributes['label']);
}
$inbetween = null;
if (isset($attributes['separator'])) {
$inbetween = $attributes['separator'];
unset($attributes['separator']);
}
if (isset($attributes['value'])) {
$value = $attributes['value'];
} else {
$value = $this->value($fieldName);
}
$out = array();
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
unset($attributes['hiddenField']);
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);
if (isset($value) && $value !== '' && $optValue == $value) {
$optionsHere['checked'] = 'checked';
}
$parsedOptions = $this->_parseAttributes(
array_merge($attributes, $optionsHere),
array('name', 'type', 'id'), '', ' '
);
$tagName = Inflector::camelize(
$attributes['id'] . '_' . Inflector::slug($optValue)
);
if ($label) {
$optTitle = sprintf($this->Html->tags['label'], $tagName, null, $optTitle);
}
$out[] = sprintf(
$this->Html->tags['radio'], $attributes['name'],
$tagName, $parsedOptions, $optTitle
);
}
$hidden = null;
if ($hiddenField) {
if (!isset($value) || $value === '') {
$hidden = $this->hidden($fieldName, array(
'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name']
));
}
}
$out = $hidden . implode($inbetween, $out);
if ($legend) {
$out = sprintf(
$this->Html->tags['fieldset'], '',
sprintf($this->Html->tags['legend'], $legend) . $out
);
}
return $out;
} | Creates a set of radio widgets. Will create a legend and fieldset
by default. Use $options to control this
### Attributes:
- `separator` - define the string in between the radio buttons
- `legend` - control whether or not the widget set has a fieldset & legend
- `value` - indicate a value that is should be checked
- `label` - boolean to indicate whether or not labels for widgets show be displayed
- `hiddenField` - boolean to indicate if you want the results of radio() to include
a hidden input with a value of ''. This is useful for creating radio sets that non-continuous
@param string $fieldName Name of a field, like this "Modelname.fieldname"
@param array $options Radio button options array.
@param array $attributes Array of HTML attributes, and special attributes above.
@return string Completed radio widget set.
@access public
@link http://book.cakephp.org/view/1429/radio | radio | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function text($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, array_merge(
array('type' => 'text'), $options
));
return sprintf(
$this->Html->tags['input'],
$options['name'],
$this->_parseAttributes($options, array('name'), null, ' ')
);
} | Creates a text input widget.
@param string $fieldName Name of a field, in the form "Modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated HTML text input element
@access public
@link http://book.cakephp.org/view/1432/text | text | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function password($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, $options);
return sprintf(
$this->Html->tags['password'],
$options['name'],
$this->_parseAttributes($options, array('name'), null, ' ')
);
} | Creates a password input widget.
@param string $fieldName Name of a field, like in the form "Modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated password input.
@access public
@link http://book.cakephp.org/view/1428/password | password | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function textarea($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, $options);
$value = null;
if (array_key_exists('value', $options)) {
$value = $options['value'];
if (!array_key_exists('escape', $options) || $options['escape'] !== false) {
$value = h($value);
}
unset($options['value']);
}
return sprintf(
$this->Html->tags['textarea'],
$options['name'],
$this->_parseAttributes($options, array('type', 'name'), null, ' '),
$value
);
} | Creates a textarea widget.
### Options:
- `escape` - Whether or not the contents of the textarea should be escaped. Defaults to true.
@param string $fieldName Name of a field, in the form "Modelname.fieldname"
@param array $options Array of HTML attributes, and special options above.
@return string A generated HTML text input element
@access public
@link http://book.cakephp.org/view/1433/textarea | textarea | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function hidden($fieldName, $options = array()) {
$secure = true;
if (isset($options['secure'])) {
$secure = $options['secure'];
unset($options['secure']);
}
$options = $this->_initInputField($fieldName, array_merge(
$options, array('secure' => false)
));
$model = $this->model();
if ($fieldName !== '_method' && $model !== '_Token' && $secure) {
$this->__secure(null, '' . $options['value']);
}
return sprintf(
$this->Html->tags['hidden'],
$options['name'],
$this->_parseAttributes($options, array('name', 'class'), '', ' ')
);
} | Creates a hidden input field.
@param string $fieldName Name of a field, in the form of "Modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated hidden input
@access public
@link http://book.cakephp.org/view/1425/hidden | hidden | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function file($fieldName, $options = array()) {
$options = array_merge($options, array('secure' => false));
$options = $this->_initInputField($fieldName, $options);
$view =& ClassRegistry::getObject('view');
$field = $view->entity();
foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $suffix) {
$this->__secure(array_merge($field, array($suffix)));
}
$attributes = $this->_parseAttributes($options, array('name'), '', ' ');
return sprintf($this->Html->tags['file'], $options['name'], $attributes);
} | Creates file input widget.
@param string $fieldName Name of a field, in the form "Modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated file input.
@access public
@link http://book.cakephp.org/view/1424/file | file | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function select($fieldName, $options = array(), $selected = null, $attributes = array()) {
$select = array();
$style = null;
$tag = null;
$attributes += array(
'class' => null,
'escape' => true,
'secure' => null,
'empty' => '',
'showParents' => false,
'hiddenField' => true
);
$escapeOptions = $this->_extractOption('escape', $attributes);
$secure = $this->_extractOption('secure', $attributes);
$showEmpty = $this->_extractOption('empty', $attributes);
$showParents = $this->_extractOption('showParents', $attributes);
$hiddenField = $this->_extractOption('hiddenField', $attributes);
unset($attributes['escape'], $attributes['secure'], $attributes['empty'], $attributes['showParents'], $attributes['hiddenField']);
$attributes = $this->_initInputField($fieldName, array_merge(
(array)$attributes, array('secure' => false)
));
if (is_string($options) && isset($this->__options[$options])) {
$options = $this->__generateOptions($options);
} elseif (!is_array($options)) {
$options = array();
}
if (isset($attributes['type'])) {
unset($attributes['type']);
}
if (!isset($selected)) {
$selected = $attributes['value'];
}
if (!empty($attributes['multiple'])) {
$style = ($attributes['multiple'] === 'checkbox') ? 'checkbox' : null;
$template = ($style) ? 'checkboxmultiplestart' : 'selectmultiplestart';
$tag = $this->Html->tags[$template];
if ($hiddenField) {
$hiddenAttributes = array(
'value' => '',
'id' => $attributes['id'] . ($style ? '' : '_'),
'secure' => false,
'name' => $attributes['name']
);
$select[] = $this->hidden(null, $hiddenAttributes);
}
} else {
$tag = $this->Html->tags['selectstart'];
}
if (!empty($tag) || isset($template)) {
if (!isset($secure) || $secure == true) {
$this->__secure();
}
$select[] = sprintf($tag, $attributes['name'], $this->_parseAttributes(
$attributes, array('name', 'value'))
);
}
$emptyMulti = (
$showEmpty !== null && $showEmpty !== false && !(
empty($showEmpty) && (isset($attributes) &&
array_key_exists('multiple', $attributes))
)
);
if ($emptyMulti) {
$showEmpty = ($showEmpty === true) ? '' : $showEmpty;
$options = array_reverse($options, true);
$options[''] = $showEmpty;
$options = array_reverse($options, true);
}
$select = array_merge($select, $this->__selectOptions(
array_reverse($options, true),
$selected,
array(),
$showParents,
array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name'], 'class' => $attributes['class'])
));
$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend';
$select[] = $this->Html->tags[$template];
return implode("\n", $select);
} | Returns a formatted SELECT element.
### Attributes:
- `showParents` - If included in the array and set to true, an additional option element
will be added for the parent of each option group. You can set an option with the same name
and it's key will be used for the value of the option.
- `multiple` - show a multiple select box. If set to 'checkbox' multiple checkboxes will be
created instead.
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `escape` - If true contents of options will be HTML entity encoded. Defaults to true.
- `class` - When using multiple = checkbox the classname to apply to the divs. Defaults to 'checkbox'.
### Using options
A simple array will create normal options:
{{{
$options = array(1 => 'one', 2 => 'two);
$this->Form->select('Model.field', $options));
}}}
While a nested options array will create optgroups with options inside them.
{{{
$options = array(
1 => 'bill',
'fred' => array(
2 => 'fred',
3 => 'fred jr.'
)
);
$this->Form->select('Model.field', $options);
}}}
In the above `2 => 'fred'` will not generate an option element. You should enable the `showParents`
attribute to show the fred option.
@param string $fieldName Name attribute of the SELECT
@param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the
SELECT element
@param mixed $selected The option selected by default. If null, the default value
from POST data will be used when available.
@param array $attributes The HTML attributes of the select element.
@return string Formatted SELECT element
@access public
@link http://book.cakephp.org/view/1430/select | select | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function day($fieldName, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
$selected = $this->__dateTimeSelected('day', $fieldName, $selected, $attributes);
if (strlen($selected) > 2) {
$selected = date('d', strtotime($selected));
} elseif ($selected === false) {
$selected = null;
}
return $this->select($fieldName . ".day", $this->__generateOptions('day'), $selected, $attributes);
} | Returns a SELECT element for days.
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
@param string $fieldName Prefix name for the SELECT element
@param string $selected Option which is selected.
@param array $attributes HTML attributes for the select element
@return string A generated day select box.
@access public
@link http://book.cakephp.org/view/1419/day | day | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function year($fieldName, $minYear = null, $maxYear = null, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
if ((empty($selected) || $selected === true) && $value = $this->value($fieldName)) {
if (is_array($value)) {
extract($value);
$selected = $year;
} else {
if (empty($value)) {
if (!$attributes['empty'] && !$maxYear) {
$selected = 'now';
} elseif (!$attributes['empty'] && $maxYear && !$selected) {
$selected = $maxYear;
}
} else {
$selected = $value;
}
}
}
if (strlen($selected) > 4 || $selected === 'now') {
$selected = date('Y', strtotime($selected));
} elseif ($selected === false) {
$selected = null;
}
$yearOptions = array('min' => $minYear, 'max' => $maxYear, 'order' => 'desc');
if (isset($attributes['orderYear'])) {
$yearOptions['order'] = $attributes['orderYear'];
unset($attributes['orderYear']);
}
return $this->select(
$fieldName . '.year', $this->__generateOptions('year', $yearOptions),
$selected, $attributes
);
} | Returns a SELECT element for years
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `orderYear` - Ordering of year values in select options.
Possible values 'asc', 'desc'. Default 'desc'
@param string $fieldName Prefix name for the SELECT element
@param integer $minYear First year in sequence
@param integer $maxYear Last year in sequence
@param string $selected Option which is selected.
@param array $attributes Attribute array for the select elements.
@return string Completed year select input
@access public
@link http://book.cakephp.org/view/1416/year | year | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function month($fieldName, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
$selected = $this->__dateTimeSelected('month', $fieldName, $selected, $attributes);
if (strlen($selected) > 2) {
$selected = date('m', strtotime($selected));
} elseif ($selected === false) {
$selected = null;
}
$defaults = array('monthNames' => true);
$attributes = array_merge($defaults, (array) $attributes);
$monthNames = $attributes['monthNames'];
unset($attributes['monthNames']);
return $this->select(
$fieldName . ".month",
$this->__generateOptions('month', array('monthNames' => $monthNames)),
$selected, $attributes
);
} | Returns a SELECT element for months.
### Attributes:
- `monthNames` - If false, 2 digit numbers will be used instead of text.
If a array, the given array will be used.
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
@param string $fieldName Prefix name for the SELECT element
@param string $selected Option which is selected.
@param array $attributes Attributes for the select element
@return string A generated month select dropdown.
@access public
@link http://book.cakephp.org/view/1417/month | month | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function hour($fieldName, $format24Hours = false, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
$selected = $this->__dateTimeSelected('hour', $fieldName, $selected, $attributes);
if (strlen($selected) > 2) {
if ($format24Hours) {
$selected = date('H', strtotime($selected));
} else {
$selected = date('g', strtotime($selected));
}
} elseif ($selected === false) {
$selected = null;
}
return $this->select(
$fieldName . ".hour",
$this->__generateOptions($format24Hours ? 'hour24' : 'hour'),
$selected, $attributes
);
} | Returns a SELECT element for hours.
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
@param string $fieldName Prefix name for the SELECT element
@param boolean $format24Hours True for 24 hours format
@param string $selected Option which is selected.
@param array $attributes List of HTML attributes
@return string Completed hour select input
@access public
@link http://book.cakephp.org/view/1420/hour | hour | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function minute($fieldName, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
$selected = $this->__dateTimeSelected('min', $fieldName, $selected, $attributes);
if (strlen($selected) > 2) {
$selected = date('i', strtotime($selected));
} elseif ($selected === false) {
$selected = null;
}
$minuteOptions = array();
if (isset($attributes['interval'])) {
$minuteOptions['interval'] = $attributes['interval'];
unset($attributes['interval']);
}
return $this->select(
$fieldName . ".min", $this->__generateOptions('minute', $minuteOptions),
$selected, $attributes
);
} | Returns a SELECT element for minutes.
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
@param string $fieldName Prefix name for the SELECT element
@param string $selected Option which is selected.
@param string $attributes Array of Attributes
@return string Completed minute select input.
@access public
@link http://book.cakephp.org/view/1421/minute | minute | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function __dateTimeSelected($select, $fieldName, $selected, $attributes) {
if ((empty($selected) || $selected === true) && $value = $this->value($fieldName)) {
if (is_array($value) && isset($value[$select])) {
$selected = $value[$select];
} else {
if (empty($value)) {
if (!$attributes['empty']) {
$selected = 'now';
}
} else {
$selected = $value;
}
}
}
return $selected;
} | Selects values for dateTime selects.
@param string $select Name of element field. ex. 'day'
@param string $fieldName Name of fieldName being generated ex. Model.created
@param mixed $selected The current selected value.
@param array $attributes Array of attributes, must contain 'empty' key.
@return string Currently selected value.
@access private | __dateTimeSelected | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function meridian($fieldName, $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
if ((empty($selected) || $selected === true) && $value = $this->value($fieldName)) {
if (is_array($value)) {
extract($value);
$selected = $meridian;
} else {
if (empty($value)) {
if (!$attribues['empty']) {
$selected = date('a');
}
} else {
$selected = date('a', strtotime($value));
}
}
}
if ($selected === false) {
$selected = null;
}
return $this->select(
$fieldName . ".meridian", $this->__generateOptions('meridian'),
$selected, $attributes
);
} | Returns a SELECT element for AM or PM.
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
@param string $fieldName Prefix name for the SELECT element
@param string $selected Option which is selected.
@param string $attributes Array of Attributes
@param bool $showEmpty Show/Hide an empty option
@return string Completed meridian select input
@access public
@link http://book.cakephp.org/view/1422/meridian | meridian | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $attributes = array()) {
$attributes += array('empty' => true);
$year = $month = $day = $hour = $min = $meridian = null;
if (empty($selected)) {
$selected = $this->value($attributes, $fieldName);
if (isset($selected['value'])) {
$selected = $selected['value'];
} else {
$selected = null;
}
}
if ($selected === null && $attributes['empty'] != true) {
$selected = time();
}
if (!empty($selected)) {
if (is_array($selected)) {
extract($selected);
} else {
if (is_numeric($selected)) {
$selected = strftime('%Y-%m-%d %H:%M:%S', $selected);
}
$meridian = 'am';
$pos = strpos($selected, '-');
if ($pos !== false) {
$date = explode('-', $selected);
$days = explode(' ', $date[2]);
$day = $days[0];
$month = $date[1];
$year = $date[0];
} else {
$days[1] = $selected;
}
if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
if (($time[0] > 12) && $timeFormat == '12') {
$time[0] = $time[0] - 12;
$meridian = 'pm';
} elseif ($time[0] == '12' && $timeFormat == '12') {
$meridian = 'pm';
} elseif ($time[0] == '00' && $timeFormat == '12') {
$time[0] = 12;
} elseif ($time[0] > 12) {
$meridian = 'pm';
}
if ($time[0] == 0 && $timeFormat == '12') {
$time[0] = 12;
}
$hour = $min = null;
if (isset($time[1])) {
$hour = $time[0];
$min = $time[1];
}
}
}
}
$elements = array('Day', 'Month', 'Year', 'Hour', 'Minute', 'Meridian');
$defaults = array(
'minYear' => null, 'maxYear' => null, 'separator' => '-',
'interval' => 1, 'monthNames' => true
);
$attributes = array_merge($defaults, (array) $attributes);
if (isset($attributes['minuteInterval'])) {
$attributes['interval'] = $attributes['minuteInterval'];
unset($attributes['minuteInterval']);
}
$minYear = $attributes['minYear'];
$maxYear = $attributes['maxYear'];
$separator = $attributes['separator'];
$interval = $attributes['interval'];
$monthNames = $attributes['monthNames'];
$attributes = array_diff_key($attributes, $defaults);
if (isset($attributes['id'])) {
if (is_string($attributes['id'])) {
// build out an array version
foreach ($elements as $element) {
$selectAttrName = 'select' . $element . 'Attr';
${$selectAttrName} = $attributes;
${$selectAttrName}['id'] = $attributes['id'] . $element;
}
} elseif (is_array($attributes['id'])) {
// check for missing ones and build selectAttr for each element
$attributes['id'] += array(
'month' => '', 'year' => '', 'day' => '',
'hour' => '', 'minute' => '', 'meridian' => ''
);
foreach ($elements as $element) {
$selectAttrName = 'select' . $element . 'Attr';
${$selectAttrName} = $attributes;
${$selectAttrName}['id'] = $attributes['id'][strtolower($element)];
}
}
} else {
// build the selectAttrName with empty id's to pass
foreach ($elements as $element) {
$selectAttrName = 'select' . $element . 'Attr';
${$selectAttrName} = $attributes;
}
}
$selects = array();
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
switch ($char) {
case 'Y':
$selects[] = $this->year(
$fieldName, $minYear, $maxYear, $year, $selectYearAttr
);
break;
case 'M':
$selectMonthAttr['monthNames'] = $monthNames;
$selects[] = $this->month($fieldName, $month, $selectMonthAttr);
break;
case 'D':
$selects[] = $this->day($fieldName, $day, $selectDayAttr);
break;
}
}
$opt = implode($separator, $selects);
if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) {
case '24':
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr);
break;
case '12':
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr);
break;
default:
$opt .= '';
break;
}
return $opt;
} | Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
### Attributes:
- `monthNames` If false, 2 digit numbers will be used instead of text.
If a array, the given array will be used.
- `minYear` The lowest year to use in the year select
- `maxYear` The maximum year to use in the year select
- `interval` The interval for the minutes select. Defaults to 1
- `separator` The contents of the string between select elements. Defaults to '-'
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `value` | `default` The default value to be used by the input. A value in `$this->data`
matching the field name will override this value. If no default is provided `time()` will be used.
@param string $fieldName Prefix name for the SELECT element
@param string $dateFormat DMY, MDY, YMD.
@param string $timeFormat 12, 24.
@param string $selected Option which is selected.
@param string $attributes array of Attributes
@return string Generated set of select boxes for the date and time formats chosen.
@access public
@link http://book.cakephp.org/view/1418/dateTime | dateTime | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function _name($options = array(), $field = null, $key = 'name') {
if ($this->requestType == 'get') {
if ($options === null) {
$options = array();
} elseif (is_string($options)) {
$field = $options;
$options = 0;
}
if (!empty($field)) {
$this->setEntity($field);
}
if (is_array($options) && isset($options[$key])) {
return $options;
}
$view = ClassRegistry::getObject('view');
$name = !empty($view->field) ? $view->field : $view->model;
if (!empty($view->fieldSuffix)) {
$name .= '[' . $view->fieldSuffix . ']';
}
if (is_array($options)) {
$options[$key] = $name;
return $options;
} else {
return $name;
}
}
return parent::_name($options, $field, $key);
} | Gets the input field name for the current tag
@param array $options
@param string $key
@return array
@access protected | _name | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) {
$select = array();
$attributes = array_merge(array('escape' => true, 'style' => null, 'class' => null), $attributes);
$selectedIsEmpty = ($selected === '' || $selected === null);
$selectedIsArray = is_array($selected);
foreach ($elements as $name => $title) {
$htmlOptions = array();
if (is_array($title) && (!isset($title['name']) || !isset($title['value']))) {
if (!empty($name)) {
if ($attributes['style'] === 'checkbox') {
$select[] = $this->Html->tags['fieldsetend'];
} else {
$select[] = $this->Html->tags['optiongroupend'];
}
$parents[] = $name;
}
$select = array_merge($select, $this->__selectOptions(
$title, $selected, $parents, $showParents, $attributes
));
if (!empty($name)) {
$name = $attributes['escape'] ? h($name) : $name;
if ($attributes['style'] === 'checkbox') {
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
} else {
$select[] = sprintf($this->Html->tags['optiongroup'], $name, '');
}
}
$name = null;
} elseif (is_array($title)) {
$htmlOptions = $title;
$name = $title['value'];
$title = $title['name'];
unset($htmlOptions['name'], $htmlOptions['value']);
}
if ($name !== null) {
if (
(!$selectedIsArray && !$selectedIsEmpty && (string)$selected == (string)$name) ||
($selectedIsArray && in_array($name, $selected))
) {
if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true;
} else {
$htmlOptions['selected'] = 'selected';
}
}
if ($showParents || (!in_array($title, $parents))) {
$title = ($attributes['escape']) ? h($title) : $title;
if ($attributes['style'] === 'checkbox') {
$htmlOptions['value'] = $name;
$tagName = Inflector::camelize(
$this->model() . '_' . $this->field().'_'.Inflector::slug($name)
);
$htmlOptions['id'] = $tagName;
$label = array('for' => $tagName);
if (isset($htmlOptions['checked']) && $htmlOptions['checked'] === true) {
$label['class'] = 'selected';
}
$name = $attributes['name'];
if (empty($attributes['class'])) {
$attributes['class'] = 'checkbox';
} elseif ($attributes['class'] === 'form-error') {
$attributes['class'] = 'checkbox ' . $attributes['class'];
}
$label = $this->label(null, $title, $label);
$item = sprintf(
$this->Html->tags['checkboxmultiple'], $name,
$this->_parseAttributes($htmlOptions)
);
$select[] = $this->Html->div($attributes['class'], $item . $label);
} else {
$select[] = sprintf(
$this->Html->tags['selectoption'],
$name, $this->_parseAttributes($htmlOptions), $title
);
}
}
}
}
return array_reverse($select, true);
} | Returns an array of formatted OPTION/OPTGROUP elements
@access private
@return array | __selectOptions | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function __generateOptions($name, $options = array()) {
if (!empty($this->options[$name])) {
return $this->options[$name];
}
$data = array();
switch ($name) {
case 'minute':
if (isset($options['interval'])) {
$interval = $options['interval'];
} else {
$interval = 1;
}
$i = 0;
while ($i < 60) {
$data[sprintf('%02d', $i)] = sprintf('%02d', $i);
$i += $interval;
}
break;
case 'hour':
for ($i = 1; $i <= 12; $i++) {
$data[sprintf('%02d', $i)] = $i;
}
break;
case 'hour24':
for ($i = 0; $i <= 23; $i++) {
$data[sprintf('%02d', $i)] = $i;
}
break;
case 'meridian':
$data = array('am' => 'am', 'pm' => 'pm');
break;
case 'day':
$min = 1;
$max = 31;
if (isset($options['min'])) {
$min = $options['min'];
}
if (isset($options['max'])) {
$max = $options['max'];
}
for ($i = $min; $i <= $max; $i++) {
$data[sprintf('%02d', $i)] = $i;
}
break;
case 'month':
if ($options['monthNames'] === true) {
$data['01'] = __('January', true);
$data['02'] = __('February', true);
$data['03'] = __('March', true);
$data['04'] = __('April', true);
$data['05'] = __('May', true);
$data['06'] = __('June', true);
$data['07'] = __('July', true);
$data['08'] = __('August', true);
$data['09'] = __('September', true);
$data['10'] = __('October', true);
$data['11'] = __('November', true);
$data['12'] = __('December', true);
} else if (is_array($options['monthNames'])) {
$data = $options['monthNames'];
} else {
for ($m = 1; $m <= 12; $m++) {
$data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1, 1999));
}
}
break;
case 'year':
$current = intval(date('Y'));
if (!isset($options['min'])) {
$min = $current - 20;
} else {
$min = $options['min'];
}
if (!isset($options['max'])) {
$max = $current + 20;
} else {
$max = $options['max'];
}
if ($min > $max) {
list($min, $max) = array($max, $min);
}
for ($i = $min; $i <= $max; $i++) {
$data[$i] = $i;
}
if ($options['order'] != 'asc') {
$data = array_reverse($data, true);
}
break;
}
$this->__options[$name] = $data;
return $this->__options[$name];
} | Generates option lists for common <select /> menus
@access private | __generateOptions | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function _initInputField($field, $options = array()) {
if (isset($options['secure'])) {
$secure = $options['secure'];
unset($options['secure']);
} else {
$secure = (isset($this->params['_Token']) && !empty($this->params['_Token']));
}
$fieldName = null;
if ($secure && !empty($options['name'])) {
preg_match_all('/\[(.*?)\]/', $options['name'], $matches);
if (isset($matches[1])) {
$fieldName = $matches[1];
}
}
$result = parent::_initInputField($field, $options);
if ($secure) {
$this->__secure($fieldName);
}
return $result;
} | Sets field defaults and adds field to form security input hash
Options
- `secure` - boolean whether or not the field should be added to the security fields.
@param string $field Name of the field to initialize options for.
@param array $options Array of options to append options into.
@return array Array of options for the input.
@access protected | _initInputField | php | Datawalke/Coordino | cake/libs/view/helpers/form.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/form.php | MIT |
function addCrumb($name, $link = null, $options = null) {
$this->_crumbs[] = array($name, $link, $options);
} | Adds a link to the breadcrumbs array.
@param string $name Text for link
@param string $link URL for link (if empty it won't be a link)
@param mixed $options Link attributes e.g. array('id'=>'selected')
@return void
@see HtmlHelper::link() for details on $options that can be used.
@access public | addCrumb | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function docType($type = 'xhtml-strict') {
if (isset($this->__docTypes[$type])) {
return $this->__docTypes[$type];
}
return null;
} | Returns a doctype string.
Possible doctypes:
- html4-strict: HTML4 Strict.
- html4-trans: HTML4 Transitional.
- html4-frame: HTML4 Frameset.
- xhtml-strict: XHTML1 Strict.
- xhtml-trans: XHTML1 Transitional.
- xhtml-frame: XHTML1 Frameset.
- xhtml11: XHTML1.1.
@param string $type Doctype to use.
@return string Doctype string
@access public
@link http://book.cakephp.org/view/1439/docType | docType | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function meta($type, $url = null, $options = array()) {
$inline = isset($options['inline']) ? $options['inline'] : true;
unset($options['inline']);
if (!is_array($type)) {
$types = array(
'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url),
'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $url),
'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $url),
'keywords' => array('name' => 'keywords', 'content' => $url),
'description' => array('name' => 'description', 'content' => $url),
);
if ($type === 'icon' && $url === null) {
$types['icon']['link'] = $this->webroot('favicon.ico');
}
if (isset($types[$type])) {
$type = $types[$type];
} elseif (!isset($options['type']) && $url !== null) {
if (is_array($url) && isset($url['ext'])) {
$type = $types[$url['ext']];
} else {
$type = $types['rss'];
}
} elseif (isset($options['type']) && isset($types[$options['type']])) {
$type = $types[$options['type']];
unset($options['type']);
} else {
$type = array();
}
} elseif ($url !== null) {
$inline = $url;
}
$options = array_merge($type, $options);
$out = null;
if (isset($options['link'])) {
if (isset($options['rel']) && $options['rel'] === 'icon') {
$out = sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
$options['rel'] = 'shortcut icon';
} else {
$options['link'] = $this->url($options['link'], true);
}
$out .= sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
} else {
$out = sprintf($this->tags['meta'], $this->_parseAttributes($options, array('type'), ' ', ' '));
}
if ($inline) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
}
} | Creates a link to an external resource and handles basic meta tags
### Options
- `inline` Whether or not the link element should be output inline, or in scripts_for_layout.
@param string $type The title of the external resource
@param mixed $url The address of the external resource or string for content attribute
@param array $options Other attributes for the generated tag. If the type attribute is html,
rss, atom, or icon, the mime-type is returned.
@return string A completed `<link />` element.
@access public
@link http://book.cakephp.org/view/1438/meta | meta | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function charset($charset = null) {
if (empty($charset)) {
$charset = strtolower(Configure::read('App.encoding'));
}
return sprintf($this->tags['charset'], (!empty($charset) ? $charset : 'utf-8'));
} | Returns a charset META-tag.
@param string $charset The character set to be used in the meta tag. If empty,
The App.encoding value will be used. Example: "utf-8".
@return string A meta tag containing the specified character set.
@access public
@link http://book.cakephp.org/view/1436/charset | charset | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function link($title, $url = null, $options = array(), $confirmMessage = false) {
$escapeTitle = true;
if ($url !== null) {
$url = $this->url($url);
} else {
$url = $this->url($title);
$title = $url;
$escapeTitle = false;
}
if (isset($options['escape'])) {
$escapeTitle = $options['escape'];
}
if ($escapeTitle === true) {
$title = h($title);
} elseif (is_string($escapeTitle)) {
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
}
if (!empty($options['confirm'])) {
$confirmMessage = $options['confirm'];
unset($options['confirm']);
}
if ($confirmMessage) {
$confirmMessage = str_replace("'", "\'", $confirmMessage);
$confirmMessage = str_replace('"', '\"', $confirmMessage);
$options['onclick'] = "return confirm('{$confirmMessage}');";
} elseif (isset($options['default']) && $options['default'] == false) {
if (isset($options['onclick'])) {
$options['onclick'] .= ' event.returnValue = false; return false;';
} else {
$options['onclick'] = 'event.returnValue = false; return false;';
}
unset($options['default']);
}
return sprintf($this->tags['link'], $url, $this->_parseAttributes($options), $title);
} | Creates an HTML link.
If $url starts with "http://" this is treated as an external link. Else,
it is treated as a path to controller/action and parsed with the
HtmlHelper::url() method.
If the $url is empty, $title is used instead.
### Options
- `escape` Set to false to disable escaping of title and attributes.
@param string $title The content to be wrapped by <a> tags.
@param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
@param array $options Array of HTML attributes.
@param string $confirmMessage JavaScript confirmation message.
@return string An `<a />` element.
@access public
@link http://book.cakephp.org/view/1442/link | link | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function css($path, $rel = null, $options = array()) {
$options += array('inline' => true);
if (is_array($path)) {
$out = '';
foreach ($path as $i) {
$out .= "\n\t" . $this->css($i, $rel, $options);
}
if ($options['inline']) {
return $out . "\n";
}
return;
}
if (strpos($path, '//') !== false) {
$url = $path;
} else {
if ($path[0] !== '/') {
$path = CSS_URL . $path;
}
if (strpos($path, '?') === false) {
if (substr($path, -4) !== '.css') {
$path .= '.css';
}
}
$url = $this->assetTimestamp($this->webroot($path));
if (Configure::read('Asset.filter.css')) {
$pos = strpos($url, CSS_URL);
if ($pos !== false) {
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
}
}
}
if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->_parseAttributes($options, array('inline'), '', ' '), '@import url(' . $url . ');');
} else {
if ($rel == null) {
$rel = 'stylesheet';
}
$out = sprintf($this->tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline'), '', ' '));
}
if ($options['inline']) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
}
} | Creates a link element for CSS stylesheets.
### Options
- `inline` If set to false, the generated tag appears in the head tag of the layout. Defaults to true
@param mixed $path The name of a CSS style sheet or an array containing names of
CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
@param string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
@param array $options Array of HTML attributes.
@return string CSS <link /> or <style /> tag, depending on the type of link.
@access public
@link http://book.cakephp.org/view/1437/css | css | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function script($url, $options = array()) {
if (is_bool($options)) {
list($inline, $options) = array($options, array());
$options['inline'] = $inline;
}
$options = array_merge(array('inline' => true, 'once' => true), $options);
if (is_array($url)) {
$out = '';
foreach ($url as $i) {
$out .= "\n\t" . $this->script($i, $options);
}
if ($options['inline']) {
return $out . "\n";
}
return null;
}
if ($options['once'] && isset($this->__includedScripts[$url])) {
return null;
}
$this->__includedScripts[$url] = true;
if (strpos($url, '//') === false) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
if (strpos($url, '?') === false && substr($url, -3) !== '.js') {
$url .= '.js';
}
$url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) {
$url = str_replace(JS_URL, 'cjs/', $url);
}
}
$attributes = $this->_parseAttributes($options, array('inline', 'once'), ' ');
$out = sprintf($this->tags['javascriptlink'], $url, $attributes);
if ($options['inline']) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
}
} | Returns one or many `<script>` tags depending on the number of scripts given.
If the filename is prefixed with "/", the path will be relative to the base path of your
application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
Can include one or many Javascript files.
### Options
- `inline` - Whether script should be output inline or into scripts_for_layout.
- `once` - Whether or not the script should be checked for uniqueness. If true scripts will only be
included once, use false to allow the same script to be included more than once per request.
@param mixed $url String or array of javascript files to include
@param mixed $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
@return mixed String of `<script />` tags or null if $inline is false or if $once is true and the file has been
included before.
@access public
@link http://book.cakephp.org/view/1589/script | script | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function scriptBlock($script, $options = array()) {
$options += array('safe' => true, 'inline' => true);
if ($options['safe']) {
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
}
$inline = $options['inline'];
unset($options['inline'], $options['safe']);
$attributes = $this->_parseAttributes($options, ' ', ' ');
if ($inline) {
return sprintf($this->tags['javascriptblock'], $attributes, $script);
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript(sprintf($this->tags['javascriptblock'], $attributes, $script));
return null;
}
} | Wrap $script in a script tag.
### Options
- `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
- `inline` (boolean) Whether or not the $script should be added to $scripts_for_layout or output inline
@param string $script The script to wrap
@param array $options The options to use.
@return mixed string or null depending on the value of `$options['inline']`
@access public
@link http://book.cakephp.org/view/1604/scriptBlock | scriptBlock | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function scriptStart($options = array()) {
$options += array('safe' => true, 'inline' => true);
$this->_scriptBlockOptions = $options;
ob_start();
return null;
} | Begin a script block that captures output until HtmlHelper::scriptEnd()
is called. This capturing block will capture all output between the methods
and create a scriptBlock from it.
### Options
- `safe` Whether the code block should contain a CDATA
- `inline` Should the generated script tag be output inline or in `$scripts_for_layout`
@param array $options Options for the code block.
@return void
@access public
@link http://book.cakephp.org/view/1605/scriptStart | scriptStart | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function scriptEnd() {
$buffer = ob_get_clean();
$options = $this->_scriptBlockOptions;
$this->_scriptBlockOptions = array();
return $this->scriptBlock($buffer, $options);
} | End a Buffered section of Javascript capturing.
Generates a script tag inline or in `$scripts_for_layout` depending on the settings
used when the scriptBlock was started
@return mixed depending on the settings of scriptStart() either a script tag or null
@access public
@link http://book.cakephp.org/view/1606/scriptEnd | scriptEnd | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function style($data, $oneline = true) {
if (!is_array($data)) {
return $data;
}
$out = array();
foreach ($data as $key=> $value) {
$out[] = $key.':'.$value.';';
}
if ($oneline) {
return join(' ', $out);
}
return implode("\n", $out);
} | Builds CSS style data from an array of CSS properties
### Usage:
{{{
echo $html->style(array('margin' => '10px', 'padding' => '10px'), true);
// creates
'margin:10px;padding:10px;'
}}}
@param array $data Style data array, keys will be used as property names, values as property values.
@param boolean $oneline Whether or not the style block should be displayed on one line.
@return string CSS styling data
@access public
@link http://book.cakephp.org/view/1440/style | style | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function getCrumbs($separator = '»', $startText = false) {
if (!empty($this->_crumbs)) {
$out = array();
if ($startText) {
$out[] = $this->link($startText, '/');
}
foreach ($this->_crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
} else {
$out[] = $crumb[0];
}
}
return join($separator, $out);
} else {
return null;
}
} | Returns the breadcrumb trail as a sequence of »-separated links.
@param string $separator Text to separate crumbs.
@param string $startText This will be the first crumb, if false it defaults to first crumb in array
@return string Composed bread crumbs
@access public | getCrumbs | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function image($path, $options = array()) {
if (is_array($path)) {
$path = $this->url($path);
} elseif (strpos($path, '://') === false) {
if ($path[0] !== '/') {
$path = IMAGES_URL . $path;
}
$path = $this->assetTimestamp($this->webroot($path));
}
if (!isset($options['alt'])) {
$options['alt'] = '';
}
$url = false;
if (!empty($options['url'])) {
$url = $options['url'];
unset($options['url']);
}
$image = sprintf($this->tags['image'], $path, $this->_parseAttributes($options, null, '', ' '));
if ($url) {
return sprintf($this->tags['link'], $this->url($url), null, $image);
}
return $image;
} | Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
generated with the link pointed at `$options['url']`. This method will set an empty
alt attribute if one is not supplied.
### Usage
Create a regular image:
`echo $html->image('cake_icon.png', array('alt' => 'CakePHP'));`
Create an image link:
`echo $html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
@param string $path Path to the image file, relative to the app/webroot/img/ directory.
@param array $options Array of HTML attributes.
@return string completed img tag
@access public
@link http://book.cakephp.org/view/1441/image | image | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function tableHeaders($names, $trOptions = null, $thOptions = null) {
$out = array();
foreach ($names as $arg) {
$out[] = sprintf($this->tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
}
return sprintf($this->tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
} | Returns a row of formatted and named TABLE headers.
@param array $names Array of tablenames.
@param array $trOptions HTML options for TR elements.
@param array $thOptions HTML options for TH elements.
@return string Completed table headers
@access public
@link http://book.cakephp.org/view/1446/tableHeaders | tableHeaders | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
if (empty($data[0]) || !is_array($data[0])) {
$data = array($data);
}
if ($oddTrOptions === true) {
$useCount = true;
$oddTrOptions = null;
}
if ($evenTrOptions === false) {
$continueOddEven = false;
$evenTrOptions = null;
}
if ($continueOddEven) {
static $count = 0;
} else {
$count = 0;
}
foreach ($data as $line) {
$count++;
$cellsOut = array();
$i = 0;
foreach ($line as $cell) {
$cellOptions = array();
if (is_array($cell)) {
$cellOptions = $cell[1];
$cell = $cell[0];
} elseif ($useCount) {
$cellOptions['class'] = 'column-' . ++$i;
}
$cellsOut[] = sprintf($this->tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
}
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
$out[] = sprintf($this->tags['tablerow'], $options, implode(' ', $cellsOut));
}
return implode("\n", $out);
} | Returns a formatted string of table rows (TR's with TD's in them).
@param array $data Array of table data
@param array $oddTrOptions HTML options for odd TR elements if true useCount is used
@param array $evenTrOptions HTML options for even TR elements
@param bool $useCount adds class "column-$i"
@param bool $continueOddEven If false, will use a non-static $count variable,
so that the odd/even count is reset to zero just for that call.
@return string Formatted HTML
@access public
@link http://book.cakephp.org/view/1447/tableCells | tableCells | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function tag($name, $text = null, $options = array()) {
if (is_array($options) && isset($options['escape']) && $options['escape']) {
$text = h($text);
unset($options['escape']);
}
if (!is_array($options)) {
$options = array('class' => $options);
}
if ($text === null) {
$tag = 'tagstart';
} else {
$tag = 'tag';
}
return sprintf($this->tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
} | Returns a formatted block tag, i.e DIV, SPAN, P.
### Options
- `escape` Whether or not the contents should be html_entity escaped.
@param string $name Tag name.
@param string $text String content that will appear inside the div element.
If null, only a start tag will be printed
@param array $options Additional HTML attributes of the DIV tag, see above.
@return string The formatted tag element
@access public
@link http://book.cakephp.org/view/1443/tag | tag | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function div($class = null, $text = null, $options = array()) {
if (!empty($class)) {
$options['class'] = $class;
}
return $this->tag('div', $text, $options);
} | Returns a formatted DIV tag for HTML FORMs.
### Options
- `escape` Whether or not the contents should be html_entity escaped.
@param string $class CSS class name of the div element.
@param string $text String content that will appear inside the div element.
If null, only a start tag will be printed
@param array $options Additional HTML attributes of the DIV tag
@return string The formatted DIV element
@access public
@link http://book.cakephp.org/view/1444/div | div | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function para($class, $text, $options = array()) {
if (isset($options['escape'])) {
$text = h($text);
}
if ($class != null && !empty($class)) {
$options['class'] = $class;
}
if ($text === null) {
$tag = 'parastart';
} else {
$tag = 'para';
}
return sprintf($this->tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
} | Returns a formatted P tag.
### Options
- `escape` Whether or not the contents should be html_entity escaped.
@param string $class CSS class name of the p element.
@param string $text String content that will appear inside the p element.
@param array $options Additional HTML attributes of the P tag
@return string The formatted P element
@access public
@link http://book.cakephp.org/view/1445/para | para | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function nestedList($list, $options = array(), $itemOptions = array(), $tag = 'ul') {
if (is_string($options)) {
$tag = $options;
$options = array();
}
$items = $this->__nestedListItem($list, $options, $itemOptions, $tag);
return sprintf($this->tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $items);
} | Build a nested list (UL/OL) out of an associative array.
@param array $list Set of elements to list
@param array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
@param array $itemOptions Additional HTML attributes of the list item (LI) tag
@param string $tag Type of list tag to use (ol/ul)
@return string The nested list
@access public | nestedList | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function __nestedListItem($items, $options, $itemOptions, $tag) {
$out = '';
$index = 1;
foreach ($items as $key => $item) {
if (is_array($item)) {
$item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
}
if (isset($itemOptions['even']) && $index % 2 == 0) {
$itemOptions['class'] = $itemOptions['even'];
} else if (isset($itemOptions['odd']) && $index % 2 != 0) {
$itemOptions['class'] = $itemOptions['odd'];
}
$out .= sprintf($this->tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);
$index++;
}
return $out;
} | Internal function to build a nested list (UL/OL) out of an associative array.
@param array $items Set of elements to list
@param array $options Additional HTML attributes of the list (ol/ul) tag
@param array $itemOptions Additional HTML attributes of the list item (LI) tag
@param string $tag Type of list tag to use (ol/ul)
@return string The nested list element
@access private
@see HtmlHelper::nestedList() | __nestedListItem | php | Datawalke/Coordino | cake/libs/view/helpers/html.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/html.php | MIT |
function __construct($options = array()) {
if (!empty($options)) {
foreach ($options as $key => $val) {
if (is_numeric($key)) {
$key = $val;
$val = true;
}
switch ($key) {
case 'cache':
break;
case 'safe':
$this->safe = $val;
break;
}
}
}
$this->useNative = function_exists('json_encode');
return parent::__construct($options);
} | Constructor. Checks for presence of native PHP JSON extension to use for object encoding
@access public | __construct | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function codeBlock($script = null, $options = array()) {
if (!empty($options) && !is_array($options)) {
$options = array('allowCache' => $options);
} elseif (empty($options)) {
$options = array();
}
$defaultOptions = array('allowCache' => true, 'safe' => true, 'inline' => true);
$options = array_merge($defaultOptions, $options);
if (empty($script)) {
$this->__scriptBuffer = @ob_get_contents();
$this->_blockOptions = $options;
$this->inBlock = true;
@ob_end_clean();
ob_start();
return null;
}
if ($this->_cacheEvents && $this->_cacheAll && $options['allowCache']) {
$this->_cachedEvents[] = $script;
return null;
}
if ($options['safe'] || $this->safe) {
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
}
if ($options['inline']) {
return sprintf($this->tags['javascriptblock'], $script);
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript(sprintf($this->tags['javascriptblock'], $script));
}
} | Returns a JavaScript script tag.
Options:
- allowCache: boolean, designates whether this block is cacheable using the
current cache settings.
- safe: boolean, whether this block should be wrapped in CDATA tags. Defaults
to helper's object configuration.
- inline: whether the block should be printed inline, or written
to cached for later output (i.e. $scripts_for_layout).
@param string $script The JavaScript to be wrapped in SCRIPT tags.
@param array $options Set of options:
@return string The full SCRIPT element, with the JavaScript inside it, or null,
if 'inline' is set to false. | codeBlock | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function blockEnd() {
if (!isset($this->inBlock) || !$this->inBlock) {
return;
}
$script = @ob_get_contents();
@ob_end_clean();
ob_start();
echo $this->__scriptBuffer;
$this->__scriptBuffer = null;
$options = $this->_blockOptions;
$this->_blockOptions = array();
$this->inBlock = false;
if (empty($script)) {
return null;
}
return $this->codeBlock($script, $options);
} | Ends a block of cached JavaScript code
@return mixed | blockEnd | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function link($url, $inline = true) {
if (is_array($url)) {
$out = '';
foreach ($url as $i) {
$out .= "\n\t" . $this->link($i, $inline);
}
if ($inline) {
return $out . "\n";
}
return;
}
if (strpos($url, '://') === false) {
if ($url[0] !== '/') {
$url = JS_URL . $url;
}
if (strpos($url, '?') === false) {
if (substr($url, -3) !== '.js') {
$url .= '.js';
}
}
$url = $this->assetTimestamp($this->webroot($url));
if (Configure::read('Asset.filter.js')) {
$pos = strpos($url, JS_URL);
if ($pos !== false) {
$url = substr($url, 0, $pos) . 'cjs/' . substr($url, $pos + strlen(JS_URL));
}
}
}
$out = sprintf($this->tags['javascriptlink'], $url);
if ($inline) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
}
} | Returns a JavaScript include tag (SCRIPT element). If the filename is prefixed with "/",
the path will be relative to the base path of your application. Otherwise, the path will
be relative to your JavaScript path, usually webroot/js.
@param mixed $url String URL to JavaScript file, or an array of URLs.
@param boolean $inline If true, the <script /> tag will be printed inline,
otherwise it will be printed in the <head />, using $scripts_for_layout
@see JS_URL
@return string | link | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function escapeScript($script) {
$script = str_replace(array("\r\n", "\n", "\r"), '\n', $script);
$script = str_replace(array('"', "'"), array('\"', "\\'"), $script);
return $script;
} | Escape carriage returns and single and double quotes for JavaScript segments.
@param string $script string that might have javascript elements
@return string escaped string | escapeScript | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function escapeString($string) {
App::import('Core', 'Multibyte');
$escape = array("\r\n" => "\n", "\r" => "\n");
$string = str_replace(array_keys($escape), array_values($escape), $string);
return $this->_utf8ToHex($string);
} | Escape a string to be JavaScript friendly.
List of escaped ellements:
+ "\r\n" => '\n'
+ "\r" => '\n'
+ "\n" => '\n'
+ '"' => '\"'
+ "'" => "\\'"
@param string $script String that needs to get escaped.
@return string Escaped string. | escapeString | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function event($object, $event, $observer = null, $options = array()) {
if (!empty($options) && !is_array($options)) {
$options = array('useCapture' => $options);
} else if (empty($options)) {
$options = array();
}
$defaultOptions = array('useCapture' => false);
$options = array_merge($defaultOptions, $options);
if ($options['useCapture'] == true) {
$options['useCapture'] = 'true';
} else {
$options['useCapture'] = 'false';
}
$isObject = (
strpos($object, 'window') !== false || strpos($object, 'document') !== false ||
strpos($object, '$(') !== false || strpos($object, '"') !== false ||
strpos($object, '\'') !== false
);
if ($isObject) {
$b = "Event.observe({$object}, '{$event}', function(event) { {$observer} }, ";
$b .= "{$options['useCapture']});";
} elseif ($object[0] == '\'') {
$b = "Event.observe(" . substr($object, 1) . ", '{$event}', function(event) { ";
$b .= "{$observer} }, {$options['useCapture']});";
} else {
$chars = array('#', ' ', ', ', '.', ':');
$found = false;
foreach ($chars as $char) {
if (strpos($object, $char) !== false) {
$found = true;
break;
}
}
if ($found) {
$this->_rules[$object] = $event;
} else {
$b = "Event.observe(\$('{$object}'), '{$event}', function(event) { ";
$b .= "{$observer} }, {$options['useCapture']});";
}
}
if (isset($b) && !empty($b)) {
if ($this->_cacheEvents === true) {
$this->_cachedEvents[] = $b;
return;
} else {
return $this->codeBlock($b, array_diff_key($options, $defaultOptions));
}
}
} | Attach an event to an element. Used with the Prototype library.
@param string $object Object to be observed
@param string $event event to observe
@param string $observer function to call
@param array $options Set options: useCapture, allowCache, safe
@return boolean true on success | event | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function cacheEvents($file = false, $all = false) {
$this->_cacheEvents = true;
$this->_cacheToFile = $file;
$this->_cacheAll = $all;
} | Cache JavaScript events created with event()
@param boolean $file If true, code will be written to a file
@param boolean $all If true, all code written with JavascriptHelper will be sent to a file
@return null | cacheEvents | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function getCache($clear = true) {
$out = '';
$rules = array();
if (!empty($this->_rules)) {
foreach ($this->_rules as $sel => $event) {
$rules[] = "\t'{$sel}': function(element, event) {\n\t\t{$event}\n\t}";
}
}
$data = implode("\n", $this->_cachedEvents);
if (!empty($rules)) {
$data .= "\nvar Rules = {\n" . implode(",\n\n", $rules) . "\n}";
$data .= "\nEventSelectors.start(Rules);\n";
}
if ($clear) {
$this->_rules = array();
$this->_cacheEvents = false;
$this->_cachedEvents = array();
}
return $data;
} | Gets (and clears) the current JavaScript event cache
@param boolean $clear
@return string | getCache | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function writeEvents($inline = true, $options = array()) {
$out = '';
$rules = array();
if (!$this->_cacheEvents) {
return;
}
$data = $this->getCache();
if (empty($data)) {
return;
}
if ($this->_cacheToFile) {
$filename = md5($data);
if (!file_exists(JS . $filename . '.js')) {
cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $data, '+999 days', 'public');
}
$out = $this->link($filename);
} else {
$out = $this->codeBlock("\n" . $data . "\n", $options);
}
if ($inline) {
return $out;
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript($out);
}
} | Write cached JavaScript events
@param boolean $inline If true, returns JavaScript event code. Otherwise it is added to the
output of $scripts_for_layout in the layout.
@param array $options Set options for codeBlock
@return string | writeEvents | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function includeScript($script = "", $options = array()) {
if ($script == "") {
$files = scandir(JS);
$javascript = '';
foreach ($files as $file) {
if (substr($file, -3) == '.js') {
$javascript .= file_get_contents(JS . "{$file}") . "\n\n";
}
}
} else {
$javascript = file_get_contents(JS . "$script.js") . "\n\n";
}
return $this->codeBlock("\n\n" . $javascript, $options);
} | Includes the Prototype Javascript library (and anything else) inside a single script tag.
Note: The recommended approach is to copy the contents of
javascripts into your application's
public/javascripts/ directory, and use @see javascriptIncludeTag() to
create remote script links.
@param string $script Script file to include
@param array $options Set options for codeBlock
@return string script with all javascript in/javascripts folder | includeScript | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function object($data = array(), $options = array()) {
if (!empty($options) && !is_array($options)) {
$options = array('block' => $options);
} else if (empty($options)) {
$options = array();
}
$defaultOptions = array(
'block' => false, 'prefix' => '', 'postfix' => '',
'stringKeys' => array(), 'quoteKeys' => true, 'q' => '"'
);
$options = array_merge($defaultOptions, $options, array_filter(compact(array_keys($defaultOptions))));
if (is_object($data)) {
$data = get_object_vars($data);
}
$out = $keys = array();
$numeric = true;
if ($this->useNative) {
$rt = json_encode($data);
} else {
if (is_null($data)) {
return 'null';
}
if (is_bool($data)) {
return $data ? 'true' : 'false';
}
if (is_array($data)) {
$keys = array_keys($data);
}
if (!empty($keys)) {
$numeric = (array_values($keys) === array_keys(array_values($keys)));
}
foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) {
$val = $this->object(
$val,
array_merge($options, array('block' => false, 'prefix' => '', 'postfix' => ''))
);
} else {
$quoteStrings = (
!count($options['stringKeys']) ||
($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) ||
(!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true))
);
$val = $this->value($val, $quoteStrings);
}
if (!$numeric) {
$val = $options['q'] . $this->value($key, false) . $options['q'] . ':' . $val;
}
$out[] = $val;
}
if (!$numeric) {
$rt = '{' . implode(',', $out) . '}';
} else {
$rt = '[' . implode(',', $out) . ']';
}
}
$rt = $options['prefix'] . $rt . $options['postfix'];
if ($options['block']) {
$rt = $this->codeBlock($rt, array_diff_key($options, $defaultOptions));
}
return $rt;
} | Generates a JavaScript object in JavaScript Object Notation (JSON)
from an array
### Options
- block - Wraps the return value in a script tag if true. Default is false
- prefix - Prepends the string to the returned data. Default is ''
- postfix - Appends the string to the returned data. Default is ''
- stringKeys - A list of array keys to be treated as a string.
- quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true.
- q - The type of quote to use. Default is '"'. This option only affects the keys, not the values.
@param array $data Data to be converted
@param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q
@return string A JSON code block | object | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function value($val, $quoteStrings = true) {
switch (true) {
case (is_array($val) || is_object($val)):
$val = $this->object($val);
break;
case ($val === null):
$val = 'null';
break;
case (is_bool($val)):
$val = !empty($val) ? 'true' : 'false';
break;
case (is_int($val)):
$val = $val;
break;
case (is_float($val)):
$val = sprintf("%.11f", $val);
break;
default:
$val = $this->escapeString($val);
if ($quoteStrings) {
$val = '"' . $val . '"';
}
break;
}
return $val;
} | Converts a PHP-native variable of any type to a JSON-equivalent representation
@param mixed $val A PHP variable to be converted to JSON
@param boolean $quoteStrings If false, leaves string values unquoted
@return string a JavaScript-safe/JSON representation of $val | value | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function afterRender() {
if (!$this->enabled) {
return;
}
echo $this->writeEvents(true);
} | AfterRender callback. Writes any cached events to the view, or to a temp file.
@return null | afterRender | php | Datawalke/Coordino | cake/libs/view/helpers/javascript.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/javascript.php | MIT |
function _methodTemplate($method, $template, $options, $extraSafeKeys = array()) {
$options = $this->_mapOptions($method, $options);
$options = $this->_prepareCallbacks($method, $options);
$callbacks = array_keys($this->_callbackArguments[$method]);
if (!empty($extraSafeKeys)) {
$callbacks = array_merge($callbacks, $extraSafeKeys);
}
$options = $this->_parseOptions($options, $callbacks);
return sprintf($template, $this->selection, $options);
} | Helper function to wrap repetitive simple method templating.
@param string $method The method name being generated.
@param string $template The method template
@param string $selection the selection to apply
@param string $options Array of options for method
@param string $callbacks Array of callback / special options.
@return string Composed method string
@access public | _methodTemplate | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function get($selector) {
if ($selector == 'window' || $selector == 'document') {
$this->selection = $this->jQueryObject . '(' . $selector .')';
} else {
$this->selection = $this->jQueryObject . '("' . $selector . '")';
}
return $this;
} | Create javascript selector for a CSS rule
@param string $selector The selector that is targeted
@return object instance of $this. Allows chained methods.
@access public | get | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options);
$function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) {
$callback .= "\nreturn false;";
}
if ($options['wrap']) {
$callback = sprintf($function, $callback);
}
return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback);
} | Add an event to the script cache. Operates on the currently selected elements.
### Options
- 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true)
- 'stop' - Whether you want the event to stopped. (defaults true)
@param string $type Type of event to bind to the current dom id
@param string $callback The Javascript function you wish to trigger or the function literal
@param array $options Options for the event.
@return string completed event handler
@access public | event | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function domReady($functionBody) {
return $this->jQueryObject . '(document).ready(function () {' . $functionBody . '});';
} | Create a domReady event. For jQuery. This method does not
bind a 'traditional event' as `$(document).bind('ready', fn)`
Works in an entirely different fashion than `$(document).ready()`
The first will not run the function when eval()'d as part of a response
The second will. Because of the way that ajax pagination is done
`$().ready()` is used.
@param string $functionBody The code to run on domReady
@return string completed domReady method
@access public | domReady | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function each($callback) {
return $this->selection . '.each(function () {' . $callback . '});';
} | Create an iteration over the current selection result.
@param string $method The method you want to apply to the selection
@param string $callback The function body you wish to apply during the iteration.
@return string completed iteration
@access public | each | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function effect($name, $options = array()) {
$speed = null;
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
$speed = $this->value($options['speed']);
}
$effect = '';
switch ($name) {
case 'slideIn':
case 'slideOut':
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
case 'hide':
case 'show':
case 'fadeIn':
case 'fadeOut':
case 'slideDown':
case 'slideUp':
$effect = ".$name($speed);";
break;
}
return $this->selection . $effect;
} | Trigger an Effect.
@param string $name The name of the effect to trigger.
@param array $options Array of options for the effect.
@return string completed string with effect.
@access public
@see JsBaseEngineHelper::effect() | effect | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function request($url, $options = array()) {
$url = $this->url($url);
$options = $this->_mapOptions('request', $options);
if (isset($options['data']) && is_array($options['data'])) {
$options['data'] = $this->_toQuerystring($options['data']);
}
$options['url'] = $url;
if (isset($options['update'])) {
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
$success = '';
if(isset($options['success']) AND !empty($options['success'])) {
$success .= $options['success'];
}
$success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);';
if (!$wrapCallbacks) {
$success = 'function (data, textStatus) {' . $success . '}';
}
$options['dataType'] = 'html';
$options['success'] = $success;
unset($options['update']);
}
$callbacks = array('success', 'error', 'beforeSend', 'complete');
if (!empty($options['dataExpression'])) {
$callbacks[] = 'data';
unset($options['dataExpression']);
}
$options = $this->_prepareCallbacks('request', $options);
$options = $this->_parseOptions($options, $callbacks);
return $this->jQueryObject . '.ajax({' . $options .'});';
} | Create an $.ajax() call.
If the 'update' key is set, success callback will be overridden.
@param mixed $url
@param array $options See JsHelper::request() for options.
@return string The completed ajax call.
@access public
@see JsBaseEngineHelper::request() for options list. | request | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function sortable($options = array()) {
$template = '%s.sortable({%s});';
return $this->_methodTemplate('sortable', $template, $options);
} | Create a sortable element.
Requires both Ui.Core and Ui.Sortables to be loaded.
@param array $options Array of options for the sortable.
@return string Completed sortable script.
@access public
@see JsBaseEngineHelper::sortable() for options list. | sortable | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function drag($options = array()) {
$template = '%s.draggable({%s});';
return $this->_methodTemplate('drag', $template, $options);
} | Create a Draggable element
Requires both Ui.Core and Ui.Draggable to be loaded.
@param array $options Array of options for the draggable element.
@return string Completed Draggable script.
@access public
@see JsBaseEngineHelper::drag() for options list. | drag | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function drop($options = array()) {
$template = '%s.droppable({%s});';
return $this->_methodTemplate('drop', $template, $options);
} | Create a Droppable element
Requires both Ui.Core and Ui.Droppable to be loaded.
@param array $options Array of options for the droppable element.
@return string Completed Droppable script.
@access public
@see JsBaseEngineHelper::drop() for options list. | drop | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function slider($options = array()) {
$callbacks = array('start', 'change', 'slide', 'stop');
$template = '%s.slider({%s});';
return $this->_methodTemplate('slider', $template, $options, $callbacks);
} | Create a Slider element
Requires both Ui.Core and Ui.Slider to be loaded.
@param array $options Array of options for the droppable element.
@return string Completed Slider script.
@access public
@see JsBaseEngineHelper::slider() for options list. | slider | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
$selector = $this->selection;
if (!$options['isForm']) {
$selector = $this->selection . '.closest("form")';
}
$method = '.serialize()';
if (!$options['inline']) {
$method .= ';';
}
return $selector . $method;
} | Serialize a form attached to $selector. If the current selection is not an input or
form, errors will be created in the Javascript.
@param array $options Options for the serialization
@return string completed form serialization script.
@access public
@see JsBaseEngineHelper::serializeForm() for option list. | serializeForm | php | Datawalke/Coordino | cake/libs/view/helpers/jquery_engine.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/jquery_engine.php | MIT |
function __construct($settings = array()) {
$className = 'Jquery';
if (is_array($settings) && isset($settings[0])) {
$className = $settings[0];
} elseif (is_string($settings)) {
$className = $settings;
}
$engineName = $className;
list($plugin, $className) = pluginSplit($className);
$this->__engineName = $className . 'Engine';
$engineClass = $engineName . 'Engine';
$this->helpers[] = $engineClass;
parent::__construct();
} | Constructor - determines engine helper
@param array $settings Settings array contains name of engine helper.
@return void
@access public | __construct | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function call__($method, $params) {
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
$buffer = false;
if (in_array(strtolower($method), $this->{$this->__engineName}->bufferedMethods)) {
$buffer = true;
}
if (count($params) > 0) {
$lastParam = $params[count($params) - 1];
$hasBufferParam = (is_bool($lastParam) || is_array($lastParam) && isset($lastParam['buffer']));
if ($hasBufferParam && is_bool($lastParam)) {
$buffer = $lastParam;
unset($params[count($params) - 1]);
} elseif ($hasBufferParam && is_array($lastParam)) {
$buffer = $lastParam['buffer'];
unset($params['buffer']);
}
}
$out = $this->{$this->__engineName}->dispatchMethod($method, $params);
if ($this->bufferScripts && $buffer && is_string($out)) {
$this->buffer($out);
return null;
}
if (is_object($out) && is_a($out, 'JsBaseEngineHelper')) {
return $this;
}
return $out;
}
if (method_exists($this, $method . '_')) {
return $this->dispatchMethod($method . '_', $params);
}
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
} | call__ Allows for dispatching of methods to the Engine Helper.
methods in the Engines bufferedMethods list will be automatically buffered.
You can control buffering with the buffer param as well. By setting the last parameter to
any engine method to a boolean you can force or disable buffering.
e.g. `$js->get('#foo')->effect('fadeIn', array('speed' => 'slow'), true);`
Will force buffering for the effect method. If the method takes an options array you may also add
a 'buffer' param to the options array and control buffering there as well.
e.g. `$js->get('#foo')->event('click', $functionContents, array('buffer' => true));`
The buffer parameter will not be passed onto the EngineHelper.
@param string $method Method to be called
@param array $params Parameters for the method being called.
@return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper
@access public | call__ | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function object($data = array(), $options = array()) {
return $this->{$this->__engineName}->object($data, $options);
} | Workaround for Object::Object() existing. Since Object::object exists, it does not
fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for
more information on this method.
@param mixed $data Data to convert into JSON
@param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details.
@return string encoded JSON
@deprecated Remove when support for PHP4 and Object::object are removed.
@access public | object | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function value($val, $quoteString = true) {
return $this->{$this->__engineName}->value($val, $quoteString);
} | Overwrite inherited Helper::value()
See JsBaseEngineHelper::value() for more information on this method.
@param mixed $val A PHP variable to be converted to JSON
@param boolean $quoteStrings If false, leaves string values unquoted
@return string a JavaScript-safe/JSON representation of $val
@access public | value | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function writeBuffer($options = array()) {
$domReady = isset($this->params['isAjax']) ? !$this->params['isAjax'] : true;
$defaults = array(
'onDomReady' => $domReady, 'inline' => true,
'cache' => false, 'clear' => true, 'safe' => true
);
$options = array_merge($defaults, $options);
$script = implode("\n", $this->getBuffer($options['clear']));
if (empty($script)) {
return null;
}
if ($options['onDomReady']) {
$script = $this->{$this->__engineName}->domReady($script);
}
$opts = $options;
unset($opts['onDomReady'], $opts['cache'], $opts['clear']);
if (!$options['cache'] && $options['inline']) {
return $this->Html->scriptBlock($script, $opts);
}
if ($options['cache'] && $options['inline']) {
$filename = md5($script);
if (!file_exists(JS . $filename . '.js')) {
cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $script, '+999 days', 'public');
}
return $this->Html->script($filename);
}
$this->Html->scriptBlock($script, $opts);
return null;
} | Writes all Javascript generated so far to a code block or
caches them to a file and returns a linked script. If no scripts have been
buffered this method will return null. If the request is an XHR(ajax) request
onDomReady will be set to false. As the dom is already 'ready'.
### Options
- `inline` - Set to true to have scripts output as a script block inline
if `cache` is also true, a script link tag will be generated. (default true)
- `cache` - Set to true to have scripts cached to a file and linked in (default false)
- `clear` - Set to false to prevent script cache from being cleared (default true)
- `onDomReady` - wrap cached scripts in domready event (default true)
- `safe` - if an inline block is generated should it be wrapped in <![CDATA[ ... ]]> (default true)
@param array $options options for the code block
@return mixed Completed javascript tag if there are scripts, if there are no buffered
scripts null will be returned.
@access public | writeBuffer | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function buffer($script, $top = false) {
if ($top) {
array_unshift($this->__bufferedScripts, $script);
} else {
$this->__bufferedScripts[] = $script;
}
} | Write a script to the buffered scripts.
@param string $script Script string to add to the buffer.
@param boolean $top If true the script will be added to the top of the
buffered scripts array. If false the bottom.
@return void
@access public | buffer | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function getBuffer($clear = true) {
$this->_createVars();
$scripts = $this->__bufferedScripts;
if ($clear) {
$this->__bufferedScripts = array();
$this->__jsVars = array();
}
return $scripts;
} | Get all the buffered scripts
@param boolean $clear Whether or not to clear the script caches (default true)
@return array Array of scripts added to the request.
@access public | getBuffer | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _createVars() {
if (!empty($this->__jsVars)) {
$setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'window.' . $this->setVariable;
$this->buffer($setVar . ' = ' . $this->object($this->__jsVars) . ';', true);
}
} | Generates the object string for variables passed to javascript.
@return string Generated JSON object of all set vars
@access protected | _createVars | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function link($title, $url = null, $options = array()) {
if (!isset($options['id'])) {
$options['id'] = 'link-' . intval(mt_rand());
}
list($options, $htmlOptions) = $this->_getHtmlOptions($options);
$out = $this->Html->link($title, $url, $htmlOptions);
$this->get('#' . $htmlOptions['id']);
$requestString = $event = '';
if (isset($options['confirm'])) {
$requestString = $this->confirmReturn($options['confirm']);
unset($options['confirm']);
}
$buffer = isset($options['buffer']) ? $options['buffer'] : null;
$safe = isset($options['safe']) ? $options['safe'] : true;
unset($options['buffer'], $options['safe']);
$requestString .= $this->request($url, $options);
if (!empty($requestString)) {
$event = $this->event('click', $requestString, $options + array('buffer' => $buffer));
}
if (isset($buffer) && !$buffer) {
$opts = array('safe' => $safe);
$out .= $this->Html->scriptBlock($event, $opts);
}
return $out;
} | Generate an 'Ajax' link. Uses the selected JS engine to create a link
element that is enhanced with Javascript. Options can include
both those for HtmlHelper::link() and JsBaseEngine::request(), JsBaseEngine::event();
### Options
- `confirm` - Generate a confirm() dialog before sending the event.
- `id` - use a custom id.
- `htmlAttributes` - additional non-standard htmlAttributes. Standard attributes are class, id,
rel, title, escape, onblur and onfocus.
- `buffer` - Disable the buffering and return a script tag in addition to the link.
@param string $title Title for the link.
@param mixed $url Mixed either a string URL or an cake url array.
@param array $options Options for both the HTML element and Js::request()
@return string Completed link. If buffering is disabled a script tag will be returned as well.
@access public | link | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function set($one, $two = null) {
$data = null;
if (is_array($one)) {
if (is_array($two)) {
$data = array_combine($one, $two);
} else {
$data = $one;
}
} else {
$data = array($one => $two);
}
if ($data == null) {
return false;
}
$this->__jsVars = array_merge($this->__jsVars, $data);
} | Pass variables into Javascript. Allows you to set variables that will be
output when the buffer is fetched with `JsHelper::getBuffer()` or `JsHelper::writeBuffer()`
The Javascript variable used to output set variables can be controlled with `JsHelper::$setVariable`
@param mixed $one Either an array of variables to set, or the name of the variable to set.
@param mixed $two If $one is a string, $two is the value for that key.
@return void
@access public | set | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _getHtmlOptions($options, $additional = array()) {
$htmlKeys = array_merge(
array('class', 'id', 'escape', 'onblur', 'onfocus', 'rel', 'title', 'style'),
$additional
);
$htmlOptions = array();
foreach ($htmlKeys as $key) {
if (isset($options[$key])) {
$htmlOptions[$key] = $options[$key];
}
unset($options[$key]);
}
if (isset($options['htmlAttributes'])) {
$htmlOptions = array_merge($htmlOptions, $options['htmlAttributes']);
unset($options['htmlAttributes']);
}
return array($options, $htmlOptions);
} | Parse a set of Options and extract the Html options.
Extracted Html Options are removed from the $options param.
@param array $options Options to filter.
@param array $additional Array of additional keys to extract and include in the return options array.
@return array Array of js options and Htmloptions
@access protected | _getHtmlOptions | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function alert($message) {
return 'alert("' . $this->escape($message) . '");';
} | Create an `alert()` message in Javascript
@param string $message Message you want to alter.
@return string completed alert()
@access public | alert | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function redirect($url = null) {
return 'window.location = "' . Router::url($url) . '";';
} | Redirects to a URL. Creates a window.location modification snippet
that can be used to trigger 'redirects' from Javascript.
@param mixed $url
@param array $options
@return string completed redirect in javascript
@access public | redirect | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function confirm($message) {
return 'confirm("' . $this->escape($message) . '");';
} | Create a `confirm()` message
@param string $message Message you want confirmed.
@return string completed confirm()
@access public | confirm | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function confirmReturn($message) {
$out = 'var _confirm = ' . $this->confirm($message);
$out .= "if (!_confirm) {\n\treturn false;\n}";
return $out;
} | Generate a confirm snippet that returns false from the current
function scope.
@param string $message Message to use in the confirm dialog.
@return string completed confirm with return script
@access public | confirmReturn | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function prompt($message, $default = '') {
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
} | Create a `prompt()` Javascript function
@param string $message Message you want to prompt.
@param string $default Default message
@return string completed prompt()
@access public | prompt | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function object($data = array(), $options = array()) {
$defaultOptions = array(
'prefix' => '', 'postfix' => '',
);
$options = array_merge($defaultOptions, $options);
if (is_object($data)) {
$data = get_object_vars($data);
}
$out = $keys = array();
$numeric = true;
if ($this->useNative && function_exists('json_encode')) {
$rt = json_encode($data);
} else {
if (is_null($data)) {
return 'null';
}
if (is_bool($data)) {
return $data ? 'true' : 'false';
}
if (is_array($data)) {
$keys = array_keys($data);
}
if (!empty($keys)) {
$numeric = (array_values($keys) === array_keys(array_values($keys)));
}
foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) {
$val = $this->object($val);
} else {
$val = $this->value($val);
}
if (!$numeric) {
$val = '"' . $this->value($key, false) . '":' . $val;
}
$out[] = $val;
}
if (!$numeric) {
$rt = '{' . join(',', $out) . '}';
} else {
$rt = '[' . join(',', $out) . ']';
}
}
$rt = $options['prefix'] . $rt . $options['postfix'];
return $rt;
} | Generates a JavaScript object in JavaScript Object Notation (JSON)
from an array. Will use native JSON encode method if available, and $useNative == true
### Options:
- `prefix` - String prepended to the returned data.
- `postfix` - String appended to the returned data.
@param array $data Data to be converted.
@param array $options Set of options, see above.
@return string A JSON code block
@access public | object | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function value($val, $quoteString = true) {
switch (true) {
case (is_array($val) || is_object($val)):
$val = $this->object($val);
break;
case ($val === null):
$val = 'null';
break;
case (is_bool($val)):
$val = ($val === true) ? 'true' : 'false';
break;
case (is_int($val)):
$val = $val;
break;
case (is_float($val)):
$val = sprintf("%.11f", $val);
break;
default:
$val = $this->escape($val);
if ($quoteString) {
$val = '"' . $val . '"';
}
break;
}
return $val;
} | Converts a PHP-native variable of any type to a JSON-equivalent representation
@param mixed $val A PHP variable to be converted to JSON
@param boolean $quoteStrings If false, leaves string values unquoted
@return string a JavaScript-safe/JSON representation of $val
@access public | value | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function escape($string) {
App::import('Core', 'Multibyte');
return $this->_utf8ToHex($string);
} | Escape a string to be JSON friendly.
List of escaped elements:
- "\r" => '\n'
- "\n" => '\n'
- '"' => '\"'
@param string $script String that needs to get escaped.
@return string Escaped string.
@access public | escape | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function get($selector) {
trigger_error(sprintf(__('%s does not have get() implemented', true), get_class($this)), E_USER_WARNING);
return $this;
} | Create javascript selector for a CSS rule
@param string $selector The selector that is targeted
@return object instance of $this. Allows chained methods.
@access public | get | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function event($type, $callback, $options = array()) {
trigger_error(sprintf(__('%s does not have event() implemented', true), get_class($this)), E_USER_WARNING);
} | Add an event to the script cache. Operates on the currently selected elements.
### Options
- `wrap` - Whether you want the callback wrapped in an anonymous function. (defaults to true)
- `stop` - Whether you want the event to stopped. (defaults to true)
@param string $type Type of event to bind to the current dom id
@param string $callback The Javascript function you wish to trigger or the function literal
@param array $options Options for the event.
@return string completed event handler
@access public | event | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function domReady($functionBody) {
trigger_error(sprintf(__('%s does not have domReady() implemented', true), get_class($this)), E_USER_WARNING);
} | Create a domReady event. This is a special event in many libraries
@param string $functionBody The code to run on domReady
@return string completed domReady method
@access public | domReady | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function each($callback) {
trigger_error(sprintf(__('%s does not have each() implemented', true), get_class($this)), E_USER_WARNING);
} | Create an iteration over the current selection result.
@param string $callback The function body you wish to apply during the iteration.
@return string completed iteration | each | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function effect($name, $options) {
trigger_error(sprintf(__('%s does not have effect() implemented', true), get_class($this)), E_USER_WARNING);
} | Trigger an Effect.
### Supported Effects
The following effects are supported by all core JsEngines
- `show` - reveal an element.
- `hide` - hide an element.
- `fadeIn` - Fade in an element.
- `fadeOut` - Fade out an element.
- `slideIn` - Slide an element in.
- `slideOut` - Slide an element out.
### Options
- `speed` - Speed at which the animation should occur. Accepted values are 'slow', 'fast'. Not all effects use
the speed option.
@param string $name The name of the effect to trigger.
@param array $options Array of options for the effect.
@return string completed string with effect.
@access public | effect | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function request($url, $options = array()) {
trigger_error(sprintf(__('%s does not have request() implemented', true), get_class($this)), E_USER_WARNING);
} | Make an XHR request
### Event Options
- `complete` - Callback to fire on complete.
- `success` - Callback to fire on success.
- `before` - Callback to fire on request initialization.
- `error` - Callback to fire on request failure.
### Options
- `method` - The method to make the request with defaults to GET in more libraries
- `async` - Whether or not you want an asynchronous request.
- `data` - Additional data to send.
- `update` - Dom id to update with the content of the request.
- `type` - Data type for response. 'json' and 'html' are supported. Default is html for most libraries.
- `evalScripts` - Whether or not <script> tags should be eval'ed.
- `dataExpression` - Should the `data` key be treated as a callback. Useful for supplying `$options['data']` as
another Javascript expression.
@param mixed $url Array or String URL to target with the request.
@param array $options Array of options. See above for cross library supported options
@return string XHR request.
@access public | request | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function drag($options = array()) {
trigger_error(sprintf(__('%s does not have drag() implemented', true), get_class($this)), E_USER_WARNING);
} | Create a draggable element. Works on the currently selected element.
Additional options may be supported by the library implementation.
### Options
- `handle` - selector to the handle element.
- `snapGrid` - The pixel grid that movement snaps to, an array(x, y)
- `container` - The element that acts as a bounding box for the draggable element.
### Event Options
- `start` - Event fired when the drag starts
- `drag` - Event fired on every step of the drag
- `stop` - Event fired when dragging stops (mouse release)
@param array $options Options array see above.
@return string Completed drag script
@access public | drag | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function drop($options = array()) {
trigger_error(sprintf(__('%s does not have drop() implemented', true), get_class($this)), E_USER_WARNING);
} | Create a droppable element. Allows for draggable elements to be dropped on it.
Additional options may be supported by the library implementation.
### Options
- `accept` - Selector for elements this droppable will accept.
- `hoverclass` - Class to add to droppable when a draggable is over.
### Event Options
- `drop` - Event fired when an element is dropped into the drop zone.
- `hover` - Event fired when a drag enters a drop zone.
- `leave` - Event fired when a drag is removed from a drop zone without being dropped.
@return string Completed drop script
@access public | drop | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function sortable() {
trigger_error(sprintf(__('%s does not have sortable() implemented', true), get_class($this)), E_USER_WARNING);
} | Create a sortable element.
Additional options may be supported by the library implementation.
### Options
- `containment` - Container for move action
- `handle` - Selector to handle element. Only this element will start sort action.
- `revert` - Whether or not to use an effect to move sortable into final position.
- `opacity` - Opacity of the placeholder
- `distance` - Distance a sortable must be dragged before sorting starts.
### Event Options
- `start` - Event fired when sorting starts
- `sort` - Event fired during sorting
- `complete` - Event fired when sorting completes.
@param array $options Array of options for the sortable. See above.
@return string Completed sortable script.
@access public | sortable | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function slider() {
trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING);
} | Create a slider UI widget. Comprised of a track and knob.
Additional options may be supported by the library implementation.
### Options
- `handle` - The id of the element used in sliding.
- `direction` - The direction of the slider either 'vertical' or 'horizontal'
- `min` - The min value for the slider.
- `max` - The max value for the slider.
- `step` - The number of steps or ticks the slider will have.
- `value` - The initial offset of the slider.
### Events
- `change` - Fired when the slider's value is updated
- `complete` - Fired when the user stops sliding the handle
@return string Completed slider script
@access public | slider | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function serializeForm() {
trigger_error(
sprintf(__('%s does not have serializeForm() implemented', true), get_class($this)), E_USER_WARNING
);
} | Serialize the form attached to $selector.
Pass `true` for $isForm if the current selection is a form element.
Converts the form or the form element attached to the current selection into a string/json object
(depending on the library implementation) for use with XHR operations.
### Options
- `isForm` - is the current selection a form, or an input? (defaults to false)
- `inline` - is the rendered statement going to be used inside another JS statement? (defaults to false)
@param array $options options for serialization generation.
@return string completed form serialization script
@access public | serializeForm | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _parseOptions($options, $safeKeys = array()) {
$out = array();
$safeKeys = array_flip($safeKeys);
foreach ($options as $key => $value) {
if (!is_int($value) && !isset($safeKeys[$key])) {
$value = $this->value($value);
}
$out[] = $key . ':' . $value;
}
sort($out);
return join(', ', $out);
} | Parse an options assoc array into an Javascript object literal.
Similar to object() but treats any non-integer value as a string,
does not include `{ }`
@param array $options Options to be converted
@param array $safeKeys Keys that should not be escaped.
@return string Parsed JSON options without enclosing { }.
@access protected | _parseOptions | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _mapOptions($method, $options) {
if (!isset($this->_optionMap[$method])) {
return $options;
}
foreach ($this->_optionMap[$method] as $abstract => $concrete) {
if (isset($options[$abstract])) {
$options[$concrete] = $options[$abstract];
unset($options[$abstract]);
}
}
return $options;
} | Maps Abstract options to engine specific option names.
If attributes are missing from the map, they are not changed.
@param string $method Name of method whose options are being worked with.
@param array $options Array of options to map.
@return array Array of mapped options.
@access protected | _mapOptions | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _prepareCallbacks($method, $options, $callbacks = array()) {
$wrapCallbacks = true;
if (isset($options['wrapCallbacks'])) {
$wrapCallbacks = $options['wrapCallbacks'];
}
unset($options['wrapCallbacks']);
if (!$wrapCallbacks) {
return $options;
}
$callbackOptions = array();
if (isset($this->_callbackArguments[$method])) {
$callbackOptions = $this->_callbackArguments[$method];
}
$callbacks = array_unique(array_merge(array_keys($callbackOptions), (array)$callbacks));
foreach ($callbacks as $callback) {
if (empty($options[$callback])) {
continue;
}
$args = null;
if (!empty($callbackOptions[$callback])) {
$args = $callbackOptions[$callback];
}
$options[$callback] = 'function (' . $args . ') {' . $options[$callback] . '}';
}
return $options;
} | Prepare callbacks and wrap them with function ([args]) { } as defined in
_callbackArgs array.
@param string $method Name of the method you are preparing callbacks for.
@param array $options Array of options being parsed
@param string $callbacks Additional Keys that contain callbacks
@return array Array of options with callbacks added.
@access protected | _prepareCallbacks | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
function _processOptions($method, $options) {
$options = $this->_mapOptions($method, $options);
$options = $this->_prepareCallbacks($method, $options);
$options = $this->_parseOptions($options, array_keys($this->_callbackArguments[$method]));
return $options;
} | Conveinence wrapper method for all common option processing steps.
Runs _mapOptions, _prepareCallbacks, and _parseOptions in order.
@param string $method Name of method processing options for.
@param array $options Array of options to process.
@return string Parsed options string.
@access protected | _processOptions | php | Datawalke/Coordino | cake/libs/view/helpers/js.php | https://github.com/Datawalke/Coordino/blob/master/cake/libs/view/helpers/js.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.