Skip to content

Commit

Permalink
Fix #131: More correct jQuery plugin initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Aug 12, 2014
1 parent 9dd6008 commit 7ec97f8
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion widgets/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function registerAssets()
AlertAsset::register($view);

if ($this->delay > 0) {
$js = '$("#' . $this->options['id'] . '").fadeTo(' . $this->delay . ', 0.00, function() {
$js = 'jQuery("#' . $this->options['id'] . '").fadeTo(' . $this->delay . ', 0.00, function() {
$(this).slideUp("slow", function() {
$(this).remove();
});
Expand Down
6 changes: 3 additions & 3 deletions widgets/ColorInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public function registerPluginAssets()
{
$view = $this->getView();
ColorInputAsset::register($view);
$input = '$("#' . $this->html5Options['id'] . '")';
$input = 'jQuery("#' . $this->html5Options['id'] . '")';
$this->registerPlugin('spectrum', $input);
$caption = '$("#' . $this->options['id'] . '")';
$input = '$("#' . $this->html5Options['id'] . '")';
$caption = 'jQuery("#' . $this->options['id'] . '")';
$input = 'jQuery("#' . $this->html5Options['id'] . '")';
$view->registerJs("{$caption}.change(function(){{$input}.spectrum('set', this.value)});\n");
}
}
4 changes: 2 additions & 2 deletions widgets/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function init()
if ($this->convertFormat && isset($this->pluginOptions['format'])) {
$this->pluginOptions['format'] = static::convertDateFormat($this->pluginOptions['format']);
}
$this->_id = ($this->type == self::TYPE_INPUT) ? '$("#' . $this->options['id'] . '")' : '$("#' . $this->options['id'] . '").parent()';
$this->_id = ($this->type == self::TYPE_INPUT) ? 'jQuery("#' . $this->options['id'] . '")' : 'jQuery("#' . $this->options['id'] . '").parent()';
$this->registerAssets();
echo $this->renderInput();
}
Expand Down Expand Up @@ -233,7 +233,7 @@ public function registerAssets()
} else {
DatePickerAsset::register($view);
}
$id = "$('#" . $this->options['id'] . "')";
$id = "jQuery('#" . $this->options['id'] . "')";
if ($this->type == self::TYPE_INLINE) {
$this->pluginEvents = ArrayHelper::merge($this->pluginEvents, ['changeDate' => 'function (e) { ' . $id . '.val(e.format());} ']);
}
Expand Down
4 changes: 2 additions & 2 deletions widgets/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function init()
if ($this->convertFormat && isset($this->pluginOptions['format'])) {
$this->pluginOptions['format'] = static::convertDateFormat($this->pluginOptions['format']);
}
$this->_id = ($this->type == self::TYPE_INPUT) ? '$("#' . $this->options['id'] . '")' : '$("#' . $this->options['id'] . '").parent()';
$this->_id = ($this->type == self::TYPE_INPUT) ? 'jQuery("#' . $this->options['id'] . '")' : 'jQuery("#' . $this->options['id'] . '").parent()';
$this->registerAssets();
echo $this->renderInput();
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public function registerAssets()
} else {
DateTimePickerAsset::register($view);
}
$id = "$('#" . $this->options['id'] . "')";
$id = "jQuery('#" . $this->options['id'] . "')";
if ($this->type == self::TYPE_INLINE) {
$this->pluginOptions['linkField'] = $this->options['id'];
if (!empty($this->pluginOptions['format'])) {
Expand Down
2 changes: 1 addition & 1 deletion widgets/DepDrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function init()
}
echo Select2::widget($settings);

$id = '$("#' . $this->options['id'] . '")';
$id = 'jQuery("#' . $this->options['id'] . '")';
$text = ArrayHelper::getValue($this->pluginOptions, 'loadingText', 'Loading ...');
$this->_view->registerJs("{$id}.on('depdrop.beforeChange',function(e,i,v){{$id}.select2('data',{text: '{$text}'});});");
$this->_view->registerJs("{$id}.on('depdrop.change',function(e,i,v,c){{$id}.select2('val',{$id}.val());});");
Expand Down
2 changes: 1 addition & 1 deletion widgets/FileInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function init()
Html::addCssClass($this->options, 'file-loading');
}
$input = $this->getInput('fileInput');
$id = '$("#' . $this->options['id'] . '")';
$id = 'jQuery("#' . $this->options['id'] . '")';
if ($this->showMessage) {
$validation = ArrayHelper::getValue($this->pluginOptions, 'showPreview', true) ? 'file preview and multiple file upload' : 'multiple file upload';
$message = '<strong>' . Yii::t('fileinput', 'Note:') . '</strong> ' . Yii::t('fileinput', 'Your browser does not support {validation}. Try an alternative or more recent browser to access these features.', ['validation' => $validation]);
Expand Down
4 changes: 2 additions & 2 deletions widgets/Html5Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public function registerAssets()
{
$view = $this->getView();
Html5InputAsset::register($view);
$caption = '$("#' . $this->options['id'] . '")';
$input = '$("#' . $this->html5Options['id'] . '")';
$caption = 'jQuery("#' . $this->options['id'] . '")';
$input = 'jQuery("#' . $this->html5Options['id'] . '")';
$js = "{$caption}.change(function(){{$input}.val(this.value)});\n" .
"{$input}.change(function(){{$caption}.val(this.value); {$caption}.trigger('change');});";
$view->registerJs($js);
Expand Down
6 changes: 3 additions & 3 deletions widgets/Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ public function registerAssets()
$this->pluginOptions['width'] = 'resolve';
if ($this->pluginLoading) {
$id = $this->options['id'];
$loading = "\$('.kv-plugin-loading.loading-{$id}')";
$loading = "jQuery('.kv-plugin-loading.loading-{$id}')";
$groupCss = "group-{$id}";
$group = "\$('.kv-hide.{$groupCss}')";
$el = "\$('#{$id}')";
$group = "jQuery('.kv-hide.{$groupCss}')";
$el = "jQuery('#{$id}')";
$callback = <<< JS
function(){
var \$container = {$el}.select2('container');
Expand Down
2 changes: 1 addition & 1 deletion widgets/Spinner.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function registerAssets()
{
$view = $this->getView();
SpinnerAsset::register($view);
$id = '$("#' . $this->options['id'] . '").find(".kv-spin")';
$id = 'jQuery("#' . $this->options['id'] . '").find(".kv-spin")';

if ($this->_validPreset) {
$js = (isset($this->color)) ? "{$id}.spin('{$this->preset}', '{$this->color}');" : "{$id}.spin('{$this->preset}');";
Expand Down
2 changes: 1 addition & 1 deletion widgets/SwitchInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function registerAssets()
$this->pluginOptions['animate'] = true;
}
if ($this->type == self::RADIO) {
$this->registerPlugin('bootstrapSwitch', '$("[name = \'' . $this->name . '\']")');
$this->registerPlugin('bootstrapSwitch', 'jQuery("[name = \'' . $this->name . '\']")');
} else {
$this->registerPlugin('bootstrapSwitch');
}
Expand Down
2 changes: 1 addition & 1 deletion widgets/TouchSpin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function renderButton($options = [])
public function registerAssets()
{
$view = $this->getView();
$id = '$("#' . $this->options['id'] . '").parent()'; //unused
$id = 'jQuery("#' . $this->options['id'] . '").parent()'; //unused
TouchSpinAsset::register($view);
$this->registerPlugin('TouchSpin');
}
Expand Down
4 changes: 2 additions & 2 deletions widgets/Typeahead.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function parseSource($source = [])
$remote = $source['remote'];
/* Add a spinning indicator for remote calls */
$r = is_array($remote) ? $remote : ['url' => $remote];
$hint = '$("#' . $this->options['id'] . '")';
$hint = 'jQuery("#' . $this->options['id'] . '")';
if (empty($r['beforeSend'])) {
$r['beforeSend'] = new JsExpression("function (xhr) { alert('before'); {$hint}.addClass('loading'); }");
}
Expand All @@ -195,7 +195,7 @@ public function registerAssets()
TypeaheadAsset::register($view);
$this->registerPluginOptions('typeahead');
$view->registerJs($this->_bloodhound);
$view->registerJs('$("#' . $this->options['id'] . '").typeahead(' . $this->_hashVar . ',' . $this->_dataset . ');');
$view->registerJs('jQuery("#' . $this->options['id'] . '").typeahead(' . $this->_hashVar . ',' . $this->_dataset . ');');
$this->registerPluginEvents($view);
}
}
4 changes: 2 additions & 2 deletions widgets/TypeaheadBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function initOptions()
protected function registerPluginEvents($view)
{
if (!empty($this->pluginEvents)) {
$id = '$("#' . $this->options['id'] . '")';
$id = 'jQuery("#' . $this->options['id'] . '")';
$js = [];
foreach ($this->pluginEvents as $event => $handler) {
$function = new JsExpression($handler);
Expand All @@ -105,7 +105,7 @@ public function registerAssets()
$dataVar = str_replace('-', '_', $this->options['id'] . '_data');
$view->registerJs('var ' . $dataVar . ' = ' . Json::encode(array_values($this->data)) . ';');
$dataset = Json::encode(['name' => $dataVar, 'source' => new JsExpression('substringMatcher(' . $dataVar . ')')]);
$view->registerJs('$("#' . $this->options['id'] . '").typeahead(' . $this->_hashVar . ',' . $dataset . ');');
$view->registerJs('jQuery("#' . $this->options['id'] . '").typeahead(' . $this->_hashVar . ',' . $dataset . ');');
$this->registerPluginEvents($view);
}
}
2 changes: 1 addition & 1 deletion widgets/TypeaheadOld.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function setPluginOptions()
/* Add a spinning indicator for remote calls */
if (!empty($d['remote'])) {
$r = is_array($d['remote']) ? $d['remote'] : ['url' => $d['remote']];
$hint = '$("#' . $this->options['id'] . '").parent().children(".tt-hint")';
$hint = 'jQuery("#' . $this->options['id'] . '").parent().children(".tt-hint")';
if (empty($r['beforeSend'])) {
$r['beforeSend'] = new JsExpression("function (xhr) { {$hint}.addClass('loading'); }");
}
Expand Down

0 comments on commit 7ec97f8

Please sign in to comment.