格式上的调整, 现在可以分开写,但发布时打成一个js提高性能

This commit is contained in:
guange 2016-06-14 16:03:10 +08:00
parent b1791f4531
commit ada15b4212
16 changed files with 59 additions and 92 deletions

View File

@ -13,6 +13,8 @@
<script type="text/javascript">
window.g_openid = '<%= @wechat_user.openid %>';
window.g_debug = false; //调试标志,如果在本地请置为true
window.apiUrl = '/api/v1/';
</script>
</head>
@ -21,7 +23,7 @@
</div>
<script src="/javascripts/wechat/build/angular.all.min.js"></script>
<script src="/javascripts/wechat/app.js"></script>
<script src="/javascripts/wechat/build/app.min.js"></script>
</body>
</html>

View File

@ -2,7 +2,7 @@
<html ng-app="wechat">
<head>
<base href="/">
<title>我的动态</title>
<title>仅供本地调试使用</title>
<meta charset='utf-8' />
<meta name="keywords" content="" />
<meta name="description" content="" />
@ -17,7 +17,15 @@
<div ng-view>
</div>
<script type="text/javascript">
window.g_openid = 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg';
window.g_debug = true; //调试标志,如果在本地请置为true
window.apiUrl = 'http://localhost:3000/api/v1/';
</script>
<script src="/javascripts/wechat/build/angular.all.min.js"></script>
<!--<script src="/javascripts/wechat/build/app.min.js"></script>-->
<script src="/javascripts/wechat/app.js"></script>
<script src="/javascripts/wechat/others/factory.js"></script>
@ -33,6 +41,9 @@
<script src="/javascripts/wechat/controllers/issue.js"></script>
<script src="/javascripts/wechat/controllers/journals.js"></script>
<script src="/javascripts/wechat/others/routes.js"></script>
</body>
</html>

View File

@ -1,8 +1 @@
var app = angular.module('wechat', ['ngRoute']);
var apiUrl = '/api/v1/';
var debug = true; //调试标志,如果在本地请置为true
if(debug===true){
apiUrl = 'http://localhost:3000/api/v1/';
//apiUrl = 'http://www.trustie.net/api/v1/';
}

View File

