HTML 5 multiple input file, pre loader with delete button - php

Hi could anyone help me
got this form that will render image when I select image, I would like to have a delete button each image just in case wrong image is selected.
got no idea how to do it.
any help, comments, links, suggestion will do. Thanks in advance.
this is my DEMO
//I just copy paste the code inside my demo.

Just clear the content inside #images_preview.
function clearContent()
{
document.getElementById('images_preview').innerHTML="";
}
Edited
Add below code just after you render the image (after document.getElementById('images_preview').appendChild(thumb);)
var element = document.createElement("input");
element.setAttribute("type", "button");
element.setAttribute("value", "clear");
element.addEventListener('click', clearContent, false);
document.getElementById('images_preview').appendChild(element);

In this code if you click the image a confirm box will ask you if you want to delete the image.
and removes it from DOM if you accept.
copy the addEventListener between the two lines of //your code
thumb.setAttribute('src',e.target.result);// your code
thumb.addEventListener('click',function(){
if(confirm('delete?')){
this.parentNode.removeChild(this)
}
},false);
document.getElementById('images_preview').appendChild(thumb); // your code
if you don't need to select the image for other purposes this is prolly the fastest way.
you also interact directly with the image with (this);
to create a nice button effect i would just add css style on hover.
#images_preview>img:hover:after{
//here u add a nice delete icon
}
if you need more buttons and the possibility to select each image i would put the image as background in a left floating div and inside the div put the different buttons you need.

Related

Expanding / Collapsing divs

I have multiple expanding / collapsing boxes on a single page being generated by PHP / MySQL.
Problem is, when I click on one link to expand a box, it expands all the boxes.
I thought about appending the post ID at the end of the class (<div class="postreplycontainer-POST_ID">) but I am not sure if that will work since I'd have to figure out a way to change the jQuery.
Here's a working example: http://jsfiddle.net/Draven/kUhkP/35/
Keep in mind, I can't manually code in each box because I am pulling the content from the database.
EDIT: Maybe somebody can help me with an additional problem.
I want to focus the textarea box when I expand the <div>. I tried using the same trick as before (using .closest but that didn't work).
Here's the example: http://jsfiddle.net/Draven/kUhkP/53/
This example will always focus the first <textarea>.
Here's the FIDDLE
$("a.postreply").click(function () {
$(this).closest('.blog-container')
.find('.postreplycontainer').slideToggle("fast");
});
If you call $("div.postreplycontainer") you will access all divs, if the div is always after a table you can use
$("a.postreply").click(function() {
$(this).parents('table').next().slideToggle("fast");
});
to slide that div http://jsfiddle.net/kUhkP/39/
I think this should be ok for your problem.
$("a.postreply").click(function () {
$(this).closest('.blog-table').next().slideToggle("fast");
});

Jquery menu color change with PHP in it

i wanna apply a affect where my links gets a new color each time i press them... This i believe can be done with a jquery function, however my link are not linked to anything just som PHP so I cant make it work but here is what i wanna do:
Make this: http://jsfiddle.net/wD6C6/
Like this: http://jsfiddle.net/cnMdb/31/
Each time i press the links, they change color to for example blue.
Hope u guys can help me with this tricky one because my links are to some php and not just some # :)
You should add an onclick event to the links, to call a javascript function to change the background color of the link, and a target="_blank", to open the link in a new tab, so that a user can see the changed background color of the clicked link.
Or you can call the php pages using Ajax (I guess you meant this by saying "my links are to some php and not just some #"), and load the responseText to a part of the current page, so that the difference you make in the general design can be seen.
But if it is not the answer you seek for, then your question really needs some more explanation.
Not sure that I've understood your problem but...
Based on:
<div id="foo">
Click
Click
</div>
And whether the links point to php or are created by php should make do difference, you can do:
$(function(){
$("#foo a").click(function(){
var r=Math.floor(Math.random()*256-1);
var g=Math.floor(Math.random()*256-1);
var b=Math.floor(Math.random()*256-1);
rgb = "rgb(" + [r,b,g].toString() + ")";
$(this).css("color", rgb);
});
});
Here's a fiddleto play with.

How do I change this show/hide DIV code?

I am using this show/hide DIV code in my project: http://papermashup.com/demos/jquery-show-hide-plugin/
Currently, after you click VIEW, the div appears and the words VIEW become CLOSE, which you then hit to close the div. Is there anyway we could move the CLOSE so that it comes up inside the DIV that appears?
I'm new at this and I've been trying all night and I can't get it to work. Any help is appreciated.
With the append() function you can insert code into a certain div.
Try something like
$("#slidingDiv_2").append("<a href='#' class='show_hide' rel='#slidingDiv_2'>Close</a>");
If you want to leave that showHide.js alone, there is a simple solution.
1) Create the "Close" text in the div that appears
2) Give it the property so that when clicked, it executes a .slideUp() function that accomplishes the exact same thing as the other "Close" text in the sample page.
slideUp()

Use Jquery to prevent page reloading pressing anchor

