nikola Posted January 4, 2012 Share Posted January 4, 2012 Would it be possible to add another checkbox beside "Link to larger version?" that would call fancybox or some similar script "in "Edit image" modal window that appears after you select your image in "Select image" modal window? It would also need some sort of input field somewhere where you can define what class or rel triggers that script. I want to avoid using bramus cssextras plugin for tinymce... Link to comment Share on other sites More sharing options...
ryan Posted January 4, 2012 Share Posted January 4, 2012 Anything is possible, but not sure I totally understand. What would the additional checkbox be for? What does the cssextras plugin do that you are wanting to duplicate? Link to comment Share on other sites More sharing options...
nikola Posted January 4, 2012 Author Share Posted January 4, 2012 Let's say I'm adding an image, then I set width and height and then I check "Link to larger version?". This way image is opening in normal browser window. I would like to have an extra checkbox, for example "Use Fancybox" and when this is checked it would assign specified class or rel to that image so it can open in Fancybox window or with similar script. An input field would exist somewhere where I would specify class or rel applied to an image. Thx Ryan. Link to comment Share on other sites More sharing options...
ryan Posted January 4, 2012 Share Posted January 4, 2012 The "link to larger version" is actually intended to be without implementation so that you can implement it with a lightbox of your choice. Rarely in my sites do I actually leave it as literally linking to the larger version. Instead, I'll usually put in some javascript like this: $(document).ready(function() { $("#bodycopy a:has(img)").fancybox(); }); Or if you want to add some attributes and do it that way: $(document).ready(function() { $("#bodycopy a:has(img)").addClass('lightbox').attr('rel', 'gallery'); $("a.lightbox").fancybox(); }); Now if you want to be able to support more then one way of linking to a large image (i.e. have one link to the larger version and another opening in a lightbox) then you'd probably need to take another approach (or maybe make a module). Let me know if that is your need. 2 Link to comment Share on other sites More sharing options...
nikola Posted January 4, 2012 Author Share Posted January 4, 2012 I actually thought about that approach, but it would apply fancybox or similar effect to all image links throughout the content area (bodycopy). For instance, if I have an image linking to some url, page or file, the effect would be applied nevertheless to that link. Link to comment Share on other sites More sharing options...
ryan Posted January 4, 2012 Share Posted January 4, 2012 That's not a problem, you can just tell jQuery to only target <a> links that have an href pointing to your site's files. Something like this should work, though could be taken further too. $(document).ready(function() { $("#bodycopy a[href*=site/assets/]:has(img)").fancybox(); }); Link to comment Share on other sites More sharing options...
nikola Posted January 5, 2012 Author Share Posted January 5, 2012 Thanks Ryan, that should work for me. Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 The "link to larger version" is actually intended to be without implementation so that you can implement it with a lightbox of your choice. Rarely in my sites do I actually leave it as literally linking to the larger version. Instead, I'll usually put in some javascript like this: $(document).ready(function() { $("#bodycopy a:has(img)").fancybox(); }); Or if you want to add some attributes and do it that way: $(document).ready(function() { $("#bodycopy a:has(img)").addClass('lightbox').attr('rel', 'gallery'); $("a.lightbox").fancybox(); }); Now if you want to be able to support more then one way of linking to a large image (i.e. have one link to the larger version and another opening in a lightbox) then you'd probably need to take another approach (or maybe make a module). Let me know if that is your need. Thanks Ryan, this really helped me out, is there anything your not good at?! Is there anyway of passing a php variable to set the "rel" attribute. Ie: the $page->name and maybe the image description for the a "title" tag? Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 Is there anyway of passing a php variable to set the "rel" attribute. Ie: the $page->name? You can put this on the header of the page: <?php echo "<script><!-- define variables for JS --> var pageName = {$page->name}, pageTitle = {$page->title}, pageWhatever = {$page->whatever}; </script>"; ?> and on your script: $("#bodycopy a:has(img)").addClass('lightbox').attr('rel', pageName); Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 Hi thanks for that Diogo, unfortunately it's not picking up the variable. I put the first bit of code in my head tags is that the right place? Thanks Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 sorry, I should have mentioned that you have to put it before calling the javascript file: <?php echo "<script><!-- define variables for JS --> var pageName = '{$page->name}', pageTitle = '{$page->title}', pageWhatever = '{$page->whatever}'; </script>"; ?> <script type="text/javascript" src="<?php echo $config->urls->templates?>scripts/main.js"></script> edit: corrected the order and added quotation marks Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 Sorry Diogo, in your example there you put it after? I've tried putting it before and I no longer get a pageName undefined error in the console but the rel isn't getting passed to the link? Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 It's before, already updated the post... Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 It's before, already updated the post... Thanks I've no idea why this won't work though. Code in full: Within <head> tag: <?php echo "<script><!-- define variables for JS --> var pageName = {$page->name} </script>"; ?> <script type="text/javascript" src="<?php echo $config->urls->templates?>scripts/scripts.js"></script> In scripts.js: $(document).ready(function() { $(".body_copy a:has(img)").addClass('fancy').attr({ rel: pageName, title: pageName }); }); I also tried a single attribute but the values don't get passed to the anchor tag. Strange Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 Ok, spotted! I forgot the quotation marks on javascript. Already corrected on the above code. 1 Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 Ok, spotted! I forgot the quotation marks on javascript. Already corrected on the above code. Perfect! Thanks, think the first var still needs the quotes, thanks for your assistance as ever Mr Diogo Sorry to bug you.... Any idea how to pass the images description field to the a title attr? These are images from within the body... I have this currently on the scripts page $(document).ready(function() { var title = $(".body_copy a:has(img) img").attr("alt"); $(".body_copy a:has(img)").addClass('fancy').attr({ rel: pageName, title: title }); }); Which sort of works but it always passes the first image description to each anchor tag... Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 Yep, one was still missing Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 This seems to have done the trick $(document).ready(function() { $(".body_copy a:has(img)").addClass('fancy').attr({ rel: pageName, title: "title" }); $(".body_copy a:has(img)").attr("title", function() { return $(this).find("img").attr("alt"); }); }); I'm sure it can be shortened and prettified but it's seems to be working - I really need to invest some time in learning jQuery! Based on here: http://stackoverflow...following-eleme Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 You are selecting twice the same element, and defining twice the same attribute. Not very efficient... Try this: $(document).ready(function() { $(".body_copy a:has(img)").addClass('fancy').attr({ rel: pageName, title: function() { return $(this).find("img").attr("alt"); } }); }); note: I didn't test it Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 You are selecting twice the same element, and defining twice the same attribute. Not very efficient... Try this: $(document).ready(function() { $(".body_copy a:has(img)").addClass('fancy').attr({ rel: pageName, title: function() { return $(this).find("img").attr("alt"); } }); note: I didn't test it Thanks that's better though think it's lacking a }); Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 You're right, I didn't close the $(document).ready(function() { I'll do it now Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now