Question: I have a function that I need to run in order to re-position my slider.

This has to happen when the window is resized or if the device orientation is changed. It can't fire twice as it causes all sorts of issues.

The issue I have is with the following code resize & orientation both trigger on orientation change so I need a way to detect one and not use the other but i'm just unsure on how to really go about it.

```js
function cssliderOrientation(trigger){

        setTimeout(function() {

        $( "<p>" + trigger + "</p>" ).appendTo( ".container" );

        }, 1000);
}

$( window ).on( "orientationchange", function() {
        cssliderOrientation('orientationChange');
    });

    $(window).resize(function() {
        cssliderOrientation('Resize');
    });
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container"></div>
```

Answer: 
The double firing of the function happens when both statements are true. 

* You change the orientation.
* The event "orientationchange" gets triggered.
* The event "resize" gets triggered

Orientation changing causes the screen to resize already and therefore triggering the event. So the first event can be left out in this case.
You could use a variabale to check if the function has already been called. If it has the `cssliderOrientation` function call will return. And after the timeout function call you just set the variable back to false. 

```
var onSliderOrientation = false;
function cssliderOrientation(trigger){
       if(onSliderOrientation){
           return;
       }

       onSliderOrientation = true;

       setTimeout(function() {

          $( "<p>" + trigger + "</p>" ).appendTo( ".container" );
          onSliderOrientation = false;

        }, 1000);
}

$( window ).on( "orientationchange", function() {
        cssliderOrientation('orientationChange');
    });

    $(window).resize(function() {
        cssliderOrientation('Resize');
    });

```

The issue with this is that the second time `cssliderOrientation` is called, if the call happens after the timeout of the first call expired, it will be called twice either way. In your case it may not be a problem but just be aware that I am not a big fan of this kind of solutions.