Skip to content

Commit

Permalink
split the controllers
Browse files Browse the repository at this point in the history
split the controllers
  • Loading branch information
NatsuDawn committed Jan 11, 2015
1 parent c3dd492 commit 1d84243
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 103 deletions.
7 changes: 5 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<li><a href="#/about">关于</a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">提点建议</a>
<a class="dropdown-toggle suggestionDrop" data-toggle="dropdown" role="button" aria-expanded="false">提点建议</a>

<ul class="dropdown-menu" role="menu">
<li>
Expand Down Expand Up @@ -129,7 +129,10 @@

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers.js"></script>
<script src="scripts/controllers/common.js"></script>
<script src="scripts/controllers/searchCtl.js"></script>
<script src="scripts/controllers/navCtl.js"></script>
<script src="scripts/controllers/aboutCtl.js"></script>
<script src="scripts/bigcache/av-mini.js"></script>
<script src="scripts/bigcache/bigcache.js"></script>
<!-- <script src="scripts/controllers/main.js"></script>
Expand Down
72 changes: 0 additions & 72 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,6 @@ require.config({
}
})

function drawChart(id, option, type) {
require(
[
'echarts',
'echarts/chart/' + type
],
function(ec) {
var myChart = ec.init(document.getElementById(id))
myChart.setOption(option)
}
)
}

var db = new LocalDB("githuber.info");
var collection = db.collection("userInfo");

function updateLocalDB() {
collection.drop();
collection.insert(window.config);
}
collection.find().then(function(data) {
if (data.length) {
window.config = data[0];
} else {
window.config = {};
}
})

function utf8_to_b64(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}

function b64_to_utf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}
Object.size = function(obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};

$(function() {
$(".navbar a").click(function() {
$(".navbar-toggle").not(".collapsed").click()
})
var triggerFeedback = function() {
$(document).trigger("feedback", [$("#feedback-email").val(), $("#feedback-content").val()])
$("#feedback-main").hide(0);
$("#feedback-gangnam-style").show(0);
setTimeout(function() {
$("#feedback-btn").trigger("click")
$("#feedback-gangnam-style").hide(0);
$("#feedback-email, #feedback-content").val("")
$("#feedback-main").show(0);
setTimeout(function() {
$("#feedback-btn").one("click", triggerFeedback)
}, 5000)
}, 2000)
return false
}
$("#feedback-btn").one("click", triggerFeedback)
$("#feedback-main").click(function() {
return false;
})
$.digits = function(text){
return text.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
})

// Angular app
var App = angular.module('App', ['ngRoute']);
App.config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/controllers/aboutCtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
App.controller('aboutCtl', ['$scope', '$location', function($scope, $location) {
$('#bar-search').show(0)
clearBDShare()
$scope.search = function() {
if ($scope.sw.replace(/\s/g, "") != "") {
window.bigcache = {}
$location.path("/search/" + $scope.sw);
}
};
$(".label-info").hover(function() {
$(this).css("cursor", "pointer")
}).click(function() {
window.open($(this).data("url"))
})
}]);
77 changes: 77 additions & 0 deletions app/scripts/controllers/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var clearBDShare = function() {
$(".bdshare-slide-button-box").remove()
window._bd_share_is_recently_loaded = false
window._bd_share_main = null
}

function drawChart(id, option, type) {
require(
[
'echarts',
'echarts/chart/' + type
],
function(ec) {
var myChart = ec.init(document.getElementById(id))
myChart.setOption(option)
}
)
}

var db = new LocalDB("githuber.info");
var collection = db.collection("userInfo");

function updateLocalDB() {
collection.drop();
collection.insert(window.config);
}
collection.find().then(function(data) {
if (data.length) {
window.config = data[0];
} else {
window.config = {};
}
})

function utf8_to_b64(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}

function b64_to_utf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}
Object.size = function(obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};

$(function() {
$(".navbar a").click(function() {
$(".navbar-toggle").not(".collapsed").click()
})
var triggerFeedback = function() {
$(document).trigger("feedback", [$("#feedback-email").val(), $("#feedback-content").val()])
$("#feedback-main").hide(0);
$("#feedback-gangnam-style").show(0);
setTimeout(function() {
$("#feedback-btn").trigger("click")
$("#feedback-gangnam-style").hide(0);
$("#feedback-email, #feedback-content").val("")
$("#feedback-main").show(0);
setTimeout(function() {
$("#feedback-btn").one("click", triggerFeedback)
}, 5000)
}, 2000)
return false
}
$("#feedback-btn").one("click", triggerFeedback)
$("#feedback-main").click(function() {
return false;
})
$.digits = function(text){
return text.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
});
9 changes: 9 additions & 0 deletions app/scripts/controllers/navCtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App.controller('navCtl', ['$scope', '$location', function($scope, $location) {
clearBDShare()
$scope.search = function() {
if ($scope.sw.replace(/\s/g, "") != "") {
window.bigcache = {}
$location.path("/search/" + $scope.sw);
}
};
}]);
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
var App = angular.module('App');
var clearBDShare = function() {
$(".bdshare-slide-button-box").remove()
window._bd_share_is_recently_loaded = false
window._bd_share_main = null
}
App.controller('searchCtl', ['$scope', '$routeParams', function($scope, $routeParams) {
$('#bar-search').show(0)
clearBDShare()
Expand All @@ -23,7 +17,7 @@ App.controller('searchCtl', ['$scope', '$routeParams', function($scope, $routePa
if (!window.config) {
window.config = {}
}
var debug = false
var debug = false;
if (debug) {
window.config.token = "acd18045340051e7bd1e1a4bd6e4f2571c475e53"
} else {
Expand Down Expand Up @@ -699,26 +693,4 @@ App.controller('searchCtl', ['$scope', '$routeParams', function($scope, $routePa
$("#index-input").trigger("focus")
}, 300)

}]).controller('navCtl', ['$scope', '$location', function($scope, $location) {
clearBDShare()
$scope.search = function() {
if ($scope.sw.replace(/\s/g, "") != "") {
window.bigcache = {}
$location.path("/search/" + $scope.sw);
}
};
}]).controller('aboutCtl', ['$scope', '$location', function($scope, $location) {
$('#bar-search').show(0)
clearBDShare()
$scope.search = function() {
if ($scope.sw.replace(/\s/g, "") != "") {
window.bigcache = {}
$location.path("/search/" + $scope.sw);
}
};
$(".label-info").hover(function() {
$(this).css("cursor", "pointer")
}).click(function() {
window.open($(this).data("url"))
})
}]);
3 changes: 3 additions & 0 deletions app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,6 @@ p {
.info-number {
font-family: Constantia, Georgia;
}
.suggestionDrop {
cursor: pointer;
}

0 comments on commit 1d84243

Please sign in to comment.