• 0

WordPress/jQuery fade out link


Question

http://www.romabio.com/products/biocalce-a/

 

Above is a link to the example. There are two links one is MSDS and the other is TDS. Those link are PDF documents so that the painters/user can get to keep it if they don't want to go back to the website. I have it working fine in WordPress. The only problem is that my boss does not have all the files yet to be uploaded. I want to fade out or hide the link so that users can't link on it or show that it's not available at this time. I know it can be down with jQuery which see if there is an PDF file to show it and if not then hide it. Can anyone help me with it. Thanks!

Link to comment
https://www.neowin.net/forum/topic/1167549-wordpressjquery-fade-out-link/
Share on other sites

14 answers to this question

Recommended Posts

  • 0

She this work?

$(".download-Wrap a").each(function(){
    var match = this.href.match(/\.([a-zA-Z0-9]{2,4})([#;\?]|$)/);
    console.log(match);
    if(match){
        $(this).addClass("linkIcon" + match[1]);
    }
});
  • 0

With PHP you could read all of the filenames from a directory, then compare them to an array of files you've saved (the final, total accumulation of files). If the PDF has yet to be uploaded, you could add a class and then style that with CSS.

 

In the browser, using buttons, you can just do this:

$('#linkId')
    .addClass('deactivated')
    .click(function(e){
        if($(this).hasClass('deactivated')){
            e.preventDefault();
        }
    });
  • 0
  On 29/07/2013 at 19:23, threetonesun said:

 

With PHP you could read all of the filenames from a directory, then compare them to an array of files you've saved (the final, total accumulation of files). If the PDF has yet to be uploaded, you could add a class and then style that with CSS.

 

In the browser, using buttons, you can just do this:

$('#linkId')
    .addClass('deactivated')
    .click(function(e){
        if($(this).hasClass('deactivated')){
            e.preventDefault();
        }
    });

 

Not really good at jQuery coding yet. Is there a way to tell jQuery that when it does not see an PDF file to add a class?

  • 0
  On 29/07/2013 at 19:54, ACTIONpack said:

Not really good at jQuery coding yet. Is there a way to tell jQuery that when it does not see an PDF file to add a class?

 

Not easily, no. You're asking it to load the page, load the script, then check for a file on the server, then report back and modify a page element. It can be done (via ajax, in jQuery), but whether or not it's worth it when you already know if the file exists or doesn't exist is a different question.

  • 0
  On 29/07/2013 at 19:58, threetonesun said:

Not easily, no. You're asking it to load the page, load the script, then check for a file on the server, then report back and modify a page element. It can be done (via ajax, in jQuery), but whether or not it's worth it when you already know if the file exists or doesn't exist is a different question.

 

http://stackoverflow.com/questions/15879130/jquery-add-class-to-href-if-link-contains-specific-text

 

The link above is something I want it to do but instead of adding a class when seeing the .pd. I want to add a class when no .pdf file is there.

  • 0
  On 29/07/2013 at 20:01, ACTIONpack said:

http://stackoverflow.com/questions/15879130/jquery-add-class-to-href-if-link-contains-specific-text

 

The link above is something I want it to do but instead of adding a class when seeing the .pd. I want to add a class when no .pdf file is there.

 

Well, you can have a link that points nowhere (a href="" or a href="placeholder") then check for an empty string, and for any link that matches, add a class.

  • 0
  On 29/07/2013 at 20:09, threetonesun said:

Well, you can have a link that points nowhere (a href="" or a href="placeholder") then check for an empty string, and for any link that matches, add a class.

 

Would it be easier to add a class when it see a PDF and I can't make it visible instead of when there is no PDF to add a Class?

  • 0
  On 29/07/2013 at 20:23, ACTIONpack said:

Would it be easier to add a class when it see a PDF and I can't make it visible instead of when there is no PDF to add a Class?

 

No :laugh:

 

You're talking about two situations here, I think. If you have something like this:

<a href="/pdfs/pdfthatexists.pdf">Click here for PDF!</a>
<a href="nowhere">Don't click here, there's no PDF!</a>

Then it's relatively trivial to add a class to any of these links, just by selecting through the href attribute. If you have this:

<a href="/pdfs/pdfthatexists1.pdf">Click here for PDF!</a>

<a href="/pdfs/pdfthatexists2.pdf">This PDF may or may not be on the server!</a>
<a href="/pdfs/pdfthatexists3.pdf">This PDF may or may not be on the server!</a>

Then it would be easier to check for the file and add a class via PHP. Otherwise you have to resort to ajax/http requests in javascript.

 

It's possible we're misunderstanding each other, though, just let me know. :D

  • 0
  On 29/07/2013 at 20:30, threetonesun said:

No :laugh:

 

You're talking about two situations here, I think. If you have something like this:

<a href="/pdfs/pdfthatexists.pdf">Click here for PDF!</a>
<a href="nowhere">Don't click here, there's no PDF!</a>

Then it's relatively trivial to add a class to any of these links, just by selecting through the href attribute. If you have this:

<a href="/pdfs/pdfthatexists1.pdf">Click here for PDF!</a>

<a href="/pdfs/pdfthatexists2.pdf">This PDF may or may not be on the server!</a>
<a href="/pdfs/pdfthatexists3.pdf">This PDF may or may not be on the server!</a>

Then it would be easier to check for the file and add a class via PHP. Otherwise you have to resort to ajax/http requests in javascript.

 

It's possible we're misunderstanding each other, though, just let me know. :D

 

Yea, forget about me using PHP/WordPress. Lets say that I'm doing it in HTML, CSS3 and jQuery only. Is there a way that I can tell jQuery if there is a PDF file or any general file on the link to add a class to it?

  • 0
  On 29/07/2013 at 20:49, ACTIONpack said:

Yea, forget about me using PHP/WordPress. Lets say that I'm doing it in HTML, CSS3 and jQuery only. Is there a way that I can tell jQuery if there is a PDF file or any general file on the link to add a class to it?

 

Like this: http://jsfiddle.net/pNRfk/

 

Again, if you need to create the links first, and then check if the file actually exists on the server only using jQuery, it gets trickier.

  • 0

This might be clearer: http://jsfiddle.net/pNRfk/3/

var $links = $('a');
$links.each(function(){
    var link = $(this).attr('href');
    var css = link.indexOf('.pdf') > -1 ? 'active' : 'notActive';
    $(this).children('button').addClass(css);
});

$('.notActive').on('click',function(e){
    e.preventDefault();
})
  • 0

The last post I provided jQuery code and it does work find. I just have to make the class look non active and when it does see a .pdf file, I just active the linkIconpdf. Have to add the pdf to the end of linIcon if I'm going to get the code to work.

 

Thanks everyone for helping me out.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • DayZ is getting a desert map with new Badlands expansion, set to be its biggest yet by Pulasthi Ariyasinghe It was only last year that developer Bohemia Interactive brought a snow-covered map to the multiplayer survival game DayZ with the Frostline expansion. The long-time supported, post-apocalyptic title is now aiming to take players to a region a little hotter with the next expansion. Touting extreme heat and war-scarred landscapes, the Badlands expansion is set to launch next year. Watch the announcement trailer above. Landing as the third expansion for DayZ, Badlands is set to deliver the biggest map ever developed for the hardcore survival experience. "With an enormous size of 267 km², DayZ Badlands introduces the largest official map in the game’s history," says the studio, describing the incoming content and setting. "Set west of Chernarus and bordering Takistan’s frontier, the terrain offers a desolate blend of cracked soil, sand-swept plains, and mountainous divides. Here, every inch of land tells a story of failed invasions, abandoned cities, and the silence that followed decades of war." The desert environment of the new Nasdara province brings its own survival elements for players to endure. This includes droughts and hydration management, as well as encounters with new types of infected zombies. New loot types, cosmetic items, and region-specific weapons are being added as a part of the expansion, too. As usual, with all the tools and environments in place, it will be the players who make up their own stories and adventures in the multiplayer title. Bohemia Interactive did not announce a release date for the DayZ Badlands expansion today, but it did attach a broad 2026 launch window to it. The expansion is being developed for PC, Xbox Series X|S, and PlayStation 5. While pricing information has not arrived yet either, judging by previous expansions, it may cost around $30 at launch.
    • NetLimiter 5.3.25.0 by Razvan Serea NetLimiter is an ultimate internet traffic control and monitoring tool designed for Windows. You can use NetLimiter to set download/upload transfer rate limits for applications or even single connection and monitor their internet traffic. Along with this unique feature, Netlimiter offers comprehensive set of internet statistical tools. It includes real-time traffic measurement and long-term per-application internet traffic statistics. Main NetLimiter features: NetLimiter shows list of all applications communicating over network it's connections, transfer rates and more. You can use NetLimiter to set download or upload transfer rate limits for applications, connections or groups of them. With limits you can easily manage your internet connection's bandwidth (bandwidth shaper or bandwidth controller) Statistical tool lets you to track your internet traffic history since you've installed NetLimiter. Additional network information: NetLimiter provides you with and additional information like WHOIS, traceroute etc. Rule scheduler, Remote administration, Connection blocker, Running as WinNT service, User rights, Chart, Advanced Rule editor and scheduler, Zone based traffic management... NetLimiter 5.3.25.0 changelog: Massive translation update. Many new text translated to all supported languages. (If you find any translation problem, please contact us at support@netlimiter.com) More robust and reliable domain name filtering system, especially when using domain names without wildcards. More info about filters. Many minor internal fixes. Download: NetLimiter 5.3.25.0 | 10.3 MB (Shareware) View: NetLimiter Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Lol, that's where it's made and hosted, how else were they expecting the "cloud hosted" model to work? Alas, guess it's the same rule that every other service provider in the EU must follow; all data processing must be handled within EU borders. That's a welcome move for privacy. Deepseek's devs would have to find an EU host if they want to provide the service in the EU.
    • This is why the Year of the Linux Desktop has become vaporware imo
    • Save 76% on this lifetime subscription to SwifDoo PDF editor for Windows by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 76% on a lifetime subscription to SwifDoo PDF. SwifDoo PDF is a comprehensive PDF editor software that serves as the ultimate solution for all your PDF management needs. SwifDoo PDF for Windows comes with various features to help you organize your PDFs and get the most out of them. It provides you with standard editing features, including the ability to split and merge documents, edit their style, cut/insert text, and more. You can also convert to and from various formats, including Word and different image formats. It’s better to spend your time on other meaningful activities instead of frowning at an editable PDF, wondering if there’s something that can make PDF tasks easier. All the PDF tools you need Open/Create/Read PDF: Open/create PDFs from blank pages, images, files, scans, CAD, and HEIC in simple steps. Edit/Annotate PDF: Empower your productivity with edit/annotate PDFs, allowing you to mark up, insert text, highlight, and edit PDFs. Merge/Split PDF: Merge lots of PDF files or images into one file in your wanted order. Split or separate PDF pages into individual PDFs ideally. Compress PDF: Compress a PDF to reduce the file size by your desired compression level and image quality. Convert PDF: Convert and save PDF to Word DOC/DOCX, Excel, PowerPoint, JPG, HEIC, EPUB, CAD, and more formats and vice versa. Remove/ Add Watermark: Add predefined or custom, text or image watermarks to PDFs for protection. Remove watermarks from PDF pages in one click. Encrypt/ Sign PDF: Protect PDFs with passwords from being opened, copied, edited, or printed. Sign PDFs with handwritten or uploaded signatures. Print PDF: Print double-sided PDFs, print a PDF as a booklet or to grayscale and print PDFs with comments. Add Link/ Pages/ Images: Add links to PDFs to quickly access other pages, files or webpages. Add a file or pages to a PDF. Insert and edit images in PDFs. Advanced features Recognize Text in Scanned PDFs: Powerful OCR to recognize and extract text from scanned and image-based PDF documents to make them editable and searchable. Or, convert images and scanned PDFs to editable file formats such as Word using OCR, without losing the original formatting and layout. Batch Process PDFs: Support simultaneously batch converting between PDF to Word, Excel, PowerPoint, TXT, CAD, images, and HTML, and compressing numerous PDFs, while preserving the original formats and layouts without quality loss. Encrypt, split and print PDFs in bulks. Good to know Length of access: Lifetime Redemption deadline: redeem your code within 30 days of purchase Access options: PC (Windows only) Max number of device(s): 1 Only available to NEW users A single license key can be only activated once Version: 2.0.5.9 Updates included A SwifDoo PDF perpetual lifetime license normally costs $129, but you can pick this up for just $29.97 for a limited time - that represents a saving of $99 (76% off). For a full description, spec, and terms, click the link below. Get SwifDoo PDF editor for just $29.97, or learn more Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
  • Recent Achievements

    • Week One Done
      emptyother earned a badge
      Week One Done
    • Week One Done
      DarkWun earned a badge
      Week One Done
    • Very Popular
      valkyr09 earned a badge
      Very Popular
    • Week One Done
      suprememobiles earned a badge
      Week One Done
    • Week One Done
      Marites earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      561
    2. 2
      ATLien_0
      176
    3. 3
      +FloatingFatMan
      169
    4. 4
      Xenon
      124
    5. 5
      Michael Scrip
      118
  • Tell a friend

    Love Neowin? Tell a friend!