Changeset 34123

Show
Ignore:
Timestamp:
06/24/09 13:39:30 (4 years ago)
Author:
kyo_ago
Message:

bug fix

Location:
lang/javascript/jQuery.opensocial_simple
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jQuery.opensocial_simple/jquery.opensocial_simple.js

    r33293 r34123  
    44 * Dual licensed under the MIT <http://www.opensource.org/licenses/mit-license.php> 
    55 * and GPL <http://www.opensource.org/licenses/gpl-license.php> licenses. 
    6  * Date: 2009-05-13 
     6 * Date: 2009-06-24 
    77 * @author kyo_ago <http://tech.kayac.com/archive/jquery-opensocial-simple.html> 
    8  * @version 1.1.3 
     8 * @version 1.1.4 
    99 */ 
    1010;(function ($) { 
     
    124124                return klass.person; 
    125125        }; 
    126         klass.getPersons = function (persons, callback) { 
     126        klass.getPersons = klass.getPeople = function (persons, callback) { 
    127127                var os = opensocial; 
    128128                var req = os.newDataRequest(); 
     
    130130                new function () { 
    131131                        var tmp = {}; 
     132                        if (!$.isArray(persons)) return users = [persons]; 
    132133                        $.each(persons, function () { tmp[this] = 1; }); 
    133134                        $.each(tmp, function (key) { users.push(key); }); 
     
    142143                        os.Person.Field.PROFILE_URL 
    143144                ]; 
    144                 req.add(req.newFetchPersonRequest(idSpec, param), 'PERSONS'); 
     145                req.add(req.newFetchPeopleRequest(idSpec, param), 'PERSONS'); 
    145146                req.send(function (res) { 
    146147                        if (res.hadError()) return; 
     
    162163                var req = os.newDataRequest(); 
    163164                req.add(req.newFetchPeopleRequest(idspec, opt), 'FRIENDS'); 
     165                var friends = {}; 
    164166                req.send(function (res) { 
    165167                        if (res.hadError()) return; 
    166                         var friends = res.get('FRIENDS').getData(); 
     168                        friends = res.get('FRIENDS').getData(); 
    167169                        var next = settings.first + settings.max; 
    168170                        if (next < friends.getTotalSize()) friends.nextFriends = function (callback) { 
  • lang/javascript/jQuery.opensocial_simple/jquery.opensocial_simple.min.js

    r33293 r34123  
    44 * Dual licensed under the MIT <http://www.opensource.org/licenses/mit-license.php> 
    55 * and GPL <http://www.opensource.org/licenses/gpl-license.php> licenses. 
    6  * Date: 2009-05-13 
     6 * Date: 2009-06-24 
    77 * @author kyo_ago <http://tech.kayac.com/archive/jquery-opensocial-simple.html> 
    8  * @version 1.1.3 
     8 * @version 1.1.4 
    99 */ 
    10 ;(function(c){var b="opensocial_simple";var a={ajaxSettings:{url:undefined,success:function(){},data:undefined,METHOD:undefined,CONTENT_TYPE:undefined,AUTHORIZATION:undefined,GET_SUMMARIES:undefined,HEADERS:undefined,NUM_ENTRIES:undefined,POST_DATA:undefined,REFRESH_INTERVAL:undefined},person:{}};a.get=function(d,f,g,e){if(c.isFunction(f)){g=f;f=null}return a.ajax({METHOD:"GET",url:d,data:f,success:g,CONTENT_TYPE:e})};c.each(gadgets.io.ContentType,function(e,d){a["get"+e]=function(f,g,h){return a.get(f,g,h,e)}});a.post=function(d,f,g,e){if(c.isFunction(f)){g=f;f={}}return a.ajax({METHOD:"POST",url:d,data:f,success:g,CONTENT_TYPE:e})};a.ajaxSetup=function(d){c.extend(a.ajaxSettings,d);return this};a.ajax=function(d){d=c.extend(true,d,c.extend(true,{},a.ajaxSettings,d));var f={};var e=gadgets.io.RequestParameters;(d.data&&(d.METHOD=="POST"))?f[e.POST_DATA]=c.param(d.data||{}):d.url+="?"+c.param(d.data||{});c.each([{obj:"AuthorizationType",req:"AUTHORIZATION"},{obj:"ContentType",req:"CONTENT_TYPE"},{obj:"MethodType",req:"METHOD"}],function(){var g=gadgets.io[this["obj"]][d[this["req"]]];if(g!==undefined){f[e[this["req"]]]=g}});if(d.REFRESH_INTERVAL!==undefined){f[gadgets.io.RequestParameters.REFRESH_INTERVAL]=d.REFRESH_INTERVAL}c.each(["GET_SUMMARIES","HEADERS","NUM_ENTRIES"],function(){if(d[this]!==undefined){f[this]=s[this]}});gadgets.io.makeRequest(d.url,function(g){d.success(g.data)},f);return this};a.getPerson=function(g){if(a.person.OWNER&&a.person.VIEWER){if(c.isFunction(g)){g(a.person)}return a.person}var e=opensocial;var f=e.IdSpec.PersonId;var d=e.newDataRequest();d.add(d.newFetchPersonRequest(f.OWNER),"OWNER");d.add(d.newFetchPersonRequest(f.VIEWER),"VIEWER");d.send(function(h){if(h.hadError()){return}a.person.OWNER=h.get("OWNER").getData();a.person.VIEWER=h.get("VIEWER").getData();if(c.isFunction(g)){g(a.person)}});return a.person};a.getPersons=function(g,j){var f=opensocial;var e=f.newDataRequest();var i=[];new function(){var k={};c.each(g,function(){k[this]=1});c.each(k,function(l){i.push(l)})};var d=(function(){var k={};k[f.IdSpec.Field.USER_ID]=i;return opensocial.newIdSpec(k)})();var h={};h[f.DataRequest.PeopleRequestFields.PROFILE_DETAILS]=[f.Person.Field.PROFILE_URL];e.add(e.newFetchPersonRequest(d,h),"PERSONS");e.send(function(k){if(k.hadError()){return}if(c.isFunction(j)){j(k.get("PERSONS").getData())}});return a.person};a.getFriends=function(g){var j=g.callback;var i=opensocial;var f=i.newIdSpec({userId:g.userId,groupId:"FRIENDS"});var d=opensocial.DataRequest.PeopleRequestFields;var e={};if(g.max!==undefined){e[d.MAX]=g.max}if(g.first!==undefined){e[d.FIRST]=g.first}var h=i.newDataRequest();h.add(h.newFetchPeopleRequest(f,e),"FRIENDS");h.send(function(l){if(l.hadError()){return}var k=l.get("FRIENDS").getData();var m=g.first+g.max;if(m<k.getTotalSize()){k.nextFriends=function(o){g.callback=o;g.first=m;a.getFriends(g)}}var n=g.first-g.max;if(n>=0){k.prevFriends=function(o){g.callback=o;g.first=n;a.getFriends(g)}}k.getFriends=function(p,o){g.callback=p;g.first=g.max*(o-0);a.getFriends(g)};k.getPageSize=function(){return Math.ceil(k.getTotalSize()/g.max)};k.getCurrentPage=function(){return Math.ceil(k.getOffset()/g.max)};if(c.isFunction(j)){j(k)}});return friends};a.getOwnerFriends=function(f,d,e){return a.getFriends({callback:f,userId:"OWNER",max:d,first:e})};a.getViewerFriends=function(d){return a.getFriends({callback:d,userId:"VIEWER",max:max,first:first})};new function(){var d=opensocial.IdSpec.PersonId;a.getOwnerData=function(e){return a.getData(e,d.OWNER)};a.postOwnerData=function(e,f){throw ("security error")};a.getViewerData=function(e){return a.getData(e,d.VIEWER)};a.postViewerData=function(e,f){return a.postData(e,f,d.VIEWER)}};new function(){var f=opensocial.IdSpec.PersonId.VIEWER;var d=opensocial.IdSpec.PersonId.OWNER;var e=function(k,j){var i=opensocial.newDataRequest();var g={};c.each(k,function(m,n){g[opensocial.IdSpec.Field[m]]=n});var h=opensocial.newIdSpec(g);var l={};l[opensocial.DataRequest.DataRequestFields.ESCAPE_TYPE]=opensocial.EscapeType.NONE;i.add(i.newFetchPersonAppDataRequest(h,b,l),b);i.add(i.newFetchPersonRequest(f),"viewer");i.send(function(m){if(m.hadError()){return(m.getErrorMessage()?undefined:j.call(this))}var n=m.get("viewer").getData();if(!n){return}j.apply(this,[m,n])});return i};a.getData=function(h,g){if(!c.isFunction(h)){throw ("callback is not function")}e({USER_ID:g},function(k,m){if(!c.isFunction(h)){return}if(!k||!m){return h({})}var j=k.get(b).getData();var i=j[m.getId()]||j[m.getId().replace(/\D/g,"")];try{if("string"===typeof i[b]){i[b]=gadgets.json.parse(decodeURIComponent(i[b]))}i=i[b][b]}catch(l){i={}}return h(i)});return this};a.getFriendsData=function(g){if(!c.isFunction(g)){throw ("callback is not function")}e({USER_ID:d,GROUP_ID:"FRIENDS",NETWORK_DISTANCE:1},function(i,k){if(!arguments.length){return g({})}var h=i.get(b).getData();(h[k.getId()]||h[k.getId().replace(/\D/g,"")]||{}).is_viewer=true;h.VIEWER=k;for(var l in h){try{h[l]=gadgets.json.parse(h[l])[b]}catch(j){}}return g(h)});return this}};new function(){var f=opensocial;var e=function(g){return function(h){if(h.hadError()){return}if(c.isFunction(g)){g.apply(this,arguments)}}};var d=function(j,h){var g={};var i=f[h].Field;c.each(j,function(k,l){g[i[k]||k]=l});return g};a.postData=function(g,k,j){var h=f.newDataRequest();var i={};i[b]=g;h.add(h.newUpdatePersonAppDataRequest(j,b,encodeURIComponent(gadgets.json.stringify(i))));h.send(e(k));return this};a.postActivity=function(l,g,m){var h=f.CreateActivityPriority;var k={TITLE:l};if("string"!==typeof l){k=l}if(c.isFunction(g)){m=g;g=h.LOW}g=h[g]||g;var j=d(k,"Activity");var i=f.newActivity(j);f.requestCreateActivity(i,g,e(m));return this};a.postMessage=function(j,m,g,n){var h=f.Message.Type;var l={TITLE:m,TYPE:"PRIVATE_MESSAGE"};if("string"!==typeof j){l=j;if(c.isFunction(m)){n=m}g=l.BODY;delete l.BODY;j=l.TARGET;delete l.TARGET}l.TYPE=h[l.TYPE]||l.TYPE;var k=d(l,"Activity");var i=f.newMessage(g,l);f.requestSendMessage(j,i,e(n));return this}};a.getLocale=function(e){var d={};var i=c(e||".jQuery_opensocial_simple_locale").get(0).innerHTML.replace(/\/\*|\*\//g,"");if(!i){throw ("missing local value")}var h=(new gadgets.Prefs()).getLang();if(!(new RegExp('<Locale lang="'+h+'">')).test(i)){h=""}var f=i.match(new RegExp('<Locale lang="'+h+'">([\\s\\S]+?)</Locale>'));if(!f){f=i.match(new RegExp("<Locale>([\\s\\S]+?)</Locale>"))}if(!f){return{}}var g=f[1].match(/<msg\s+name="\w+">[\s\S]+?<\/msg>/gi);if(!g){return{}}c.each(g,function(){var j=this.match(/<msg\s+name="(\w+)">([\s\S]+?)<\/msg>/i);d[j[1]]=j[2]});return d};a.navigateTo=function(d,f){if(!gadgets.views.getSupportedViews){throw ('require <Require feature="views" />')}var e=gadgets.views.getSupportedViews();if(!e[d]){throw"unsupportedViewName "+d}gadgets.views.requestNavigateTo(e[d],f);return this};a.getParams=function(){if(!gadgets.views.getParams){throw ('require <Require feature="views" />')}return gadgets.views.getParams()};c[b]=a;c[b.replace(/_([a-z])/g,function(){return arguments[1].toUpperCase()})]=a})(jQuery); 
     10;(function(c){var b="opensocial_simple";var a={ajaxSettings:{url:undefined,success:function(){},data:undefined,METHOD:undefined,CONTENT_TYPE:undefined,AUTHORIZATION:undefined,GET_SUMMARIES:undefined,HEADERS:undefined,NUM_ENTRIES:undefined,POST_DATA:undefined,REFRESH_INTERVAL:undefined},person:{}};a.get=function(d,f,g,e){if(c.isFunction(f)){g=f;f=null}return a.ajax({METHOD:"GET",url:d,data:f,success:g,CONTENT_TYPE:e})};c.each(gadgets.io.ContentType,function(e,d){a["get"+e]=function(f,g,h){return a.get(f,g,h,e)}});a.post=function(d,f,g,e){if(c.isFunction(f)){g=f;f={}}return a.ajax({METHOD:"POST",url:d,data:f,success:g,CONTENT_TYPE:e})};a.ajaxSetup=function(d){c.extend(a.ajaxSettings,d);return this};a.ajax=function(d){d=c.extend(true,d,c.extend(true,{},a.ajaxSettings,d));var f={};var e=gadgets.io.RequestParameters;(d.data&&(d.METHOD=="POST"))?f[e.POST_DATA]=c.param(d.data||{}):d.url+="?"+c.param(d.data||{});c.each([{obj:"AuthorizationType",req:"AUTHORIZATION"},{obj:"ContentType",req:"CONTENT_TYPE"},{obj:"MethodType",req:"METHOD"}],function(){var g=gadgets.io[this["obj"]][d[this["req"]]];if(g!==undefined){f[e[this["req"]]]=g}});if(d.REFRESH_INTERVAL!==undefined){f[gadgets.io.RequestParameters.REFRESH_INTERVAL]=d.REFRESH_INTERVAL}c.each(["GET_SUMMARIES","HEADERS","NUM_ENTRIES"],function(){if(d[this]!==undefined){f[this]=s[this]}});gadgets.io.makeRequest(d.url,function(g){d.success(g.data)},f);return this};a.getPerson=function(g){if(a.person.OWNER&&a.person.VIEWER){if(c.isFunction(g)){g(a.person)}return a.person}var e=opensocial;var f=e.IdSpec.PersonId;var d=e.newDataRequest();d.add(d.newFetchPersonRequest(f.OWNER),"OWNER");d.add(d.newFetchPersonRequest(f.VIEWER),"VIEWER");d.send(function(h){if(h.hadError()){return}a.person.OWNER=h.get("OWNER").getData();a.person.VIEWER=h.get("VIEWER").getData();if(c.isFunction(g)){g(a.person)}});return a.person};a.getPersons=a.getPeople=function(g,j){var f=opensocial;var e=f.newDataRequest();var i=[];new function(){var k={};if(!c.isArray(g)){return i=[g]}c.each(g,function(){k[this]=1});c.each(k,function(l){i.push(l)})};var d=(function(){var k={};k[f.IdSpec.Field.USER_ID]=i;return opensocial.newIdSpec(k)})();var h={};h[f.DataRequest.PeopleRequestFields.PROFILE_DETAILS]=[f.Person.Field.PROFILE_URL];e.add(e.newFetchPeopleRequest(d,h),"PERSONS");e.send(function(k){if(k.hadError()){return}if(c.isFunction(j)){j(k.get("PERSONS").getData())}});return a.person};a.getFriends=function(h){var k=h.callback;var j=opensocial;var g=j.newIdSpec({userId:h.userId,groupId:"FRIENDS"});var d=opensocial.DataRequest.PeopleRequestFields;var f={};if(h.max!==undefined){f[d.MAX]=h.max}if(h.first!==undefined){f[d.FIRST]=h.first}var i=j.newDataRequest();i.add(i.newFetchPeopleRequest(g,f),"FRIENDS");var e={};i.send(function(l){if(l.hadError()){return}e=l.get("FRIENDS").getData();var m=h.first+h.max;if(m<e.getTotalSize()){e.nextFriends=function(o){h.callback=o;h.first=m;a.getFriends(h)}}var n=h.first-h.max;if(n>=0){e.prevFriends=function(o){h.callback=o;h.first=n;a.getFriends(h)}}e.getFriends=function(p,o){h.callback=p;h.first=h.max*(o-0);a.getFriends(h)};e.getPageSize=function(){return Math.ceil(e.getTotalSize()/h.max)};e.getCurrentPage=function(){return Math.ceil(e.getOffset()/h.max)};if(c.isFunction(k)){k(e)}});return e};a.getOwnerFriends=function(f,d,e){return a.getFriends({callback:f,userId:"OWNER",max:d,first:e})};a.getViewerFriends=function(d){return a.getFriends({callback:d,userId:"VIEWER",max:max,first:first})};new function(){var d=opensocial.IdSpec.PersonId;a.getOwnerData=function(e){return a.getData(e,d.OWNER)};a.postOwnerData=function(e,f){throw ("security error")};a.getViewerData=function(e){return a.getData(e,d.VIEWER)};a.postViewerData=function(e,f){return a.postData(e,f,d.VIEWER)}};new function(){var f=opensocial.IdSpec.PersonId.VIEWER;var d=opensocial.IdSpec.PersonId.OWNER;var e=function(k,j){var i=opensocial.newDataRequest();var g={};c.each(k,function(m,n){g[opensocial.IdSpec.Field[m]]=n});var h=opensocial.newIdSpec(g);var l={};l[opensocial.DataRequest.DataRequestFields.ESCAPE_TYPE]=opensocial.EscapeType.NONE;i.add(i.newFetchPersonAppDataRequest(h,b,l),b);i.add(i.newFetchPersonRequest(f),"viewer");i.send(function(m){if(m.hadError()){return(m.getErrorMessage()?undefined:j.call(this))}var n=m.get("viewer").getData();if(!n){return}j.apply(this,[m,n])});return i};a.getData=function(h,g){if(!c.isFunction(h)){throw ("callback is not function")}e({USER_ID:g},function(k,m){if(!c.isFunction(h)){return}if(!k||!m){return h({})}var j=k.get(b).getData();var i=j[m.getId()]||j[m.getId().replace(/\D/g,"")];try{if("string"===typeof i[b]){i[b]=gadgets.json.parse(decodeURIComponent(i[b]))}i=i[b][b]}catch(l){i={}}return h(i)});return this};a.getFriendsData=function(g){if(!c.isFunction(g)){throw ("callback is not function")}e({USER_ID:d,GROUP_ID:"FRIENDS",NETWORK_DISTANCE:1},function(i,k){if(!arguments.length){return g({})}var h=i.get(b).getData();(h[k.getId()]||h[k.getId().replace(/\D/g,"")]||{}).is_viewer=true;h.VIEWER=k;for(var l in h){try{h[l]=gadgets.json.parse(h[l])[b]}catch(j){}}return g(h)});return this}};new function(){var f=opensocial;var e=function(g){return function(h){if(h.hadError()){return}if(c.isFunction(g)){g.apply(this,arguments)}}};var d=function(j,h){var g={};var i=f[h].Field;c.each(j,function(k,l){g[i[k]||k]=l});return g};a.postData=function(g,k,j){var h=f.newDataRequest();var i={};i[b]=g;h.add(h.newUpdatePersonAppDataRequest(j,b,encodeURIComponent(gadgets.json.stringify(i))));h.send(e(k));return this};a.postActivity=function(l,g,m){var h=f.CreateActivityPriority;var k={TITLE:l};if("string"!==typeof l){k=l}if(c.isFunction(g)){m=g;g=h.LOW}g=h[g]||g;var j=d(k,"Activity");var i=f.newActivity(j);f.requestCreateActivity(i,g,e(m));return this};a.postMessage=function(j,m,g,n){var h=f.Message.Type;var l={TITLE:m,TYPE:"PRIVATE_MESSAGE"};if("string"!==typeof j){l=j;if(c.isFunction(m)){n=m}g=l.BODY;delete l.BODY;j=l.TARGET;delete l.TARGET}l.TYPE=h[l.TYPE]||l.TYPE;var k=d(l,"Activity");var i=f.newMessage(g,l);f.requestSendMessage(j,i,e(n));return this}};a.getLocale=function(e){var d={};var i=c(e||".jQuery_opensocial_simple_locale").get(0).innerHTML.replace(/\/\*|\*\//g,"");if(!i){throw ("missing local value")}var h=(new gadgets.Prefs()).getLang();if(!(new RegExp('<Locale lang="'+h+'">')).test(i)){h=""}var f=i.match(new RegExp('<Locale lang="'+h+'">([\\s\\S]+?)</Locale>'));if(!f){f=i.match(new RegExp("<Locale>([\\s\\S]+?)</Locale>"))}if(!f){return{}}var g=f[1].match(/<msg\s+name="\w+">[\s\S]+?<\/msg>/gi);if(!g){return{}}c.each(g,function(){var j=this.match(/<msg\s+name="(\w+)">([\s\S]+?)<\/msg>/i);d[j[1]]=j[2]});return d};a.navigateTo=function(d,f){if(!gadgets.views.getSupportedViews){throw ('require <Require feature="views" />')}var e=gadgets.views.getSupportedViews();if(!e[d]){throw"unsupportedViewName "+d}gadgets.views.requestNavigateTo(e[d],f);return this};a.getParams=function(){if(!gadgets.views.getParams){throw ('require <Require feature="views" />')}return gadgets.views.getParams()};c[b]=a;c[b.replace(/_([a-z])/g,function(){return arguments[1].toUpperCase()})]=a})(jQuery);