hrajchert / angular-screenfull

Angular binding to the Screenfull library to allow fullscreen in your app.
http://hrajchert.github.io/angular-screenfull/
MIT License
60 stars 16 forks source link

ngsfToggleFullscreen state doesn't update #4

Closed cdjackson closed 9 years ago

cdjackson commented 9 years ago

After toggling state, the ngsfToggleFullscreen directive doesn't update correctly. By adding a $apply() call inside a timer this is fixed -:

/* global angular */
(function(angular) {
    angular.module('angularScreenfull')
    .directive('ngsfToggleFullscreen', ngsfToggleFullscreenDirective);
    ngsfToggleFullscreenDirective.$inject = ['$timeout'];

    function ngsfToggleFullscreenDirective ($timeout) {
        return {
            restrict: 'A',
            require: '^ngsfFullscreen',
            link: function(scope, elm, attrs, fullScreenCtrl) {
                elm.on('click', function() {
                    fullScreenCtrl.toggleFullscreen();

                    $timeout(scope.$apply(),500);
                });
            }
        };
    }
})(angular);

I'm not sure if the 500ms is needed (although some time is definately required and 100ms didn't work). Maybe it's also possible to get an event that would be more reliable...

hrajchert commented 9 years ago

Thats weird... I will have a look into it, but most probably the error is not in the toggle directive but in the fullscreenchange on the fullscreen.js file.

Can you post in jsfiddle or other similar tool the code that produces the error?

cdjackson commented 9 years ago

Hmmm, well I tried editing one of your examples in plunkr, but I couldn’t get them to work. I initially thought it was because github doesn’t allow linking of files for this purpose, but even after sorting this out it didn’t work… Do you have a working plunkr or fiddle I can mess with?

Thanks.

hrajchert commented 9 years ago

Yes, I should add a mention about that, I think the problem is that plunkr is using an iframe and you cannot access the fullscreen API from there.

Buuuuuut....

If you go here http://hrajchert.github.io/angular-screenfull/#/api, click "edit in plunkr" on the first example and then inside plunkr you click on "Launch the preview in a separate window" then the example works :D

let me know if it works out

cdjackson commented 9 years ago

Yep - it works :)

So, I tried to recreate this, and can’t, so I removed the timeout, and it still works… I might have been a problem with Chrome - it was playing up, and I had to close it down forcefully… Anyway, it looks like there’s no problem, so we can close this…

Thanks for the support, and sorry for the hassle :)

hrajchert commented 9 years ago

Great! there is no hassle, if you run into this again just reopen.

Thanks for contributing