I am trying to use the jquery to Prevent page realoading. I have the whole code php done... and is functional. if you can please go to http://www.jonathansconstruction.com/gallery3.php and click on the different gallery SUbmenus for category View All, Kitchen etc... i'm using get for variables. However, I would like to use a jquery to process the php so i dont have to include it into the gallery.php and also, to prevent page reloading because it brings the page back up and that could be confusing. Any hlep willl be greatly appreciated THanks
UPDATE, Thanks for everyone that helped:
SO far i made an advance on the website, Corrected URL was edited on top of the post
Everything is working smoothly on the effects of quicksand.. HOwever, Lytebox Doesn't Load when a quicksand effect is placed. , at the beginning it loads just fine, but right after pressing one of the menus for the quicksand effect. It stops working. Also, I want to style my menu buttons as is in http://www.jonathansconstruction.com/gallery.php. I see jquery doesnt add and witht the sample I downloaded. and also the that says "gallery Pictures" dissapears ont he quicksand demo.
Any Help is appreciated. Below is the script.js code I have modified so far
$(document).ready(function(){
var items = $('.photo_show figure'),
itemsByTags = {};
// Looping though all the li items:
items.each(function(i){
var elem = $(this),
tags = elem.data('tags').split(',');
// Adding a data-id attribute. Required by the Quicksand plugin:
elem.attr('data-id',i);
$.each(tags,function(key,value){
// Removing extra whitespace:
value = $.trim(value);
if(!(value in itemsByTags)){
// Create an empty array to hold this item:
itemsByTags[value] = [];
}
// Each item is added to one array per tag:
itemsByTags[value].push(elem);
});
});
// Creating the "Everything" option in the menu:
createList('View All',items);
// Looping though the arrays in itemsByTags:
$.each(itemsByTags,function(k,v){
createList(k,v);
});
$('#gallery_menu nav a').live('click',function(e){
var link = $(this);
link.addClass('current').siblings().removeClass('current');
// Using the Quicksand plugin to animate the li items.
// It uses data('list') defined by our createList function:
$('.photo_show').quicksand(link.data('list').find('figure'), {adjustHeight: 'dynamic'} );
e.preventDefault();
});
$('#gallery_menu nav a:first').click();
function createList(text,items){
// This is a helper function that takes the
// text of a menu button and array of li items
// Creating an empty unordered list:
var ul = $('<ul>',{'class':'hidden'});
$.each(items,function(){
// Creating a copy of each li item
// and adding it to the list:
$(this).clone().appendTo(ul);
});
ul.appendTo('.photo_show');
// Creating a menu item. The unordered list is added
// as a data parameter (available via .data('list'):
var a = $('<a>',{
html: text,
href:'#',
data: {list:ul}
}).appendTo('#gallery_menu nav');
}
});
ANOTHER EDIT :
All Looking good So far Fixed Lot of problems, However, for some reason, the span I had on teh static html dissapears from display and even html code when loading jquery quicksand code..?? Here is the code i have on the html part of the website that Does Not appear on the live website for some reason.
<div id="portfolio">
<div class="photo_show"><span>Gallery Pictures</span>
the span part doesnt appear, dont know why
I had the TOp Part Resolvd. just moved the on top of photo_show div and edited positioning... HOPEFULLY Last Edit
the jquery for quicksand made my calendar dissapear, checked and yes it was some jquery conflict but dont know what can be causing it.. also the form validation not working as well ... any help is appreciated!
I visited your webpage link after correcting a typo in the URL for word construction.
I also see the problem that the page reloads when clicking on a sorting filter such as View All, Kitchen, and Miscellaneous which is what you want to prevent.
Unfortunately, those buttons are using URL Links asking to reload the webpage with a filtered option via query string. Nothing can be done for that method of filtering, your just going to reload the webpage since filtering is done on page load.
Perhaps this DEMO shows what you want to accomplish since it does not reload the webpage. That demo has markup that is easy to create and maintain which is build using the Quicksand jQuery Plugin. The tutorial for that demo is accessed using the link at the bottom right, but looking at the source HTML file shows how simple it is.
I made a downloadable demo using both Quicksand and Shadowbox, a lightbox alternative HERE, which might interest you since your webpage is linking the filtered icon results to a lightbox alternative named Lytebox.
Since your edit reflects your interest in Lytebox, the following markup will reinitialize that lightbox alternative after a filtering event has occurred with Quicksand. Update your script.js file accordingly.
$('.photo_show').quicksand(link.data('list').find('figure'), function(){
adjustHeight = 'dynamic';
initLytebox();
});
I also made a correction to your existing adjustHeight since it was using a semicolon instead of an equal sign, but the correct location and use of that is for something unrelated.
The reason that you are not seeing the bullets is because your not using ul/li tags that the demo is using.

PHP: Don't load images until div is expanded?

On my site, I have an updates section, which groups updates (galleries) into their own div. Each div is loaded hidden. They choose a section, and it expands to show the new galleries.
That all works fine. However, it loads all the images on the page load, which causes the hour glass to linger longer than I like. Is there any way to make an image load after a div is made visible?
Edit:
Went with:
$(function() {
$('.collapse img').attr('src', function(index, src) {
return this.getAttribute('data-src');
});
});
collapse is the div name that has the images in it. How can this be changed to only change the images in that current div? All the collapsed divs have the same name. However, when expanded, I want it to load only the images in that one div. Right now it loads all the images in all the collapsed div once I expand one of them.
Your divs should not contain the images at startup. You can load the images via JavaScript if a user expands your div.
Example:
function expandDiv(idOfDivElement) {
divObj = document.getElementById(idOfDivElement);
var imageObj = document.createElement('img');
imageObj.setAttribute('src', 'path/example_image.jpg');
divObj.appendChild(imageObj);
// your expand div code here
}
You could advance this function and add a second parameter for the image url. Or a array / comma seperated string if you want to load multiple images.
The process of loading images is up to the browser. You should load that content with javascript, like ajax.
You can load the images( within expandable div ) from ajax...
Just make the div visible, and then call ajax to get the images. Then use .innerHtml() or if you use jQuery, use .html() to put the images in the expanded div.
In this case you have to build the html in ajax page. It will just add the html to the eexpanded div.
This way loads the page much faster.
Please give feedback.

Categories