@ -0,0 +1,14 @@
var app=angular.module("wechat",["ngRoute"]);
app.factory("auth",["$http","$routeParams","$q",function(e,n,t){var o="";"undefined"!=typeof g_openid&&(o=g_openid);var a=function(){var a=t.defer();if("undefined"!=typeof o&&o.length>0)a.resolve(o);else{var i=n.code;e({url:"/wechat/get_open_id",data:{code:i},method:"POST"}).then(function(e){o=e.data.openid,a.resolve(o)},function(e){a.reject(e)})}return a.promise},i=function(){return o};return{getOpenId:a,openid:i}}]),app.factory("rms",function(){var e={},n=function(n,t){e[n]=t},t=function(n){return e[n]};return{save:n,get:t}}),app.factory("common",["$http","auth","$routeParams",function(e,n,t){var o=function(t,o,a,i){if(a.comment&&!(a.comment.length<=0)){var r=a.comment.replace(/\n/g,"<br/>"),d={type:o,content:r,openid:n.openid()};a.disabled=!0,e({method:"POST",url:apiUrl+"new_comment/"+t,data:d}).then(function(e){a.disabled=!1,"function"==typeof i&&i()},function(e){})}},a=function(t,o){return e({method:"GET",url:apiUrl+o+"/"+t+"?openid="+n.openid()})},i=function(t){t.praise_count+=1,t.has_praise=!0,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})},r=function(t){t.praise_count-=1,t.has_praise=!1,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})};return{addCommonReply:o,loadCommonData:a,addCommonPraise:i,decreaseCommonPraise:r}}]);
app.filter("safeHtml",["$sce",function(t){return function(n){return t.trustAsHtml(n)}}]);
app.controller("ActivityController",["$anchorScroll","$location","$scope","$http","$timeout","auth","rms","common",function(t,a,e,o,i,n,c,s){e.replaceUrl=function(t){return t},console.log("ActivityController load"),e.page=c.get("page")||0,e.activities=c.get("activities")||[],e.has_more=c.get("has_more"),e.loadActData=function(t){e.page=t,o({method:"POST",url:apiUrl+"activities",data:{openid:n.openid(),page:t}}).then(function(t){t.data.page>0?e.activities=e.activities.concat(t.data.data):e.activities=t.data.data,c.save("activities",e.activities),e.has_more=t.data.count+10*t.data.page<t.data.all_count,c.save("has_more",e.has_more),c.save("page",t.data.page),console.log(t.data)},function(t){})},e.activities.length<=0?n.getOpenId().then(function(t){e.loadActData(0)},function(t){alert("获取openid出错:"+t)}):i(function(){window.scrollTo(0,c.get("yoffset"))}),e.goDetail=function(t,e,o){c.save("yoffset",window.document.body.scrollTop),a.path("/"+t+"/"+e)},e.addPraise=function(t){s.addCommonPraise(t)},e.decreasePraise=function(t){s.decreaseCommonPraise(t)}}]);
app.controller("AddClassController",["$scope",function(o){}]);
app.controller("BlogController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"blog_comments").then(function(n){console.log(n.data),o.blog=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addBlogReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"BlogComment",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){console.log(o),a.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),a.decreaseCommonPraise(o)}}]);
app.controller("CourseNoticeController",["$scope","$http","$routeParams","auth","common",function(o,n,e,t,a){o.formData={comment:""};var c=function(n){a.loadCommonData(n,"newss").then(function(n){console.log(n.data),o.news=n.data.data},function(o){})};t.getOpenId().then(function(o){c(e.id)},function(o){alert("获取openid出错:"+o)}),o.addNoticeReply=function(n){console.log(n.comment),a.addCommonReply(e.id,"News",n,function(){o.formData={comment:""},c(e.id)})},o.addPraise=function(o){a.addCommonPraise(o)},o.decreasePraise=function(o){a.decreaseCommonPraise(o)}}]);
app.controller("DiscussionController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var i=function(n){t.loadCommonData(n,"messages").then(function(n){console.log(n.data),o.discussion=n.data.data},function(o){})};e.getOpenId().then(function(o){i(a.id)},function(o){alert("获取openid出错:"+o)}),o.addDiscussionReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"Message",n,function(){o.formData={comment:""},i(a.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
app.controller("HomeworkController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var m=function(n){t.loadCommonData(n,"whomeworks").then(function(n){console.log(n.data),o.homework=n.data.data},function(o){})};a.getOpenId().then(function(o){m(e.id)},function(o){alert("获取openid出错:"+o)}),o.addHomeworkReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"HomeworkCommon",n,function(){o.formData={comment:""},m(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
app.controller("IssueController",["$scope","$http","$routeParams","auth","common",function(o,n,e,a,t){o.formData={comment:""};var s=function(n){t.loadCommonData(n,"issues").then(function(n){console.log(n.data),o.issue=n.data.data},function(o){})};a.getOpenId().then(function(o){s(e.id)},function(o){alert("获取openid出错:"+o)}),o.addIssueReply=function(n){console.log(n.comment),t.addCommonReply(e.id,"Issue",n,function(){o.formData={comment:""},s(e.id)})},o.addPraise=function(o){t.addCommonPraise(o)},o.decreasePraise=function(o){t.decreaseCommonPraise(o)}}]);
app.controller("JournalsController",["$scope","$http","$routeParams","auth","common",function(o,n,a,e,t){o.formData={comment:""};var c=function(n){t.loadCommonData(n,"journal_for_messages").then(function(n){console.log(n.data),o.message=n.data.data},function(o){})};e.getOpenId().then(function(o){c(a.id)},function(o){alert("获取openid出错:"+o)}),o.addJournalReply=function(n){console.log(n.comment),t.addCommonReply(a.id,"JournalsForMessage",n,function(){o.formData={comment:""},c(a.id)})},o.addPraise=function(o){console.log(o),t.addCommonPraise(o)},o.decreasePraise=function(o){console.log(o),t.decreaseCommonPraise(o)}}]);
app.directive("inputAuto",function(){return{restrict:"A",scope:{},link:function(n,t){var e=t.parent().children().eq(0),i=t.parent().next();t.on("input",function(){console.log(i),e.html(t[0].value);var n=e[0].scrollHeight;t.css("height",n+"px")}),i.on("click",function(){t.css("height","28px")})}}});
app.directive("loadingSpinner",["$http",function(i){return{restrict:"A",replace:!0,template:'<div ng-show="activeCalls>0" class="loading-bg"><div class="loading-box"><img src="/images/loading.gif" alt=""/><span>加载中...</span></div></div>'}}]);
app.config(["$routeProvider","$httpProvider","$locationProvider",function(e,r,t){var o="/assets/wechat/";e.when("/activites",{templateUrl:o+"activities.html",controller:"ActivityController"}).when("/issues/:id",{templateUrl:o+"issue_detail.html",controller:"IssueController"}).when("/project_discussion/:id",{templateUrl:o+"project_discussion.html",controller:"DiscussionController"}).when("/homework/:id",{templateUrl:o+"homework_detail.html",controller:"HomeworkController"}).when("/course_notice/:id",{templateUrl:o+"course_notice.html",controller:"CourseNoticeController"}).when("/course_discussion/:id",{templateUrl:o+"course_discussion.html",controller:"DiscussionController"}).when("/journal_for_message/:id",{templateUrl:o+"jour_message_detail.html",controller:"JournalsController"}).when("/blog_comment/:id",{templateUrl:o+"blog_detail.html",controller:"BlogController"}).when("/add_class",{templateUrl:o+"add_class.html",controller:"AddClassController"}).otherwise({redirectTo:"/activites"}),r.interceptors.push(["$q","$rootScope",function(e,r){return void 0==r.activeCalls&&(r.activeCalls=0),{request:function(e){return r.activeCalls+=1,e},requestError:function(e){return r.activeCalls-=1,e},response:function(e){return r.activeCalls-=1,e},responseError:function(e){return r.activeCalls-=1,e}}}])}]);

View File

@ -1,5 +1,7 @@
app.controller('ActivityController',function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){
app.controller('ActivityController',
['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common',
function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){
$scope.replaceUrl = function(url){
return url;
};
@ -63,4 +65,4 @@ app.controller('ActivityController',function($anchorScroll, $location,$scope, $h
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,5 +1,7 @@
app.controller('BlogController', function($scope, $http, $routeParams, auth, common){
app.controller('BlogController',
['$scope', '$http', '$routeParams', 'auth', 'common',
function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -35,4 +37,4 @@ app.controller('BlogController', function($scope, $http, $routeParams, auth, com
console.log(act);
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,4 +1,5 @@
app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){
app.controller('CourseNoticeController', ['$scope', '$http', '$routeParams', 'auth', 'common',
function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -32,4 +33,4 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,5 +1,5 @@
app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){
app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -33,4 +33,4 @@ app.controller('DiscussionController', function($scope, $http, $routeParams, aut
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,5 +1,5 @@
app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){
app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -33,4 +33,4 @@ app.controller('HomeworkController', function($scope, $http, $routeParams, auth,
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,4 +1,4 @@
app.controller('IssueController', function($scope, $http, $routeParams, auth, common){
app.controller('IssueController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -33,4 +33,4 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co
$scope.decreasePraise = function(act){
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,4 +1,4 @@
app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){
app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
@ -34,4 +34,4 @@ app.controller('JournalsController', function($scope, $http, $routeParams, auth,
console.log(act);
common.decreaseCommonPraise(act);
};
});
}]);

View File

@ -1,14 +1,10 @@
app.factory('auth', function($http,$routeParams, $q){
app.factory('auth', ['$http','$routeParams', '$q', function($http,$routeParams, $q){
var _openid = '';
if(typeof g_openid !== 'undefined'){
_openid = g_openid;
}
if(debug===true){
_openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; //guange的帐号
}
var getOpenId = function() {
var deferred = $q.defer();
if (typeof _openid !== 'undefined' && _openid.length > 0){
@ -32,7 +28,7 @@ app.factory('auth', function($http,$routeParams, $q){
return _openid;
};
return {getOpenId: getOpenId, openid: openid};
});
}]);
app.factory('rms', function(){
@ -48,7 +44,7 @@ app.factory('rms', function(){
return {save: save, get: get};
});
app.factory('common', function($http, auth, $routeParams){
app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $routeParams){
var addCommonReply = function(id, type, data, cb){
if(!data.comment || data.comment.length<=0){
@ -117,4 +113,4 @@ app.factory('common', function($http, auth, $routeParams){
};
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
});
}]);

View File

@ -1,5 +1,5 @@
app.filter('safeHtml', function ($sce) {
app.filter('safeHtml', ['$sce',function ($sce) {
return function (input) {
return $sce.trustAsHtml(input);
}
});
}]);

View File

@ -43,7 +43,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou
});
//监听异步请求,实现加载中显隐标记
$httpProvider.interceptors.push(function ($q, $rootScope) {
$httpProvider.interceptors.push(['$q', '$rootScope', function ($q, $rootScope) {
if ($rootScope.activeCalls == undefined) {
$rootScope.activeCalls = 0;
}
@ -66,5 +66,5 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou
return rejection;
}
};
});
}]);
}]);

View File

@ -1,57 +0,0 @@
/**
* Created by root on 3/25/16.
*/
$(document).ready(function(){
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
var apiUrl = '/api/v1/';
var loadDataFromServer = function(id, page){
getOpenId(function(openid){
$.ajax({
url: apiUrl + 'activities',
data: {openid: openid, page: page},
type: 'POST',
dataType: 'json',
success: function(data){
setTemplate(data.data, data.all_count, data.count, data.page);
},
error: function(xhr,status,err){
console.log(err);
}
});
})
};
var setTemplate = function(data, all_count, count, page){
console.log(data);
var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page});
if (page == 0) {
$('#container').prepend(html);
} else {
$("#more_activities").remove();
$('#container').append(html);
}
descToggle();
};
//内容全部显示与部分隐藏
var descToggle = function(){
$(".post-all-content").each(function(){
var postHeight = $(this).height();
if (postHeight > 90){
$(this).parent().next().css("display","block");
$(this).parent().next().toggle(function(){
$(this).text("点击隐藏");
$(this).prev().css("height",postHeight);
},function(){
$(this).text("点击展开");
$(this).prev().css("height",90);
});
}
});
}
loadDataFromServer(8686, 0);
});

3
script/assets Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cd public/javascripts/wechat && gulp && gulp minify