Post by WintersWolf » Thu Oct 01, 2015 7:22 am

Currently trying to wrap my head around something in OpenCart. It's been years since I have done anything with PHP so having a little trouble. I'm redirecting clicks of href links in to the same div the page is in but some href links need to be ignored because they add elements to the page. I'm ignoring them with a not() selector via my own class I am adding to links I want to ignore, though having trouble adding a class to some links.

For example on the products form for adding products there's an option tab which lets you add different options such as check boxes and date/time. The drop down menu for adding these options has some href links that I can't seem to figure out how to add a class to.

Here's a pastebin to the product_form.php: http://pastebin.com/Fchxw8XG

Here's a look at the actual pages html through chrome dev tools: http://i.imgur.com/SwqO1Tp.png

I just need to figure out how to add a class called navtab to these dropdown links so I can ignore them.

Newbie

Posts

Joined
Tue Sep 29, 2015 7:08 am

Post by straightlight » Thu Oct 01, 2015 7:35 am

SInce the class name is called navtab, you could pull the href link by using this jQuery statement:

Code: Select all

navtab = $('.navtab').attr('href');

alert(navtab);
This will popup every click event you use on the navtab class. If you want to remove the popup box, simply remove the alert line. From the defined navtab variable, you could add IF statement for all the URLs you want to pull or you could use AJAX to call PHP in order to pull valid URLs from a PHP array.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by WintersWolf » Thu Oct 01, 2015 8:59 am

straightlight wrote:SInce the class name is called navtab, you could pull the href link by using this jQuery statement:

Code: Select all

navtab = $('.navtab').attr('href');

alert(navtab);
This will popup every click event you use on the navtab class. If you want to remove the popup box, simply remove the alert line. From the defined navtab variable, you could add IF statement for all the URLs you want to pull or you could use AJAX to call PHP in order to pull valid URLs from a PHP array.
Not sure I really understood, I don't think that really helps what I am trying to do however it did give me an idea of how I could fix the problem. So instead of finding where the href links are created I instead put in a little script that detects when links are clicked in that div and adds a class to them, and then my other script I am using to load all links to other pages within the same div ignores these links.

So this is my solution:

Code: Select all

$(function(){
    var option = $('#tab-option');
    option.delegate('a','click',function(){
        option.addClass('navtab');
        $(this).addClass('navtab');
    });
});
After that this runs to ignore all links with a class of navtab:

Code: Select all

$("#products").on("click", "a:not(.navtab, #)", function (e) {
    $("#products").load($(this).attr("href"));
    e.preventDefault();
});

Newbie

Posts

Joined
Tue Sep 29, 2015 7:08 am

Post by straightlight » Thu Oct 01, 2015 11:08 am

Technically, you did added this line:

Code: Select all

$("#products").load($(this).attr("href"));
to your code which my example post above demonstrates. Glad you found the answer to your own discovery. :)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by WintersWolf » Thu Oct 01, 2015 11:51 am

straightlight wrote:Technically, you did added this line:

Code: Select all

$("#products").load($(this).attr("href"));
to your code which my example post above demonstrates. Glad you found the answer to your own discovery. :)
Ah yeah, thanks for giving me a nudge in the right direction. Not sure I would of figured it out otherwise! :P

Newbie

Posts

Joined
Tue Sep 29, 2015 7:08 am
Who is online

Users browsing this forum: No registered users and 179 guests