From ae49e0bbdcd46f2c3c52919dcda106eae236eb8d Mon Sep 17 00:00:00 2001 From: watanabe Date: Tue, 7 Jan 2014 23:08:42 +0900 Subject: [PATCH] improve javascript use backbone.js 1.1.0 use underscore.js 1.5.2 add 'op' namespace --- .../templates/_smtCommunityListBox.php | 13 +-- .../_smtCommunityMemberJoinListBox.php | 6 +- .../community/templates/smtSearchSuccess.php | 6 +- .../friend/templates/smtListSuccess.php | 2 +- .../templates/_smtMemberFriendListBox.php | 6 +- .../_smtMemberJoinCommunityListBox.php | 6 +- .../member/templates/smtProfileSuccess.php | 6 +- .../member/templates/smtSearchSuccess.php | 6 +- apps/pc_frontend/templates/_layout.php | 15 ++- apps/pc_frontend/templates/smtLayoutGroup.php | 19 +-- apps/pc_frontend/templates/smtLayoutHome.php | 28 +++-- .../pc_frontend/templates/smtLayoutMember.php | 28 +++-- apps/pc_frontend/templates/smtLayoutSns.php | 28 +++-- web/js/backbone-min.js | 2 + web/js/jquery.notify.js | 16 ++- web/js/op_notify.js | 78 ++++++------- web/js/openpne/api.js | 30 +++++ web/js/smt_notify.js | 109 ------------------ web/js/smt_tosaka.js | 97 +++++++++------- web/js/underscore-min.js | 6 + 20 files changed, 233 insertions(+), 274 deletions(-) create mode 100644 web/js/backbone-min.js create mode 100644 web/js/openpne/api.js delete mode 100644 web/js/smt_notify.js create mode 100644 web/js/underscore-min.js diff --git a/apps/pc_frontend/modules/community/templates/_smtCommunityListBox.php b/apps/pc_frontend/modules/community/templates/_smtCommunityListBox.php index 8569abae2..672ce78ba 100644 --- a/apps/pc_frontend/modules/community/templates/_smtCommunityListBox.php +++ b/apps/pc_frontend/modules/community/templates/_smtCommunityListBox.php @@ -82,10 +82,10 @@ $('#leaveCommunity').click(function(){ $('#leaveCommunityLoading').show(); $('#leaveCommunityLink').hide(); - $.ajax({ + op.api.ajax({ type: 'GET', - url: openpne.apiBase + 'community/join.json', - data: 'community_id=getId() ?>&leave=true&apiKey=' + openpne.apiKey, + url: 'community/join.json', + data: {community_id: getId() ?>, leave: true}, success: function(json){ $('#leaveCommunityFinish').show(); $('#leaveCommunityLoading').hide(); @@ -100,10 +100,10 @@ $('#joinCommunity').click(function(){ $('#joinCommunityLoading').show(); $('#joinCommunityLink').hide(); - $.ajax({ + op.api.ajax({ type: 'GET', - url: openpne.apiBase + 'community/join.json', - data: 'community_id=getId() ?>&apiKey=' + openpne.apiKey, + url: 'community/join.json', + data: {community_id: getId() ?>}, success: function(json){ $('#joinCommunityFinish').show(); $('#joinCommunityLoading').hide(); @@ -114,6 +114,5 @@ }, }); }); - }); diff --git a/apps/pc_frontend/modules/community/templates/_smtCommunityMemberJoinListBox.php b/apps/pc_frontend/modules/community/templates/_smtCommunityMemberJoinListBox.php index a785392c3..b069a63f8 100644 --- a/apps/pc_frontend/modules/community/templates/_smtCommunityMemberJoinListBox.php +++ b/apps/pc_frontend/modules/community/templates/_smtCommunityMemberJoinListBox.php @@ -7,7 +7,7 @@ + get('pc_html_head') ?> diff --git a/apps/pc_frontend/templates/smtLayoutGroup.php b/apps/pc_frontend/templates/smtLayoutGroup.php index 467e43191..f1ec77c6d 100644 --- a/apps/pc_frontend/templates/smtLayoutGroup.php +++ b/apps/pc_frontend/templates/smtLayoutGroup.php @@ -25,13 +25,18 @@ '); ?> - - - - - - - + diff --git a/apps/pc_frontend/templates/smtLayoutHome.php b/apps/pc_frontend/templates/smtLayoutHome.php index bf9201a28..41f7ac48b 100644 --- a/apps/pc_frontend/templates/smtLayoutHome.php +++ b/apps/pc_frontend/templates/smtLayoutHome.php @@ -19,19 +19,25 @@ ); $json = defined('JSON_PRETTY_PRINT') ? json_encode($jsonData, JSON_PRETTY_PRINT) : json_encode($jsonData); - -echo javascript_tag(' -var openpne = '.$json.'; -'); ?> + - - - - - - - + diff --git a/apps/pc_frontend/templates/smtLayoutMember.php b/apps/pc_frontend/templates/smtLayoutMember.php index edd858850..02125e225 100644 --- a/apps/pc_frontend/templates/smtLayoutMember.php +++ b/apps/pc_frontend/templates/smtLayoutMember.php @@ -19,19 +19,25 @@ ); $json = defined('JSON_PRETTY_PRINT') ? json_encode($jsonData, JSON_PRETTY_PRINT) : json_encode($jsonData); - -echo javascript_tag(' -var openpne = '.$json.'; -'); ?> + - - - - - - - + diff --git a/apps/pc_frontend/templates/smtLayoutSns.php b/apps/pc_frontend/templates/smtLayoutSns.php index 15dba17c3..ddf3be4d0 100644 --- a/apps/pc_frontend/templates/smtLayoutSns.php +++ b/apps/pc_frontend/templates/smtLayoutSns.php @@ -19,19 +19,25 @@ ); $json = defined('JSON_PRETTY_PRINT') ? json_encode($jsonData, JSON_PRETTY_PRINT) : json_encode($jsonData); - -echo javascript_tag(' -var openpne = '.$json.'; -'); ?> + - - - - - - - + diff --git a/web/js/backbone-min.js b/web/js/backbone-min.js new file mode 100644 index 000000000..3b2593dd2 --- /dev/null +++ b/web/js/backbone-min.js @@ -0,0 +1,2 @@ +(function(){var t=this;var e=t.Backbone;var i=[];var r=i.push;var s=i.slice;var n=i.splice;var a;if(typeof exports!=="undefined"){a=exports}else{a=t.Backbone={}}a.VERSION="1.1.0";var h=t._;if(!h&&typeof require!=="undefined")h=require("underscore");a.$=t.jQuery||t.Zepto||t.ender||t.$;a.noConflict=function(){t.Backbone=e;return this};a.emulateHTTP=false;a.emulateJSON=false;var o=a.Events={on:function(t,e,i){if(!l(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,i){if(!l(this,"once",t,[e,i])||!e)return this;var r=this;var s=h.once(function(){r.off(t,s);e.apply(this,arguments)});s._callback=e;return this.on(t,s,i)},off:function(t,e,i){var r,s,n,a,o,u,c,f;if(!this._events||!l(this,"off",t,[e,i]))return this;if(!t&&!e&&!i){this._events={};return this}a=t?[t]:h.keys(this._events);for(o=0,u=a.length;o").attr(t);this.setElement(e,false)}else{this.setElement(h.result(this,"el"),false)}}});a.sync=function(t,e,i){var r=T[t];h.defaults(i||(i={}),{emulateHTTP:a.emulateHTTP,emulateJSON:a.emulateJSON});var s={type:r,dataType:"json"};if(!i.url){s.url=h.result(e,"url")||U()}if(i.data==null&&e&&(t==="create"||t==="update"||t==="patch")){s.contentType="application/json";s.data=JSON.stringify(i.attrs||e.toJSON(i))}if(i.emulateJSON){s.contentType="application/x-www-form-urlencoded";s.data=s.data?{model:s.data}:{}}if(i.emulateHTTP&&(r==="PUT"||r==="DELETE"||r==="PATCH")){s.type="POST";if(i.emulateJSON)s.data._method=r;var n=i.beforeSend;i.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",r);if(n)return n.apply(this,arguments)}}if(s.type!=="GET"&&!i.emulateJSON){s.processData=false}if(s.type==="PATCH"&&E){s.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var o=i.xhr=a.ajax(h.extend(s,i));e.trigger("request",e,o,i);return o};var E=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};a.ajax=function(){return a.$.ajax.apply(a.$,arguments)};var k=a.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var $=/(\(\?)?:\w+/g;var H=/\*\w+/g;var A=/[\-{}\[\]+?.,\\\^$|#\s]/g;h.extend(k.prototype,o,{initialize:function(){},route:function(t,e,i){if(!h.isRegExp(t))t=this._routeToRegExp(t);if(h.isFunction(e)){i=e;e=""}if(!i)i=this[e];var r=this;a.history.route(t,function(s){var n=r._extractParameters(t,s);i&&i.apply(r,n);r.trigger.apply(r,["route:"+e].concat(n));r.trigger("route",e,n);a.history.trigger("route",r,e,n)});return this},navigate:function(t,e){a.history.navigate(t,e);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=h.result(this,"routes");var t,e=h.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(A,"\\$&").replace(S,"(?:$1)?").replace($,function(t,e){return e?t:"([^/]+)"}).replace(H,"(.*?)");return new RegExp("^"+t+"$")},_extractParameters:function(t,e){var i=t.exec(e).slice(1);return h.map(i,function(t){return t?decodeURIComponent(t):null})}});var I=a.History=function(){this.handlers=[];h.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var N=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/[?#].*$/;I.started=false;h.extend(I.prototype,o,{interval:50,getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=this.location.pathname;var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(N,"")},start:function(t){if(I.started)throw new Error("Backbone.history has already been started");I.started=true;this.options=h.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var e=this.getFragment();var i=document.documentMode;var r=P.exec(navigator.userAgent.toLowerCase())&&(!i||i<=7);this.root=("/"+this.root+"/").replace(O,"/");if(r&&this._wantsHashChange){this.iframe=a.$('