示例#1
0
function Q_after_Q_tool_render($params, &$result)
{
    $info = $params['info'];
    $extra = $params['extra'];
    if (!is_array($extra)) {
        $extra = array();
    }
    $id_prefix = Q_Html::getIdPrefix();
    $tool_ids = Q_Html::getToolIds();
    $tag = Q::ifset($extra, 'tag', 'div');
    if (empty($tag)) {
        Q_Html::popIdPrefix();
        return;
    }
    $classes = '';
    $data_options = '';
    $count = count($info);
    foreach ($info as $name => $opt) {
        $classes = ($classes ? "{$classes} " : $classes) . implode('_', explode('/', $name)) . '_tool';
        $options = Q_Response::getToolOptions($name);
        if (isset($options)) {
            $friendly_options = str_replace(array('"', '\\/'), array('"', '/'), Q_Html::text(Q::json_encode($options)));
        } else {
            $friendly_options = '';
        }
        $normalized = Q_Utils::normalize($name, '-');
        if (isset($options) or $count > 1) {
            $id = $tool_ids[$name];
            $id_string = $count > 1 ? "{$id} " : '';
            $data_options .= " data-{$normalized}='{$id_string}{$friendly_options}'";
        }
        $names[] = $name;
    }
    if (isset($extra['classes'])) {
        $classes .= ' ' . $extra['classes'];
    }
    $attributes = isset($extra['attributes']) ? ' ' . Q_Html::attributes($extra['attributes']) : '';
    $data_retain = !empty($extra['retain']) || Q_Response::shouldRetainTool($id_prefix) ? " data-Q-retain=''" : '';
    $data_replace = !empty($extra['replace']) || Q_Response::shouldReplaceWithTool($id_prefix) ? " data-Q-replace=''" : '';
    $names = $count === 1 ? ' ' . key($info) : 's ' . implode(" ", $names);
    $ajax = Q_Request::isAjax();
    $result = "<{$tag} id='{$id_prefix}tool' " . "class='Q_tool {$classes}'{$data_options}{$data_retain}{$data_replace}{$attributes}>" . "{$result}</{$tag}>";
    if (!Q_Request::isAjax()) {
        $result = "<!--\nbegin tool{$names}\n-->{$result}<!--\nend tool{$names} \n-->";
    }
    Q_Html::popIdPrefix();
}
示例#2
0
 /**
  * Gets the current content of a slot, if any.
  * If slot content is null, then raises an event
  * to try to fill the slot. If it is filled,
  * returns the content. Otherwise, returns null.
  * @method fillSlot
  * @static
  * @param {string|array} $slotName The name of the slot.
  * @param {boolean} [$default_slotName=null] If the slot named in $slotName returns null,
  *  the handler corresponding to the default slot will be called,
  *  passing it the requested slot's name in the 'slotName' parameter,
  *  and its value will be returned instead.
  *  Note: this does not fill the slot named $default_slotName!
  *  That is to say, the computed value is not saved, so that
  *  the slot's handler is called again if it is ever consulted again.
  * @param {string} [$prefix=null] Sets a prefix for the HTML ids of all the elements in the slot.
  * @return {string|null}
  */
 static function fillSlot($slotName, $default_slotName = null, $prefix = null)
 {
     if (isset(self::$slots[$slotName])) {
         return self::$slots[$slotName];
     }
     $prev_slotName = self::$slotName;
     self::$slotName = $slotName;
     if (isset($prefix)) {
         Q_Html::pushIdPrefix($prefix);
     }
     try {
         if (isset($default_slotName)) {
             if (!Q::canHandle("Q/response/{$slotName}")) {
                 /**
                  * @event Q/response/$default_slotName
                  * @param {string} slotName
                  * @return {string}
                  */
                 $result = Q::event("Q/response/{$default_slotName}", compact('slotName'));
                 if (isset(self::$slots[$slotName])) {
                     // The slot was already filled, while we were rendering it
                     // so discard the $result and return the slot's contents
                     return self::$slots[$slotName];
                 }
                 return self::$slots[$slotName] = $result;
             }
         }
         /**
          * @event Q/response/$slotName
          * @return {string}
          */
         $result = Q::event("Q/response/{$slotName}");
     } catch (Exception $e) {
         self::$slotName = $prev_slotName;
         if (isset($prefix)) {
             Q_Html::popIdPrefix();
         }
         throw $e;
     }
     self::$slotName = $prev_slotName;
     if (isset($prefix)) {
         Q_Html::popIdPrefix();
     }
     if (isset(self::$slots[$slotName])) {
         // The slot was already filled, while we were rendering it
         // so discard the $result and return the slot's contents
         return self::$slots[$slotName];
     }
     if (isset($result)) {
         self::setSlot($slotName, $result);
         return $result;
     }
     // Otherwise, render default slot
     if (!isset($default_slotName)) {
         return null;
     }
     /**
      * @event Q/response/$default_slotName
      * @param {string} slotName
      * @return {string}
      */
     return Q::event("Q/response/{$default_slotName}", compact('slotName'));
 }