Changeset 35158

Show
Ignore:
Timestamp:
09/02/09 13:06:12 (4 years ago)
Author:
kyo_ago
Message:

requestShareAppでキャンセルを選択した場合にcallbackが呼ばれない問題の修正

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

Legend:

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

    r34745 r35158  
    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-08-4 
     6 * Date: 2009-08-28 
    77 * @author kyo_ago <http://tech.kayac.com/archive/jquery-opensocial-simple.html> 
    8  * @version 1.1.6 
     8 * @version 1.1.9 
    99 */ 
    1010;(function ($) { 
     
    3030                                return all; 
    3131                        })(), 
    32                         'mixi_field_set' : ['PROFILE_URL', 'ADDRESSES', 'AGE', 'DATE_OF_BIRTH', 'GENDER', 'HAS_APP', 'BLOOD_TYPE'] 
     32                        'mixi_field_set' : ['ID', 'NAME', 'NICKNAME', 'PROFILE_URL', 'ADDRESSES', 'AGE', 'DATE_OF_BIRTH', 'GENDER', 'HAS_APP', 'BLOOD_TYPE'] 
    3333                } 
    3434        }; 
     
    173173                        if (res.hadError()) return; 
    174174                        if ($.isFunction(callback)) callback(res.get('PERSONS').getData()); 
     175                }); 
     176                return klass; 
     177        }; 
     178        klass.requestShareApp = function (callback) { 
     179                var os = opensocial; 
     180                os.requestShareApp("VIEWER_FRIENDS", null, function(res) { 
     181//mixi�̓L�����Z����es.hadError() === true 
     182//                      if (res.hadError()) return; 
     183                        if ($.isFunction(callback)) return callback(res); 
    175184                }); 
    176185                return klass; 
  • lang/javascript/jQuery.opensocial_simple/jquery.opensocial_simple.min.js

    r34745 r35158  
    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-08-4 
     6 * Date: 2009-08-28 
    77 * @author kyo_ago <http://tech.kayac.com/archive/jquery-opensocial-simple.html> 
    8  * @version 1.1.6 
     8 * @version 1.1.9 
    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_field_set:{all_field_set:(function(){var d=[],e=opensocial.Person.Field;c.each(e,function(f){d.push(f)});return d})(),mixi_field_set:["PROFILE_URL","ADDRESSES","AGE","DATE_OF_BIRTH","GENDER","HAS_APP","BLOOD_TYPE"]}};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(h,j){var g=opensocial;var i=g.IdSpec.PersonId;var f=g.newDataRequest();if(c.isFunction(h)){j=h;h=["PROFILE_URL"]}if(a.person_field_set[h]){h=a.person_field_set[h]}if(!c.isArray(h)){throw ("field is not array")}var e=c.map(h,function(k){return g.Person.Field[k]});c.each(["OWNER","VIEWER"],function(){var k=this+"";var l={};l[g.DataRequest.PeopleRequestFields.PROFILE_DETAILS]=e;f.add(f.newFetchPersonRequest(i[k],l),k)});var d={};f.send(function(k){if(k.hadError()){return}d.OWNER=k.get("OWNER").getData();d.VIEWER=k.get("VIEWER").getData();c.each(["OWNER","VIEWER"],function(){var l=this+"";var m={};c.each(h,function(){m[this]=d[l].getField(g.Person.Field[this]);if(this!="ADDRESSES"||!m[this]){return}m[this]=m[this][g.Address.Field.UNSTRUCTURED_ADDRESS]||m[this]["unstructured_address"]});d[l].fieldValue=m});if(c.isFunction(j)){j(d)}});return d};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};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); 
     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_field_set:{all_field_set:(function(){var d=[],e=opensocial.Person.Field;c.each(e,function(f){d.push(f)});return d})(),mixi_field_set:["ID","NAME","NICKNAME","PROFILE_URL","ADDRESSES","AGE","DATE_OF_BIRTH","GENDER","HAS_APP","BLOOD_TYPE"]}};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(h,j){var g=opensocial;var i=g.IdSpec.PersonId;var f=g.newDataRequest();if(c.isFunction(h)){j=h;h=["PROFILE_URL"]}if(a.person_field_set[h]){h=a.person_field_set[h]}if(!c.isArray(h)){throw ("field is not array")}var e=c.map(h,function(k){return g.Person.Field[k]});c.each(["OWNER","VIEWER"],function(){var k=this+"";var l={};l[g.DataRequest.PeopleRequestFields.PROFILE_DETAILS]=e;f.add(f.newFetchPersonRequest(i[k],l),k)});var d={};f.send(function(k){if(k.hadError()){return}d.OWNER=k.get("OWNER").getData();d.VIEWER=k.get("VIEWER").getData();c.each(["OWNER","VIEWER"],function(){var l=this+"";var m={};c.each(h,function(){m[this]=d[l].getField(g.Person.Field[this]);if(this!="ADDRESSES"||!m[this]){return}m[this]=m[this][g.Address.Field.UNSTRUCTURED_ADDRESS]||m[this]["unstructured_address"]});d[l].fieldValue=m});if(c.isFunction(j)){j(d)}});return d};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};a.requestShareApp=function(e){var d=opensocial;d.requestShareApp("VIEWER_FRIENDS",null,function(f){if(c.isFunction(e)){return e(f)}});return a};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);