Ejemplo n.º 1
0
/**
 * Provides a checkbox styled as a switch.
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 *
 * The element can contain these variables (all are optional):
 *     switchtext        text        Text to be displayed on button - chosen by style
 *                                   valid options are 'onoff', 'yesno', 'truefalse' - used for headdata
 *     wrapperclass      text        Class to use on the div wrapper
 *
 * @return string           The HTML for the element
 */
function pieform_element_switchbox(Pieform $form, $element)
{
    $wrapper = !empty($element['wrapperclass']) ? $element['wrapperclass'] : '';
    $html = '<div class="' . $wrapper . '">' . pieform_element_checkbox($form, $element) . '</div>';
    $labels = pieform_element_switchbox_labeltext($element);
    // Dealing with the label text
    $type = $labels['type'];
    $onlabel = $labels['on'];
    $offlabel = $labels['off'];
    $strlength = max(strlen($onlabel), strlen($offlabel));
    $width = floor(57 + ($strlength - 2) * 3.5 + pow(1.4, $strlength - 2)) . 'px';
    $elementid = $form->make_id($element, $form->get_name());
    $html = '<div class="form-switch ' . $wrapper . '">';
    $html .= '    <div class="switch ' . $type . '" style="width:' . $width . '">';
    $html .= pieform_element_checkbox($form, $element);
    $html .= '        <label class="switch-label" tabindex="1" for="' . $elementid . '">';
    $html .= '            <span class="switch-inner" role="presentation"></span>';
    $html .= '            <span class="switch-indicator" role="presentation"></span>';
    $html .= '            <span class="state-label on" role="presentation" tabindex="-1">' . $onlabel . '</span>';
    $html .= '            <span class="state-label off" role="presentation" tabindex="-1">' . $offlabel . '</span>';
    $html .= '        </label>';
    $html .= '    </div>';
    $html .= '</div>';
    return $html;
}
Ejemplo n.º 2
0
/**
 * Provides a checkbox styled as a switch.
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 *
 * The element can contain these variables (all are optional):
 *     switchtext        text        Text to be displayed on button - chosen by style
 *                                   valid options are 'onoff', 'yesno', 'truefalse' - used for headdata
 *     wrapperclass      text        Class to use on the div wrapper
 *
 * @return string           The HTML for the element
 */
function pieform_element_switchbox(Pieform $form, $element)
{
    $wrapper = !empty($element['wrapperclass']) ? $element['wrapperclass'] : '';
    $html = '<div class="' . $wrapper . '">' . pieform_element_checkbox($form, $element) . '</div>';
    // Dealing with the label text
    $switchtext = isset($element['switchtext']) ? $element['switchtext'] : 'onoff';
    $html = '<div class="form-switch ' . $wrapper . '">';
    $html .= '    <div class="switch ' . $switchtext . '">' . pieform_element_checkbox($form, $element);
    $elementid = $form->make_id($element, $form->get_name());
    $html .= '        <label class="switch-label" for="' . $elementid . '">';
    $html .= '            <span class="switch-inner"></span>';
    $html .= '            <span class="switch-switch"></span>';
    $html .= '        </label>';
    $html .= '    </div>';
    $html .= '</div>';
    return $html;
}