Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelligent and more correct Html addCssClass #7896

Closed
kartik-v opened this issue Mar 27, 2015 · 4 comments
Closed

Intelligent and more correct Html addCssClass #7896

kartik-v opened this issue Mar 27, 2015 · 4 comments

Comments

@kartik-v
Copy link
Contributor

I will be submitting a PR for improving and making the Html::addCssClass more intelligent and more practical to use for all use cases - similar or better than jquery addClass.

Enhancements:

  • Parse the original $options['class'] correctly irrespective of whitespaces (tabs, newlines or spaces)
  • Parse the $class param correctly irrespective of whitespaces (tabs, newlines or spaces)
  • If the $class property is separated by spaces... it will validate each class separately already added and
  • Intelligently do not append css class if it already exists irrespective of the whitespace

Current Implementation

Example

$options = ['class' => '    kartik']; // note the whitespace
Html::addCssClass($options, ' hide    kartik  robot');
Html::addCssClass($options, "\tkartik   hide fancy    box     holy");

Output

// generated output
$options['class'] =  '    kartik  hide    kartik  robot         kartik   hide fancy    box     holy';

Proposed Implementation (After PR Change)

Example

$options = ['class' => '    kartik']; // note the whitespace
Html::addCssClass($options, ' hide    kartik  robot');
Html::addCssClass($options, "\tkartik   hide fancy    box     holy");

Output

// generated output
$options['class'] =  'kartik hide robot fancy box holy';
@cebe
Copy link
Member

cebe commented Mar 27, 2015

how realistic is it that this method will receive unclean input? In general improvement is good but it should not add too much overhead.

@kartik-v
Copy link
Contributor Author

The purpose is not just for unclean input... but it currently does not correctly support adding CSS class separated by white spaces. Let's say I want to add 5 different CSS classes to an options... the current approach is to call this method 5 times.

@cebe
Copy link
Member

cebe commented Mar 27, 2015

sure, that should be possible.

@klimov-paul
Copy link
Member

how realistic is it that this method will receive unclean input? In general improvement is good but it should not add too much overhead.

Agreed.

Let's say I want to add 5 different CSS classes to an options... the current approach is to call this method 5 times.

Will be resolved by #8458

Closed in favor of #6043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants