Question

I am using the galleria script for my website, with the facebook mod. I want to modify it a bit, so the albumid that should be showing, is the ID given in query string.

My code is:

Galleria.run('#galleria', { facebook: 'album:000000000', width: 745, height: 550, lightbox: true});

Where i want album:000000000, to be album:-querystring albumid-

For example, my page is album.php?albumid=123456, i want the code to be:

Galleria.run('#galleria', { facebook: 'album:123456', width: 745, height: 550, lightbox: true});

Could someone help me with a certain code?

Was it helpful?

Solution

I can't claim too much familiarity with Galleria, but I have used the JS function below to grab query string variable values.

function parseURLParams(name, locat) {
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(locat);
        if (results) {
            return results[1] || "";
        } else {
            return "";
        }
}

So if you include the above function in your project, you could potentially set up your code like so:

Galleria.run('#galleria', { facebook: 'album:' + parseURLParams("albumid", window.location.href), width: 745, height: 550, lightbox: true});

Hope it helps!

OTHER TIPS

<script type="text/javascript">
    $(document).ready(function () {
        $('input.letter').click(function () {
            //0- prepare values
            var qsTargeted = 'letter=' + this.value; //"letter=A";
            var windowUrl = '';
            var qskey = qsTargeted.split('=')[0];
            var qsvalue = qsTargeted.split('=')[1];
            //1- get row url
            var originalURL = window.location.href;
            //2- get query string part, and url
            if (originalURL.split('?').length > 1) //qs is exists
            {
                windowUrl = originalURL.split('?')[0];
                var qs = originalURL.split('?')[1];
                //3- get list of query strings
                var qsArray = qs.split('&');
                var flag = false;
                //4- try to find query string key
                for (var i = 0; i < qsArray.length; i++) {
                    if (qsArray[i].split('=').length > 0) {
                        if (qskey == qsArray[i].split('=')[0]) {
                            //exists key
                            qsArray[i] = qskey + '=' + qsvalue;
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag)//   //5- if exists modify,else add
                {
                    qsArray.push(qsTargeted);
                }
                var finalQs = qsArray.join('&');
                //6- prepare final url
                window.location = windowUrl + '?' + finalQs;
            }
            else {
                //6- prepare final url
                //add query string
                window.location = originalURL + '?' + qsTargeted;
            }
        })
    });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top