diff --git a/.gitignore b/.gitignore index 4d4b695..2060e58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .DS_Store .gitignore +node_modules diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..5d845fe --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,37 @@ +module.exports = function(grunt) { + + grunt + .initConfig({ + pkg : grunt.file.readJSON('package.json'), + // LINT + jshint : { + options : { + sub : true, // Allow object['member'], and don't insist on object.member + }, + all : ['*.js'] + }, + uglify : { + all : { + files : { + 'dist/openfb.min.js' : ['openfb.js'] + } + } + }, + shell : { + commit_dist : { + command : 'git commit -am "Release" dist/*.js' + } + }, + release : { + options : { + npm: false, + npmtag: false + } + } + }); + grunt.loadNpmTasks('grunt-release'); + grunt.loadNpmTasks('grunt-shell'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.registerTask('default', ['jshint', 'uglify']); +}; diff --git a/dist/openfb.min.js b/dist/openfb.min.js new file mode 100644 index 0000000..3a3db9d --- /dev/null +++ b/dist/openfb.min.js @@ -0,0 +1 @@ +var openFB=function(){function a(a){if(!a.appId)throw"appId parameter not set in init()";j=a.appId,a.tokenStore&&(p=a.tokenStore)}function b(a){var b=p.fbtoken,c={};b?(c.status="connected",c.authResponse={token:b}):c.status="unknown",a&&a(c)}function c(a,b){function c(a){var b=a.url;if(b.indexOf("access_token=")>0||b.indexOf("error=")>0){var c=600-((new Date).getTime()-g);setTimeout(function(){f.close()},c>0?c:0),d(b)}}function e(){console.log("exit and remove listeners"),deferredLogin.reject({error:"user_cancelled",error_description:"User cancelled login process",error_reason:"user_cancelled"}),f.removeEventListener("loadstop",c),f.removeEventListener("exit",e),f=null,console.log("done removing listeners")}var f,g,h="";return j?(b&&b.scope&&(h=b.scope),k=a,m=!1,l&&(s="https://www.facebook.com/connect/login_success.html"),g=(new Date).getTime(),f=window.open(n+"?client_id="+j+"&redirect_uri="+s+"&response_type=token&scope="+h,"_blank","location=no"),void(l&&(f.addEventListener("loadstart",c),f.addEventListener("exit",e)))):a({status:"unknown",error:"Facebook App Id not set."})}function d(a){var b,c;m=!0,a.indexOf("access_token=")>0?(b=a.substr(a.indexOf("#")+1),c=h(b),p.fbtoken=c.access_token,k&&k({status:"connected",authResponse:{token:c.access_token}})):a.indexOf("error=")>0?(b=a.substring(a.indexOf("?")+1,a.indexOf("#")),c=h(b),k&&k({status:"not_authorized",error:c.error})):k&&k({status:"not_authorized"})}function e(a){var b,c=p.fbtoken;p.removeItem("fbtoken"),c&&(b=window.open(o+"?access_token="+c+"&next="+t,"_blank","location=no"),l&&setTimeout(function(){b.close()},700)),a&&a()}function f(a){var b,c=a.method||"GET",d=a.params||{},e=new XMLHttpRequest;d.access_token=p.fbtoken,b="https://graph.facebook.com"+a.path+"?"+i(d),e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status)a.success&&a.success(JSON.parse(e.responseText));else{var b=e.responseText?JSON.parse(e.responseText).error:{message:"An error has occurred"};a.error&&a.error(b)}},e.open(c,b,!0),e.send()}function g(a,b){return f({method:"DELETE",path:"/me/permissions",success:function(){p.fbtoken=void 0,a()},error:b})}function h(a){var b=decodeURIComponent(a),c={},d=b.split("&");return d.forEach(function(a){var b=a.split("=");c[b[0]]=b[1]}),c}function i(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}var j,k,l,m,n="https://www.facebook.com/dialog/oauth",o="https://www.facebook.com/logout.php",p=window.sessionStorage,q=window.location.pathname.substring(0,window.location.pathname.indexOf("/",2)),r=location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")+q,s=r+"/oauthcallback.html",t=r+"/logoutcallback.html";console.log(s),console.log(t),document.addEventListener("deviceready",function(){l=!0},!1);var u={init:a,login:c,logout:e,revokePermissions:g,api:f,oauthCallback:d,getLoginStatus:b};return module.exports=u,u}(); \ No newline at end of file diff --git a/openfb.js b/openfb.js index 8e7413e..f66023b 100644 --- a/openfb.js +++ b/openfb.js @@ -274,7 +274,7 @@ var openFB = (function () { } // The public API - return { + var publicApi = { init: init, login: login, logout: logout, @@ -282,6 +282,8 @@ var openFB = (function () { api: api, oauthCallback: oauthCallback, getLoginStatus: getLoginStatus - } + }; + module.exports = publicApi; + return publicApi; +}()); -}()); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e17663c --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "open-fb", + "version": "0.0.5", + "repository": "jhberges/OpenFB", + "main": "dist/openfb.min.js", + "devDependencies": { + "grunt": "^0.4.5", + "grunt-contrib-jshint": "^0.11.0", + "grunt-contrib-uglify": "^0.8.0", + "grunt-release": "^0.11.0", + "grunt-shell": "^1.1.2" + }, + "dependencies": {}, + "author": { + "name": "ccoenraets" + }, + "contributors": [ + { + "name": "Jan-Helge Bergesen", + "email": "jhberges@gmail.com", + "url": "http://github.com/jhberges" + } + ] +}