/    Sign up×
Community /Pin to ProfileBookmark

Gallery Change Out

I’m really new to arrays and am looking to keep things efficient and simple (although what I’m asking for is a bit complex). I’ll try and phrase things from my psuedo-newb standpoint.

Thus far, I have this script:

[CODE]function ShowGallery(type, origin) {

if (type == ‘session’) {

var photos = new Array(‘gallery/2007_04_11_photo_small_01.jpg’, ‘gallery/2007_04_11_photo_large_01.jpg’, ‘gallery/2007_04_06_video_small_01.jpg’, ‘gallery/2007_04_06_video_large_01.flv’, ‘gallery/2005_07_12_photo_small_09.jpg’, ‘gallery/2005_07_12_photo_small_08.jpg’, ‘gallery/2005_07_12_photo_small_07.jpg’, ‘gallery/2005_07_12_photo_small_06.jpg’, ‘gallery/2005_07_12_photo_small_05.jpg’, ‘gallery/2005_07_12_photo_small_04.jpg’, ‘gallery/2005_07_12_photo_small_03.jpg’, ‘gallery/2005_07_12_photo_small_02.jpg’, ‘gallery/2005_07_12_photo_small_01.jpg’, ‘gallery/2005_07_12_photo_large_09.jpg’, ‘gallery/2005_07_12_photo_large_08.jpg’, ‘gallery/2005_07_12_photo_large_07.jpg’, ‘gallery/2005_07_12_photo_large_06.jpg’, ‘gallery/2005_07_12_photo_large_05.jpg’, ‘gallery/2005_07_12_photo_large_04.jpg’, ‘gallery/2005_07_12_photo_large_03.jpg’, ‘gallery/2005_07_12_photo_large_02.jpg’, ‘gallery/2005_07_12_photo_large_01.jpg’, ‘gallery/2005_05_01_photo_small_16.jpg’, ‘gallery/2005_05_01_photo_small_15.jpg’, ‘gallery/2005_05_01_photo_small_14.jpg’, ‘gallery/2005_05_01_photo_small_13.jpg’, ‘gallery/2005_05_01_photo_small_12.jpg’, ‘gallery/2005_05_01_photo_small_11.jpg’, ‘gallery/2005_05_01_photo_small_10.jpg’, ‘gallery/2005_05_01_photo_small_09.jpg’, ‘gallery/2005_05_01_photo_small_08.jpg’, ‘gallery/2005_05_01_photo_small_07.jpg’, ‘gallery/2005_05_01_photo_small_06.jpg’, ‘gallery/2005_05_01_photo_small_05.jpg’, ‘gallery/2005_05_01_photo_small_04.jpg’, ‘gallery/2005_05_01_photo_small_03.jpg’, ‘gallery/2005_05_01_photo_small_02.jpg’, ‘gallery/2005_05_01_photo_small_01.jpg’, ‘gallery/2005_05_01_photo_large_16.jpg’, ‘gallery/2005_05_01_photo_large_15.jpg’, ‘gallery/2005_05_01_photo_large_14.jpg’, ‘gallery/2005_05_01_photo_large_13.jpg’, ‘gallery/2005_05_01_photo_large_12.jpg’, ‘gallery/2005_05_01_photo_large_11.jpg’, ‘gallery/2005_05_01_photo_large_10.jpg’, ‘gallery/2005_05_01_photo_large_09.jpg’, ‘gallery/2005_05_01_photo_large_08.jpg’, ‘gallery/2005_05_01_photo_large_07.jpg’, ‘gallery/2005_05_01_photo_large_06.jpg’, ‘gallery/2005_05_01_photo_large_05.jpg’, ‘gallery/2005_05_01_photo_large_04.jpg’, ‘gallery/2005_05_01_photo_large_03.jpg’, ‘gallery/2005_05_01_photo_large_02.jpg’, ‘gallery/2005_05_01_photo_large_01.jpg’, ‘gallery/2003_07_28_photo_small_16.jpg’, ‘gallery/2003_07_28_photo_small_15.jpg’, ‘gallery/2003_07_28_photo_small_14.jpg’, ‘gallery/2003_07_28_photo_small_13.jpg’, ‘gallery/2003_07_28_photo_small_12.jpg’, ‘gallery/2003_07_28_photo_small_11.jpg’, ‘gallery/2003_07_28_photo_small_10.jpg’, ‘gallery/2003_07_28_photo_small_09.jpg’, ‘gallery/2003_07_28_photo_small_08.jpg’, ‘gallery/2003_07_28_photo_small_07.jpg’, ‘gallery/2003_07_28_photo_small_06.jpg’, ‘gallery/2003_07_28_photo_small_05.jpg’, ‘gallery/2003_07_28_photo_small_04.jpg’, ‘gallery/2003_07_28_photo_small_03.jpg’, ‘gallery/2003_07_28_photo_small_02.jpg’, ‘gallery/2003_07_28_photo_small_01.jpg’, ‘gallery/2003_07_28_photo_large_16.jpg’, ‘gallery/2003_07_28_photo_large_15.jpg’, ‘gallery/2003_07_28_photo_large_14.jpg’, ‘gallery/2003_07_28_photo_large_13.jpg’, ‘gallery/2003_07_28_photo_large_12.jpg’, ‘gallery/2003_07_28_photo_large_11.jpg’, ‘gallery/2003_07_28_photo_large_10.jpg’, ‘gallery/2003_07_28_photo_large_09.jpg’, ‘gallery/2003_07_28_photo_large_08.jpg’, ‘gallery/2003_07_28_photo_large_07.jpg’, ‘gallery/2003_07_28_photo_large_06.jpg’, ‘gallery/2003_07_28_photo_large_05.jpg’, ‘gallery/2003_07_28_photo_large_04.jpg’, ‘gallery/2003_07_28_photo_large_03.jpg’, ‘gallery/2003_07_28_photo_large_02.jpg’, ‘gallery/2003_07_28_photo_large_01.jpg’, ‘*’);

}

}
[/CODE]

I have a div full of images and each image, when clicked, runs the function as follows (example):

[CODE]ShowGallery(‘session’, ‘2005_07_12’);[/CODE]

I want this function to find all images in the array with “2005_07_12” in it, as well as the word “small”.

Then I want for each file to be given the following html “casing” like this:

[CODE]<div class=”gallery_option”><div class=”gallery_thumb” style=”background: url(gallery/2005_07_12_photo_small_01.jpg) no-repeat;” onclick=”ShowGallery(‘photo’, ’01’);”></div></div>[/CODE]

Next, they all need to be combined into a single html string to be applied as gallery.innerHTML = the string.

Never done anything like this. Is there a simple method?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @robindean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...