How do I run the script after loading the page

Asked

Viewed 1,359 times

1

I have a question about framework7, how do I run the scripts after dynamically loaded the page, example:

mainView.router.loadPage("pagina.html)


[script que registram eventos nos botoes da pagina acima]

$("#capturarFoto").unbind().bind("click",function () {
    navigator.camera.getPicture(onSuccessCapturaImagem, onFailCapturaImagem, 
 {
        quality: 50,
        correctOrientation: true,
        encodingType: navigator.camera.EncodingType.JPEG,
        destinationType: navigator.camera.DestinationType.FILE_URI
    });
});

$("#procurarFoto").unbind().bind("click",function () {
    navigator.camera.getPicture(onSuccessCapturaImagem, onFailCapturaImagem,
        {
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
            encodingType: navigator.camera.EncodingType.JPEG,
            correctOrientation: true
        }
    );
});

When I do this it does not record the events on the button, someone knows why?

3 answers

4


You can use the event pageInt, link

$(document).on('pageInit', function (e) {
    //as funções de bind
    $("#capturarFoto").unbind().bind()...
});

3

Framework7 itself has a way to perform functions every time you access a page.

app.onPageInit('pagina', function (page) {
  // Sua função...
})

the app is the assignment of framework7, are generally defined as app or MyApp. The name of pagina past in onPageInit is set logo in your file. Ex:

<div class="page" data-page="pagina">

</div>

0

As you are using jQuery/Zepto you can use the delegation of events and instead of executing at all times it would be enough to do so:

$(document).on("click", "#capturarFoto", function () {
    navigator.camera.getPicture(onSuccessCapturaImagem, onFailCapturaImagem, {
        quality: 50,
        correctOrientation: true,
        encodingType: navigator.camera.EncodingType.JPEG,
        destinationType: navigator.camera.DestinationType.FILE_URI
    });
});

$(document).on("click", "#procurarFoto", function () {
    navigator.camera.getPicture(onSuccessCapturaImagem, onFailCapturaImagem, {
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
        encodingType: navigator.camera.EncodingType.JPEG,
        correctOrientation: true
    });
});

This script should be run only once.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.