Ejemplo n.º 1
0
    /**
     * core
     *
     * @param string $formSelector
     * @param string $variable
     * @param array  $options
     *
     * @return void
     */
    public static function core($formSelector = '#admin-form', $variable = 'Phoenix', $options = array())
    {
        if (!static::inited(__METHOD__)) {
            JQueryScript::core();
            CoreScript::csrfToken();
            static::addJS(static::phoenixName() . '/js/phoenix/phoenix.js');
        }
        if (!static::inited(__METHOD__, get_defined_vars())) {
            $defaultOptions = array('theme' => 'bootstrap', 'uri' => get_object_vars(Ioc::getUriData()));
            $options = static::mergeOptions($defaultOptions, $options);
            if ($options['theme'] == 'bootstrap') {
                static::addJS(static::phoenixName() . '/js/phoenix/theme/bootstrap.js');
            }
            $options = static::getJSObject($defaultOptions, $options);
            $js = <<<JS
// Phoenix Core
jQuery(document).ready(function(\$)
{
\tvar core = \$('{$formSelector}').phoenix({$options});

\twindow.{$variable} = window.{$variable} || {};
\twindow.{$variable} = \$.extend(window.{$variable}, core);
});
JS;
            static::internalJS($js);
        }
    }
Ejemplo n.º 2
0
 /**
  * Vue Resource.
  *
  * @see  Configuration           https://github.com/vuejs/vue-resource/blob/master/docs/config.md
  * @see  HTTP Requests/Response  https://github.com/vuejs/vue-resource/blob/master/docs/http.md
  * @see  Creating Resources      https://github.com/vuejs/vue-resource/blob/master/docs/resource.md
  * @see  Code Recipes            https://github.com/vuejs/vue-resource/blob/master/docs/recipes.md
  *
  * @param array $options
  * @param array $headers
  */
 public static function resource(array $options = [], array $headers = [])
 {
     if (!static::inited(__METHOD__)) {
         static::core();
         static::addJS(static::phoenixName() . '/js/vue/vue-resource.min.js');
         $defaultOptions = ['root' => Ioc::getUriData()->path];
         $options = static::getJSObject($defaultOptions, $options);
         $defaultHealders = ['common' => ['X-Csrf-Token' => CsrfProtection::getFormToken()]];
         $headers = static::mergeOptions($defaultHealders, $headers);
         $headers = array_intersect_key($headers, array_flip(['common', 'custom', 'delete', 'patch', 'post', 'put']));
         $js[] = "// Init Vue-resource http settings.";
         $js[] = "Vue.http.options = Object.assign({}, Vue.http.options, {$options});";
         foreach ($headers as $key => $headerLines) {
             if (count($headerLines)) {
                 $js[] = "Vue.http.headers.{$key} = Object.assign({}, Vue.http.headers.{$key}, " . static::getJSObject($headerLines) . ");";
             }
         }
         static::internalJS(implode("\n", $js));
     }
 }