How to remove class from all list of an id with prototypejs - prototypejs

I want to remove all classes named active of all <li> under <ul id="navNovelty"> using prototypejs.
I did $('ul#navNovelty li').removeClassName('active'); but it did not work. Here is my full code
<ul id="navNovelty" class="nav om">
<li id="multimedia" class="active">Multimedia</li>
<li id="love">Love & Family</li>
<li>MyBusiness</li>
</ul>
How to remove class from all list of an id with prototypejs ?

Unlike jQuery, Prototype has a different accessor for single elements and multiple elements. If you want to target a single item, and find it by its id, you use one dollar sign:
$('navNovelty').removeClassName('active');
If you want to access multiple items, you use two:
$$('ul#navNovelty li').map('removeClassName', 'active');

Related

How to prevent loops in laravel global variable

I've created file GlobalVariable.php inside app\Composers
public function compose($view)
{
$categories = \App\Models\Category::all();
$view->with('globCategory', $categories);
}
then register to AppServiceProvider the code view()->composer('*', GlobalVariable::class);
I use global $globCategory for creating dynamic navbar
<ul class="nav nav-tabs border-0 flex-column flex-lg-row">
#foreach ($globCategory as $item)
<li class="nav-item">
{{$item->name}}
</li>
#endforeach
</ul>
the only problem here when I see laravel debuggar it show repetition of categories query.
here is the result
How to avoid this looping query? is there correct way?
The way you're registering your view composer (using '*' instead of a particular view name), it's going to call the compose method for every single rendered view + subview.
What you can do is instead of this:
view()->composer('*', GlobalVariable::class);
Have this:
\View::share('globCategory', \App\Models\Category::all());
This will globally share your categories (within views), and run the query only once.
View composers, as described from the laravel documentation, bind data to a view every time it is rendered. They clean our code by getting fetching data once and passing it to the view.
While it is possible to get the data in every controller method and pass it to the single view, this approach may be undesirable.
Replace the view name with an asterisk wildcard.

fetching all the data from a partially hidden list watir

I'm trying to fetch a span of 4,600 elements
<span> 4,600 </span>
i inspected the elements and found that each element is a list class which has a child class with a title and href that i want to fetch the problem is that :
not all elements are visible , you would have to scroll down the api to find more elements
i cant seem to successfully fetch a single piece of data
puts browser.th(:class => %w("_9irns _pg23k _jpwof _gvoze")).link.hreflang
this is the structure of the code i'm trying to fetch
<ul class = 'xxx'>
<div class = 'xxa'>
<li class ='fff'>
<li class ='fff'>
<li class ='fff'>
.
.
the <li class = 'fff'> has <a class='xxx xxx xxx xxx'> having the data i'm trying to fetch tittle and href
to be more clear how can I iterate over all the classes of 'fff' and pick a url which is in a child class of it.
Don't use quotes inside the %w to find an element from a collection of classes, and try requiring watigiri gem and using #text! to obtain text of hidden elements.

Select href with id and class using xpath

let say I have DOM like this:
<div id="tabsmenu">
<ul>
<li class="one">foo</li>
<li class="two">baz </li>
</ul>
</div>
and I would like to get the text from <a href> elements:
# desired output: ['#foo', '#baz']
How to do it using xpath and using combination id and element with a specific class within id ?
Already tried:
some_doc.xpath('//a[#id="tabsmenu"]/[#class="ui-tabs-anchor"]/#href')
# select all href tags of any a element that is in id tabsmenu and class attribute ui- tabs-anchor
EDIT - corrected tabmenu into tabsmenu
You're most likely looking for something like this:
//div[#id='tabsmenu']//a[#class='ui-tabs-anchor']/#href
That will get all href attributes that are part of an a tag with the class ui-tabs-anchor and inside a div element with the id tabsmenu.
Also you might want to take a look at this question:
Find out if class name contains certain text
This is because the class will match the exact value (ui-tabs-anchor) and maybe some additional class might be added there such as class="ui-tabs-anchor disabled" and then there will not be a match in there.

Laravel 4 - understanding View::share()

From what I understand:
View::share('foo','bar');
Will make $foo available in all views.
However, is it correct to say View::share() can be used only in the __construct()?
Because from outside __construct() I can't make it to work.
View::share should be available anywhere within your application. A common place that it is used is in view composers, but it should be usable within a route or wherever you need it.
Yes, adding:
View::share('foo','bar');
in your routes.php file will make $foo (with a value of 'bar') available in all views. This is especially useful for something like Twitter Bootstrap's "active" navigation classes. For example, you could do:
View::share('navactive', '');
to make sure the navactive variable is set in all views (and thus won't throw errors) and then when you are making views (in your controller, for example), you could pass:
return View::make('one')->with('navactive', 'one');
and then in your view (preferably some bootstrappy blade template) you can do the following:
<ul class="nav">
#if ( Auth::user() )
<li #if ($navactive === 'one') class="active" #endif>One</li>
<li #if ($navactive === 'three') class="active" #endif>Three</li>
<li #if ($navactive === 'five') class="active" #endif>Five</li>
#endif
</ul>
Basically if you want to share the variables through all view, you might first want to create a base route(E.x.:internalController.php) as a parent class then extend other controllers as a child of it(E.x:childController.php).
And yeah you will most likely set the view::share('foo', $bar) in the __constructor() of the internalController.php, since it lunches whenever the class is initialized, this way the parent class will serve the variable values to the child classes.

Magento - Add category name as a classname to list item in main navigation

In the main menu, I'd like to add the name of each category as a classname to the list item, for example
<li class="level0 nav-3 brands level-top parent">
<a href="http://www.examplesite.co.uk/brands.html" class="level-top">
<span>Brands</span>
</a>
</li>
The place the navigation is rendered can be found in Mage_Catalog_Block_Navigation::_renderCategoryMenuItemHtml, which is located in app/code/core/Mage/Catalog/Block/Navigation. The first argument passed to the function is the category, I imagine you can pull the name out of that and add it into the $classes array (~line 247 in Magento 1.7). You should of course consider creating your own module and rewriting that block, rather than editing the core file.

Resources