Skip to content

Instantly share code, notes, and snippets.

View vseventer's full-sized avatar

Mark van Seventer vseventer

View GitHub Profile
@vseventer
vseventer / gist:3217837
Created July 31, 2012 15:29
Kinvey JavaScript Library: Loading the shim.
...
<script>
window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || document.write('<script src="IndexedDBShim.min.js"><\/script>');
</script>
<script src="//da189i1jfloii.cloudfront.net/js/kinvey-js-0.9.8.min.js"></script>
</body>
</html>
@vseventer
vseventer / gist:3258533
Created August 4, 2012 16:01
Setting the store for a custom collection.
// "items" is the collection name.
var Item = Kinvey.Entity.extend({
constructor: function(attributes) {
Kinvey.Entity.prototype.constructor.call(this, attributes, 'items', {
store: 'offline',
options: { policy: 'cachefirst' }
});
}
});
var Items = Kinvey.Collection.extend({
@vseventer
vseventer / gist:3537784
Created August 30, 2012 19:04
Facebook authentication.
// Initialize the Facebook SDK.
FB.init({
appId: '<your-app-id>',
oauth: true
/* additional properties */
});
// Open login popup.
FB.login(function(response) {
if(response.authResponse) {
@vseventer
vseventer / gist:3537809
Created August 30, 2012 19:05
Facebook authentication with Kinvey.
// Initialize the Facebook SDK.
FB.init({
appId: '<your-app-id>',
oauth: true
/* additional properties */
});
// Open login popup.
FB.login(function(response) {
if(response.authResponse) {
@vseventer
vseventer / callable-object.js
Last active July 10, 2016 10:31
Create a callable object in JavaScript which returns an isolated clone of itself. This is *not* a class, hence using the new keyword has no effect.
// How to define:
// --------------
var callableObjectFn = function() {
// Use CallableObject as name in constructor function, but also when setting property below.
var CallableObject = (function(CallableObject) {
return function() {
return CallableObject();
};
}(callableObjectFn));
CallableObject.property = 'value';
@vseventer
vseventer / gist:8342565
Created January 9, 2014 21:40
Adding the Kinvey AngularJS library to your web app.
<script src="//da189i1jfloii.cloudfront.net/js/kinvey-angular-1.1.4.min.js"></script>
@vseventer
vseventer / gist:8342575
Created January 9, 2014 21:41
Initialize Kinvey for use with AngularJS.
<html ng-app="MyApp">
<script>
var myApp = angular.module('MyApp', ['kinvey']);
myApp.run(function($kinvey) {
$kinvey.init({
appKey : 'App Key',
appSecret : 'App Secret'
});
});
@vseventer
vseventer / gist:8342579
Last active January 2, 2016 18:19
Initialize Kinvey, then bootstrap AngularJS.
<html>
<script>
var myApp = angular.module('MyApp', ['kinvey']);
var $injector = angular.injector(['ng', 'kinvey']);
$injector.invoke(['$kinvey', function($kinvey) {
$kinvey.init({
appKey : 'App Key',
appSecret : 'App Secret'
@vseventer
vseventer / gist:8342583
Last active January 2, 2016 18:19
The old way of defining an AngularJS controller which uses $kinvey. Note $scope.$apply() is required.
app.controller('DataCtrl', ['$scope', '$kinvey', function($scope, $kinvey) {
$kinvey.DataStore.get('collection-name', 'entity-id').then(function(entity) {
$scope.entity = entity;
$scope.$apply();
});
}]);
@vseventer
vseventer / gist:8342598
Created January 9, 2014 21:43
The new, easy way of defining an AngularJS controller which uses $kinvey.
app.controller('DataCtrl', ['$scope', '$kinvey', function($scope, $kinvey) {
$kinvey.DataStore.get('collection-name', 'entity-id').then(function(entity) {
$scope.entity = entity;
});
}]);