作者:jimminababa
项目:sangkilbiz
/**
*
* @param View $view
* @param array $data
*/
public static function bizConfig($view, $config = [], $position = View::POS_BEGIN)
{
$default = ['delay' => 1000, 'limit' => 20, 'checkStock' => false, 'debug' => YII_ENV == 'dev', 'pullUrl' => \yii\helpers\Url::to(['/master/sources/pull'])];
$js = "\n var biz = biz || {};" . "\n biz.config = " . Json::encode(ArrayHelper::merge($default, $config)) . ";\n";
$view->registerJs($js, $position);
BizAsset::register($view);
}
作者:slava
项目:placemen
/**
* Adds an asset to the view
*
* @param View $view The View object
* @param string $file The asset file name
* @param string $type The asset file type (css or js)
* @param string $class The class name of the AssetBundle
*
* @return void
*/
protected function addAsset($view, $file, $type, $class)
{
if ($type == 'css' || $type == 'js') {
$asset = $view->getAssetManager();
$bundle = $asset->bundles[$class];
if ($type == 'css') {
$bundle->css[] = $file;
} else {
$bundle->js[] = $file;
}
$asset->bundles[$class] = $bundle;
$view->setAssetManager($asset);
}
}
作者:mzdan
项目:yii2-daterangepicke
/**
* @param string $language
* @param View $view
*/
public function registerLanguage($language, $view)
{
if (file_exists($this->sourcePath . "/locale/{$language}.js")) {
$this->js = array_merge($this->js, ['min/locales.min.js']);
$view->registerJsFile($this->baseUrl . "/locale/{$language}.js");
$js = <<<JS
moment.locale('{$language}');
JS;
$view->registerJs($js, View::POS_READY, 'moment-locale-' . $language);
}
}
作者:haunt
项目:yii2-basketjs-asse
/**
* Registers the CSS and JS files with the given view.
* @param \yii\web\View $view the view that the asset files are to be registered with.
*/
public function registerAssetFiles($view)
{
$manager = $view->getAssetManager();
foreach ($this->css as $css) {
$view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
}
$view->registerJsFile($this->basketJs);
$jsFiles = [];
foreach ($this->js as $js) {
$jsFiles[] = Json::encode(['url' => $manager->getAssetUrl($this, $js)]);
}
$view->registerJs(sprintf('basket.require(%s);', implode(",\r\n", $jsFiles)), View::POS_END);
}
作者:manyoubaby12
项目:imsho
/**
* @param View $view
*/
public function applyTo(View $view)
{
$attributes = $this->getAttributes(null, ['id', 'meta_id']);
foreach ($attributes as $name => $value) {
$view->registerMetaTag(['property' => 'twitter:' . $name, 'content' => $value]);
}
}
作者:yarisrespec
项目:yii2-nprogres
/**
* Registers the CSS and JS files with the given view.
* @param \yii\web\View $view the view that the asset files are to be registered with.
*/
public function registerAssetFiles($view)
{
if ($this->configuration !== null) {
$view->registerJs('NProgress.configure(' . Json::encode($this->configuration) . ');');
}
$view->registerJs(<<<JS
jQuery(document).on('pjax:start', function() { NProgress.start(); });
jQuery(document).on('pjax:end', function() { NProgress.done(); });
JS
);
$view->registerJs(<<<JS
var exceptUrls = [
];
jQuery(document).on('ajaxSend', function(e, xhr, options) {
if( \$.inArray( options.url, exceptUrls ) == -1)
NProgress.start();
});
jQuery(document).on('ajaxComplete', function(e, xhr, options) {
if( \$.inArray( options.url, exceptUrls ) == -1 )
NProgress.done();
});
JS
);
parent::registerAssetFiles($view);
}
作者:webvimar
项目:module-seo-pane
/**
* Register global meta tags like verifications and so on
*
* @param View $view
*/
protected static function registerGlobalMetaTags($view)
{
$globalMetaTags = Yii::$app->cache->get('__globalMetaTags');
if ($globalMetaTags === false) {
$globalMetaTags = GlobalMetaTag::find()->andWhere(['active' => 1])->asArray()->all();
Yii::$app->cache->set('__globalMetaTags', $globalMetaTags, 3600 * 24);
}
foreach ($globalMetaTags as $globalTag) {
$view->registerMetaTag(['name' => $globalTag['name'], 'content' => $globalTag['content']], $globalTag['name']);
}
}
作者:mg-cod
项目:yii2-session-timeout-warnin
/**
* Initializes plugin
* @param View $view
* @return $this
*/
public function initPlugin(View $view, $options = [])
{
$options = array_merge(['message' => Yii::t('mgcode/sessionWarning', 'Your session is going to expire at {time}.')], $options);
$json = Json::encode($options);
$view->registerJs("\$('#session-warning-modal').sessionWarning({$json});");
return $this;
}
作者:weiyiy
项目:bas
public function sendMessage($to, $file, $params = [])
{
$view = new View();
$message = ['from' => $this->from, 'to' => $to, 'to' => '+8618670366212', 'text' => $view->render($file, $params)];
return;
//@todo remove
$this->getTransport()->send($message);
}
作者:bigpauli
项目:yii2-fancybo
/**
* Register scripts
* @param View $view
*/
protected function registerScripts(\yii\web\View $view)
{
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#{$this->id}').fancybox({$options});";
$view->registerJs($js, View::POS_READY);
}
}
作者:tsyry
项目:mybrio
/**
* @param View $view
* @param KursExtended $kursRecord
* @param mixed $tip
* @return string
*/
function renderRazdelyTipa($view, $kursRecord, $tip)
{
$ret = '';
$query = $kursRecord->getRazdelyKursaRel()->orderBy('nomer')->where(['tip' => TipRazdelaKursa::asSql($tip)]);
foreach ($query->all() as $razdelRecord) {
$ret .= $view->render('_razdel-kursa', compact('razdelRecord'));
}
return $ret;
}
作者:netis-p
项目:yii2-cru
/**
* Registers JS code to help initialize Select2 widgets
* with access to netis\crud\crud\ActiveController API.
* @param \yii\web\View $view
*/
public static function registerSelect($view)
{
$script = <<<JavaScript
(function (s2helper, \$, undefined) {
"use strict";
s2helper.formatResult = function (result, container, query, escapeMarkup, depth) {
if (typeof depth == 'undefined') {
depth = 0;
}
var markup = [];
window.Select2.util.markMatch(result._label, query.term, markup, escapeMarkup);
return markup.join("");
};
s2helper.formatSelection = function (item) {
return item._label;
};
// generates query params
s2helper.data = function (term, page) {
return { search: term, page: page };
};
// builds query results from ajax response
s2helper.results = function (data, page) {
return { results: data.items, more: page < data._meta.pageCount };
};
s2helper.getParams = function (element) {
var primaryKey = element.data('relation-pk');
if (typeof primaryKey === 'undefined' || primaryKey === null) {
primaryKey = 'id';
}
var params = {search: {}};
params.search[primaryKey] = element.val();
return params;
};
s2helper.initSingle = function (element, callback) {
\$.getJSON(element.data('select2').opts.ajax.url, s2helper.getParams(element), function (data) {
if (typeof data.items[0] != 'undefined') {
callback(data.items[0]);
}
});
};
s2helper.initMulti = function (element, callback) {
\$.getJSON(element.data('select2').opts.ajax.url, s2helper.getParams(element), function (data) {callback(data.items);});
};
}( window.s2helper = window.s2helper || {}, jQuery ));
JavaScript;
$view->registerJs($script, \yii\web\View::POS_END, 'netis.s2helper');
\maddoger\widgets\Select2BootstrapAsset::register($view);
}
作者:CBETOBu
项目:yii2-widget
/**
* Registers plugin events
*
* @param View $view The View object
*/
protected function registerPluginEvents($view)
{
if (!empty($this->pluginEvents)) {
$id = 'jQuery("#' . $this->options['id'] . '")';
$js = [];
foreach ($this->pluginEvents as $event => $handler) {
$function = new JsExpression($handler);
$js[] = "{$id}.on('{$event}', {$function});";
}
$js = implode("\n", $js);
$view->registerJs($js);
}
}
作者:madan
项目:yii2-momentj
/**
* @param \yii\web\View $view
* @throws \yii\base\InvalidConfigException If file with the locale is not exists.
*/
public function registerLocaleInternal($view)
{
$localeFilePath = $this->tryFindLocale();
if (YII_DEBUG && !$localeFilePath) {
throw new InvalidConfigException('Locale file "' . \Yii::$app->language . '" not exists!');
}
$manager = $view->getAssetManager();
$view->registerJsFile($manager->getAssetUrl($this, $this->locale), $this->jsOptions, 'moment-locale-' . $this->locale);
if ($this->setLocaleOnReady) {
$js = "moment().locale('" . $this->locale . "');";
$view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
}
}
作者:servocode
项目:yii2-momentj
/**
* @param \yii\web\View $view
* @throws \yii\base\InvalidConfigException If file with the locale is not exists.
*/
public function registerLocaleInternal($view)
{
$localeFile = strtolower($this->locale) . '.js';
$localeFilePath = "{$this->sourcePath}/{$localeFile}";
if (YII_DEBUG && !file_exists($localeFilePath)) {
throw new InvalidConfigException('Locale file "' . $localeFilePath . '" not exists!');
}
$manager = $view->getAssetManager();
$view->registerJsFile($manager->getAssetUrl($this, $localeFile), $this->jsOptions, 'moment-locale-' . $this->locale);
if ($this->setLocaleOnReady) {
$js = "moment.locale('{$this->locale}');'";
$view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
}
}
作者:jacmo
项目:yii2-mdpages-modul
/**
* This View class overrides render and findViewFile
* to use the theme view files
*/
public function render($view, $params = array(), $context = null)
{
if ($context === null) {
$context = $this->context;
}
return parent::render($view, $params, $context);
}
作者:deesof
项目:yii2-de
/**
* @inheritdoc
*/
public function registerJs($js, $position = null, $key = null)
{
if ($position === null && NgView::$instance) {
$position = NgView::$instance->getController() ?: self::POS_READY;
}
parent::registerJs($js, $position, $key);
}
作者:phpson
项目:ExtJS5-Yii
public function registerAssetFiles(View $view)
{
$manager = $view->getAssetManager();
$arr_js = $this->js;
$arr_css = $this->css;
if (isset($view->context->layout) && $view->context->layout === 'parts') {
$arr_js = $this->js_parts;
$arr_css = $this->css_parts;
}
foreach ($arr_js as $js) {
$view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
}
foreach ($arr_css as $css) {
$view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
}
}
作者:tecnologiaterabyt
项目:yii2-foru
/**
* @inheritdoc
*/
public function afterRender($viewFile, $params, &$output)
{
parent::afterRender($viewFile, $params, $output);
if (isset($params['dataProvider']) && $params['dataProvider'] instanceof DataProviderInterface && $params['dataProvider']->pagination instanceof Pagination) {
$this->title .= $this->getPage($params['dataProvider']->pagination);
}
}
作者:mauriziocingolan
项目:yii2-fmwk-ph
/**
* Imposta il titolo della pagina secondo i seguenti criteri:
* <ul>
* <li>Se la proprietà <code>$pageTitle</code> non è impostata viene utilizzato il parametro
* <code>'title'</code> dell'applicazione. Se nemmeno quest'ultimo è impostato viene sollevata
* un'eccezione.</li>
* <li>Se la proprietà <code>$pageTitle</code> è assegnata, allora viene utilizzato il parametro
* <code>'title'</code> dell'applicazione come prefisso, sempre che sia stato impostato. Il separatore
* tra il prefisso e il titolo della pagina può essere specificato tramite il parametro <code>'titleSeparator'</code>
* dell'applicazione. Altrimenti viene utilizzato di default il carattere '-'.</li>
* </ul>
* Quindi imposta la descrizione della pagina secondo i seguenti criteri:
* <ul>
* <li>Se la proprietà <code>$pageDescription</code> non è assegnata esplicitamente viene utilizzato
* il parametro <code>'description'</code> dell'applicazione.</li>
* <li>Se nemmeno il parametro <code>'description'</code> è assegnato viene sollevata un'eccezione</li>
* </ul>
* Le impostazioni vengono fatte in questo metodo per consentire l'assegnazione del valore
* alla proprietà <code>$pageTitle</code> e <code>$pageDescription</code> nella view invece che nel controller.
* @throws \yii\base\InvalidConfigException Se nessun titolo o nessuna descrizione sono stati impostati
*/
public function afterRender($viewFile, $params, &$output)
{
parent::afterRender($viewFile, $params, $output);
# titolo
if ($this->pageTitle) {
if (isset(Yii::$app->params['title'])) {
$this->title = Yii::$app->params['title'] . ' ' . (isset(Yii::$app->params['titleSeparator']) ? Yii::$app->params['titleSeparator'] : '-') . ' ' . $this->pageTitle;
}
} else {
if (isset(Yii::$app->params['title'])) {
$this->title = Yii::$app->params['title'];
} else {
throw new \yii\base\InvalidConfigException('Il parametro \'title\' non è stato impostato.');
}
}
# descrizione
if (!$this->pageDescription) {
if (isset(Yii::$app->params['description'])) {
$this->pageDescription = Yii::$app->params['description'];
} else {
throw new \yii\base\InvalidConfigException('Il parametro \'description\' non è stato impostato.');
}
} else {
}
}