I spent half a day writing the content section of my index page of my website but when I tried adding another image to the list of images (There is currently 6) it was a very long and annoying process. (Website: http://rikahiyuka.com)
Is there a way to write the code so that it will be easier to add more buttons (The Images)?
Things that are linked per image listed:
- JQuery
- Div (Link)
The most annoying part is adding to the JQuery.
Is there a better way to write the code for the buttons/images in the content section so it is more compact and easier to edit?
Note: The only section of the index.php file that uses PHP is the footer for the year number.
Instead of doing each image individually, just write one function:
function showhide(shownum) {
$("#Ip1, #Ip2, #Ip3, #Ip4, #Ip5, #Ip6").hide();
$("#Il1, #Il2, #Il3, #Il4, #Il5, #Il6, #IDTopic").hide();
$("#Ip" + shownum + ", #IDTopic, #Il" + shownum).show();
}
Then, if you want to show something, you simply call this function:
showhide(6);
You can put it in your HTML (like so:)
<td>
<img id="Iimg1" class="c-img" src="#" title="Show 1" onclick="showhide(1) />
</td>
or edit your JavaScript:
$("#Iimg1").click(function(){
showhide(1);
});
Replacing 1 with whichever link you want to show. This will make it much quicker and much less annoying because you won't have to list out each element to show and hide. Just call the showhide function :) It basically works by, instead of worrying about hiding everything except the one clicked on, hiding ALL of the links. Then, showing the one requested.
Related
I have done the easy bit and actually added a "Download Image" anchor into the swipebox.js html and formatted it with the CSS to make it play properly with the caption/title.
My specific problem lies in trying to add in a new data attribute containing the naked directory url to the image file and using that info to append it to the href of my created anchor so that I can link to the original size for each image.
Most other JQuery lightboxes can do this, but I stuck myself with using Swipebox because it was easier at the time and now it is returning to bite me in the ass.
You can check out what I have done so far # http://kazenracing.com/?page=1964_Griffith
It is not as pretty as some of my other sites, but people will want the larger images.
You can see I am using timthumb for both the thumbnails and the viewed image, so things will run a bit faster on slower connections and so I do not have to create three separate images "by hand". If I did not care about load times and if my customer did not care about load times I would just have the full image be the viewed one and just use timthumb for the thumbnails alone.
You can also see a data-href attribute ready to go on everything except the videos, which I have already accounted for.
EDIT:
What I tried to do before was add in a function inside the swipebox JS called "setDownload" and tried many ways to pull the data-href into the href of the Download anchor.
The last one I tried that worked but only for the first image was:
setDownload : function () {
$('a[data-href]').each(function() {
$('#swipebox-download').attr('href', $('.swipebox').attr('data-href'));
});
},
I even tried following the logic of setTitle, but that got me nowhere.
EDIT: Okay, now it has become; Who has got a better idea than putting it in the title attribute? Like so:
title="Image Name <a id="swipebox-download" href="path/to/image.jpg">Download</a>"
It does accomplish what I want, but it just seems dirty and wrong.
Well I got off my lazy ass and just figured it out the way I wanted it in the first place.
The big problem I had was wrapping my head around using data attributes.
After I got my head around it I pretty much monkeyed the code in using brutaldesign's already existing code for attributes. I even added an option to change the text of the download link in case it is used for something completely different.
Here is the beef of the code I added:
setDownload : function ( index ) {
var datahref = null;
$( '#swipebox-download' ).empty();
if ( elements[ index ] !== undefined ) {
datahref = elements[ index ].datahref;
}
if ( datahref ) {
$( '#swipebox-download' ).append( plugin.settings.downloadText );
$( '#swipebox-download' ).attr( "href", datahref );
} else {
$( '#swipebox-download' ).hide();
}
},
All the changes are documented here on Github.
Well, I guess, thank you for not answering my question.
I found it way more fulfilling figuring it out on my own than having it handed to me.
Oh, and the forked project page is here, if anyone would like to use it.
I'm creating a slideshow where I'm displaying images based on their urls. I've used PHP to extract the image urls from web pages and I've used JavaScript to display them in a slideshow format. Only thing is, the first picture takes a lot of time to load so I decided to cache the urls by storing them in a text file, but I don't know how to read the urls from the text file in my JavaScript bit?
Could anyone point me in the right direction as to how I should proceed. I couln't find anything helpful online.
My JS code is like this:
<script language="JavaScript1.1">
var slideimages=new Array()
slideshowimages("<?php echo join("\", \"", $image_urls); ?>") <--this is where I was initially echoing the array or image urls from php, but it proves slow for the first few images
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages[i]=new Image()
slideimages[i].src=slideshowimages.arguments[i]
}
}
var slideshowspeed1=30000
var whichimage1=0
function slideit1(){
if (!document.images)
return
document.images.slide1.src=slideimages[whichimage1].src
if (whichimage1<slideimages.length-1)
whichimage1++
else
whichimage1=0
setTimeout("slideit1()",slideshowspeed1)}slideit1()
</script>
Thanks!
Why are you pulling from an external website? You generally will get a lot more speed if you pull them locally. I do believe that once it pulls the images once or so, it will cache for users when it shows up again. What you could do is to use that list you pull and create the images hidden on the page so they load with the page. Then when going through the slideshow, the user should have had time to cache the images and the slideshow will have sped up.
Just make a CSS class known as hidden and visability:hidden;it. Most browsers will still try to load the data.
We're trying to create a trackback system where an outside web publisher can put some html on a page on their website that links back to a specific product page on our site. Let's call it a 'badge' for purposes of this question.
Once they've inserted the badge, we want to identify this, then grab the < h1 > and first < p > as a teaser to comprise a link from our site back to theirs and write all this stuff to our database. Then, our users can see the title and first bit of their page, then decide if they want to see more.
Here's what we've done (not much I'm afraid):
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.gif" style="width:200px;height:100px" />
</a>
We're planning to build an admin page to do the last part of grabbing the < h1> and < p> and posting it to the live database, etc. and we'll figure this out later.
However, the middle step (identifying that this piece of html has been used) we're at a loss.
Is this something we should be doing through a log file....I have no clue even how to begin thinking about it.
A little direction of where to begin working on this problem would be very helpful.
Thanks in advance!!
This is one approach.
You give them HTML which looks something like:
<a href="http://www.mysite.com/abc.html">
<img alt="abc" src="http://www.mysite.com/logo.php" style="width:200px;height:100px" />
</a>
Notice that says logo.php, not logo.gif.
logo.php will live on your server. Its purpose is twofold:
Gather information about the page holding the <img> tag
Load and output logo.gif so the users see the image as expected.
If you embed that html on a webpage somewhere, logo.php will have information about where the request for the image originated. Specifically, $_SERVER['HTTP_REFERER'] will give you the complete URL to the page where the img tag resides. It is then up to you to decide how to process and store that information.
I don't know exactly what you want to do, but a very simplified logo.php would look something like this:
<?php
$url = $_SERVER['HTTP_REFERER'];
// do something with $url...
// it will be something like "http://theirsite.com/wherever/they/pasted/the.html"
// now output the logo image...
header("Content-Type: image/gif");
echo file_get_contents("/path/to/logo.gif");
Keep in mind that every time anyone hits their page with the image tag, logo.php will be run. So don't accidentally create 10000 links back to their site on your site :)
We have several pages generated using PHP on our website with the following titles (for example):
http://www.mysite.com/project/category/1
http://www.mysite.com/project/category/2
http://www.mysite.com/project/category/3
Each one is created dynamically with the same page layout with each showing a different database result depending on the predefined conditions.
I would like an image to be displayed at the top of the page for just one of the results, let's say for http://www.mysite.com/project/category/2 - how can I go about this?
The relevant code on our page is this:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));?>
If we go down the if statement route can you show an example of how to display an example image by modifying the above code to get me started?
I would probably make it a property (can be a as simple yes/no) in the database, and use the existing db-result to determine if the category has to display a page. Although this might seem overkill - I'd definitely pick this dynamic solution over a if ($categoryId == 2) { } solution any day. Keeps it dynamic and your code clean and generic.
In the end I opted for an if statement (as found here http://www.tizag.com/phpT/if.php).
The original code above was modified in the following way:
$category=mysql_fetch_array(mysql_query("select * from project_category where project_category_id='".$project_category_id."'"));
if ( $project_category_id == "2" ) {
echo '<img src="http://www.mywebsite.com/image.jpg" width="675" height="75" border="0" />';
}?>
I have google custom search, by default the search box has got background image, I can remove that image, But not able to replace with my image. so Is there a way to do this.
Adding this to my CSS worked for me:
.cse input.gsc-input, input.gsc-input {background-image:none !important;}
Yes! You can do this!
Please find particular id or css for that and then use CSS according to that id or CSS and make sure you add !important at end it will works for you.
To remove the Google Custom search watermark you need to run a java-query infinite looped code it can't be done by adding a one time running code since every time you will click the search input field he code will rerun from the server side and the watermark will reappear.
the exact code you need to do is listed below but to achieve the desired result you must import Jquery liberary file from link jquery.com download/ and link it to your page
to link it to your page do so.
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
the actual code to hide watermark is.
<script>
$(document).ready(function() {
setInterval( function()
{
$("#gsc-i-id1").css("background-image","none")
},1/*Time*/);
});
</script>
because the ID of the search box is " gsc-i-id1 " so the code will work even if you click and unclick the field.
Please adjust the time of the function to your preference for better performance better keep it less than 100 mile seconds
check the live performance of code by clicking the link below.
http://jsfiddle.net/atulc007/tHQAD/1/
You have to customize GCSE which is given in your code. To explain in detail, you have to select this url in your code - "http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en". Then paste and search this url in your browser. You will get the sorce code of that java script. In that find an image .gif link and replace with your image and save it as .js file and replace the link and upload. Hope you will enjoy :)