Search code examples
javascriptjqueryzkgalleria

JavaScript JQuery Galleria.io Zk Framework getSelectedImage() or getIndex


i have implement a Image Gallery using javascript,JQuery,Galleria.io library everything works as expected we are using Zk Framework my question is

how can i get the Selected image or selected index to able to delete it in both image gallery and the dataBase here is what i have try so far.

this is how i have created the gallery

<script type="text/javascript">Galleria.loadTheme('gallery/galleria.classic.min.js');Galleria.run('#galleria');</script>

when zk clicked a button i am calling a javascript snippet like this

var index = $('#galleria').getIndex();alert(index);

but throws..

Object #<Object> has no method 'getIndex' (TypeError)

i think knowing the index should be enough for me delete the image i am trying to call this method

.getIndex()
returns Number
Returns the current index.

See API


Solution

  • The getIndex() method(as well as all other Galleria methods) is stored in Galleria instance. So you should obtain the instance first, and then call the method.
    The instance stored in jQuery data, associated with gallery element.

    var index = $('#galleria').data('galleria').getIndex();
    alert(index);