Created
June 26, 2013 13:46
-
-
Save jonathan-fielding/5867484 to your computer and use it in GitHub Desktop.
JS State Manager (none library based)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stateManager = (function () { | |
var state = null; | |
var setState = function () { | |
if ($('body').width() < 768) { | |
if (state !== "mobile") { | |
state = "mobile"; | |
displayMobile(); | |
} | |
} | |
else { | |
if (state !== "desktop") { | |
state = "desktop"; | |
displayDesktop(); | |
} | |
} | |
}; | |
var resizePage = function () { | |
setState(); | |
if (state === "mobile") { | |
resizeMobile(); | |
} | |
else { | |
resizeDesktop(); | |
} | |
}; | |
var displayMobile = function () { | |
//When mobile state is shown this fires | |
}; | |
var displayDesktop = function () { | |
//When desktop state is shown this fires | |
}; | |
var resizeMobile = function () { | |
//When mobile state is resized this fires | |
}; | |
var resizeDesktop = function () { | |
//When desktop state is resized this fires | |
}; | |
return { | |
init: function () { | |
setState(); | |
$(window).on('resize', resizePage); | |
}, | |
getState: function () { | |
return state; | |
} | |
}; | |
} ()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment