Skip to content

Instantly share code, notes, and snippets.

@mikaa123
Created November 19, 2012 09:19
Show Gist options
  • Save mikaa123/4109789 to your computer and use it in GitHub Desktop.
Save mikaa123/4109789 to your computer and use it in GitHub Desktop.
Samsung TV cookie module
// Use this as a black-box module to replace joshlib!utils/cookie when developing with
// Samsung TV.
//
// It returns a function to be called with the following parameters:
// name - The key to store.
// data - The value associated with this key.
//
// NOTE: In order to use, you need to expose <script src='$MANAGER_WIDGET/Common/af/2.0.0/loader.js' type='text/javascript'></script>
// in your index file.
//
// This module will use Samsung's sf.core.localData function.
define([], function(){
return function (name, data) {
if (typeof(sf) === "undefined") {
console.log('sf undefined');
return;
}
if (typeof(sf.core) === "undefined") {
console.log('sf.core undefined');
return;
}
if (typeof(sf.core.localData) === "undefined") {
console.log('sf.core.localData undefined');
return;
}
// At this point, sf.core.localData is available.
//
// Two cases:
// Called with one argument: Retrieve value
// Called with two arguments: Set value
if (arguments.length > 1) {
// Set value
if (typeof(data) === "undefined" || String(data) === "[object Object]") {
console.log('data not settable.');
return;
} else {
console.log('Setting ' + name + ' to ' + data);
sf.core.localData(name, data);
console.log('sf.core.localData("'+name+'") is ' + sf.core.localData(name));
}
} else {
console.log('Getting cookie value: ' + name + ' val: ' + sf.core.localData(name));
// Retrieve value
return sf.core.localData(name);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment