diff --git a/app/app.js b/app/app.js index 5735926c..63595625 100644 --- a/app/app.js +++ b/app/app.js @@ -1,78 +1,80 @@ angular - .module("web", [ - "ui.router", - "ui.bootstrap", - "ui.codemirror", - "pascalprecht.translate", - "ngSanitize", - "templates", - "ui.bootstrap.contextMenu", - ]) - .config([ - "$stateProvider", - "$urlRouterProvider", - "$translateProvider", - function ($stateProvider, $urlRouterProvider, $translateProvider) { - moment.locale("zh-CN"); + .module('web', [ + 'ui.router', + 'ui.bootstrap', + 'ui.codemirror', + 'pascalprecht.translate', + 'ngSanitize', + 'templates', + 'ui.bootstrap.contextMenu' + ]) + .config([ + '$stateProvider', + '$urlRouterProvider', + '$translateProvider', + function($stateProvider, $urlRouterProvider, $translateProvider) { + moment.locale('zh-CN'); - $stateProvider - .state("files", { - url: "/", - templateUrl: "main/files/files.html", - controller: "filesCtrl", - }) - .state("login", { - url: "/login", - templateUrl: "main/auth/login.html", - controller: "loginCtrl", - }); + $stateProvider + .state('files', { + url: '/', + templateUrl: 'main/files/files.html', + controller: 'filesCtrl' + }) + .state('login', { + url: '/login', + templateUrl: 'main/auth/login.html', + controller: 'loginCtrl' + }); + + $urlRouterProvider.otherwise('/'); - $urlRouterProvider.otherwise("/"); + // i18n + for (var k in Global.i18n) { + $translateProvider.translations(k, Global.i18n[k].content); + } - //i18n - for (var k in Global.i18n) { - $translateProvider.translations(k, Global.i18n[k].content); + $translateProvider.preferredLanguage('zh-CN'); + + $translateProvider.useSanitizeValueStrategy('escapeParameters'); } - $translateProvider.preferredLanguage("zh-CN"); + ]) + .run([ + '$rootScope', + '$translate', + 'Toast', + function($rootScope, $translate, Toast) { + $rootScope.openURL = function(url) { + openExternal(url); + }; - $translateProvider.useSanitizeValueStrategy("escapeParameters"); - }, - ]) - .run([ - "$rootScope", - "$translate", - "Toast", - function ($rootScope, $translate, Toast) { - $rootScope.openURL = function (url) { - openExternal(url); - }; + // //i18n + var langMap = {}; + var langList = []; - // //i18n - var langMap = {}; - var langList = []; - angular.forEach(Global.i18n, function (v, k) { - langMap[k] = v; - langList.push({ - lang: k, - label: v.label, + angular.forEach(Global.i18n, function(v, k) { + langMap[k] = v; + langList.push({ + lang: k, + label: v.label + }); }); - }); - var lang = localStorage.getItem("lang") || langList[0].lang; + var lang = localStorage.getItem('lang') || langList[0].lang; - $rootScope.langSettings = { - langList: langList, - lang: lang, - changeLanguage: function (key) { - console.log("changeLanguage:", key); - key = langMap[key] ? key : langList[0].lang; - $translate.use(key); - localStorage.setItem("lang", key); - $rootScope.langSettings.lang = key; - Toast.success($translate.instant("setup.success")); //'已经设置成功' - }, - }; - $translate.use(lang); + $rootScope.langSettings = { + langList: langList, + lang: lang, + changeLanguage: function(key) { + console.log('changeLanguage:', key); + key = langMap[key] ? key : langList[0].lang; + $translate.use(key); + localStorage.setItem('lang', key); + $rootScope.langSettings.lang = key; + Toast.success($translate.instant('setup.success')); // '已经设置成功' + } + }; + $translate.use(lang); - console.log("ready"); - }, - ]); + console.log('ready'); + } + ]); diff --git a/app/components/directives/auto-height.js b/app/components/directives/auto-height.js index 8be45fee..5b57d7ef 100644 --- a/app/components/directives/auto-height.js +++ b/app/components/directives/auto-height.js @@ -1,31 +1,32 @@ -angular.module("web").directive("autoHeight", [ - "$timeout", - function ($timeout) { +angular.module('web').directive('autoHeight', [ + '$timeout', + function($timeout) { return { link: linkFn, - restrict: "EA", + restrict: 'EA', transclude: false, scope: { - autoHeight: "=", - //bottomLoader: '&' - }, + autoHeight: '=' + // bottomLoader: '&' + } }; function linkFn(scope, ele, attr) { var h = parseInt(scope.autoHeight); ele.css({ - //'border-bottom': '1px solid #ccc', - overflow: "auto", - position: "relative", + // 'border-bottom': '1px solid #ccc', + overflow: 'auto', + position: 'relative' }); var tid; function resize() { $timeout.cancel(tid); - tid = $timeout(function () { + tid = $timeout(function() { var v = $(window).height() + h; + $(ele).height(v); }, 300); } @@ -52,5 +53,5 @@ angular.module("web").directive("autoHeight", [ // $(ele).scroll(onScroll); // } } - }, + } ]); diff --git a/app/components/directives/bottom-loader.js b/app/components/directives/bottom-loader.js index efbf0289..23d7689b 100644 --- a/app/components/directives/bottom-loader.js +++ b/app/components/directives/bottom-loader.js @@ -1,25 +1,26 @@ -angular.module("web").directive("bottomLoader", [ - "$timeout", - function ($timeout) { +angular.module('web').directive('bottomLoader', [ + '$timeout', + function($timeout) { return { link: linkFn, - restrict: "EA", + restrict: 'EA', transclude: false, scope: { - bottomLoader: "&", - }, + bottomLoader: '&' + } }; function linkFn(scope, ele, attr) { ele.css({ - //'border-bottom': '1px solid red', - overflow: "auto", - position: "relative", + // 'border-bottom': '1px solid red', + overflow: 'auto', + position: 'relative' }); var tid2; + function onScroll() { $timeout.cancel(tid2); - tid2 = $timeout(function () { + tid2 = $timeout(function() { if ( $(ele)[0].scrollHeight > 0 && $(ele).parent().height() + $(ele).scrollTop() + 10 >= @@ -33,5 +34,5 @@ angular.module("web").directive("bottomLoader", [ $(window).resize(onScroll); $(ele).scroll(onScroll); } - }, + } ]); diff --git a/app/components/directives/cleanable-input.js b/app/components/directives/cleanable-input.js index 42a58ef5..0c472775 100644 --- a/app/components/directives/cleanable-input.js +++ b/app/components/directives/cleanable-input.js @@ -2,60 +2,61 @@ */ -angular.module("web").directive("cleanableInput", [ - "$timeout", - function ($timeout) { +angular.module('web').directive('cleanableInput', [ + '$timeout', + function($timeout) { return { - restrict: "EA", - require: "ngModel", + restrict: 'EA', + require: 'ngModel', scope: { - model: "=ngModel", - ngChange: "&", - x: "=", - y: "=", + model: '=ngModel', + ngChange: '&', + x: '=', + y: '=' }, link: function link(scope, element) { - var id = "cleanable_inp-" + (Math.random() + "").substring(2); + var id = 'cleanable_inp-' + (Math.random() + '').substring(2); element.wrap( - '
' + '
' ); var btn = $( - '' + + '' + '' - ).appendTo($("#" + id)); + ).appendTo($('#' + id)); btn - .css({ - display: "none", - position: "absolute", - "z-index": 10, - }) - .click(function (e) { - scope.model = ""; - if (!scope.$root.$$phase) { - scope.$apply(); - } + .css({ + display: 'none', + position: 'absolute', + 'z-index': 10 + }) + .click(function(e) { + scope.model = ''; - if (scope.ngChange) { - scope.$eval(scope.ngChange); - } + if (!scope.$root.$$phase) { + scope.$apply(); + } - return false; - }); + if (scope.ngChange) { + scope.$eval(scope.ngChange); + } + + return false; + }); var y = isNaN(scope.y) ? 0 : parseInt(scope.y); var x = isNaN(scope.x) ? 0 : parseInt(scope.x); function onchange(v) { - if (v && v !== "") { + if (v && v !== '') { btn - .css({ - top: 6 + y, - right: 6 - x, - }) - .show(); + .css({ + top: 6 + y, + right: 6 - x + }) + .show(); } else { btn.hide(); } @@ -63,17 +64,18 @@ angular.module("web").directive("cleanableInput", [ // Listen for any changes to the original model. var tid; + scope.$watch( - "model", - function alteredValues(newValue, oldValue) { - $timeout.cancel(tid); - tid = $timeout(function () { - onchange(newValue); - }, 300); - }, - true + 'model', + function alteredValues(newValue, oldValue) { + $timeout.cancel(tid); + tid = $timeout(function() { + onchange(newValue); + }, 300); + }, + true ); - }, + } }; - }, + } ]); diff --git a/app/components/directives/clipboard-button.js b/app/components/directives/clipboard-button.js index b4b9e745..d1f698df 100644 --- a/app/components/directives/clipboard-button.js +++ b/app/components/directives/clipboard-button.js @@ -2,30 +2,31 @@ */ -angular.module("web").directive("clipboardButton", [ - "$translate", - "Toast", - function ($translate, Toast) { +angular.module('web').directive('clipboardButton', [ + '$translate', + 'Toast', + function($translate, Toast) { var T = $translate.instant; + return { - restrict: "EA", + restrict: 'EA', scope: { - action: "=", - target: "=", - success: "&", + action: '=', + target: '=', + success: '&' }, link: function link(scope, ele) { var d = new Clipboard(ele[0], { - text: function () { + text: function() { return $(scope.target).val(); }, - action: scope.action || "copy", + action: scope.action || 'copy' }); - d.on("success", function () { - Toast.success(T("copy.successfully")); //'复制成功' + d.on('success', function() { + Toast.success(T('copy.successfully')); // '复制成功' }); - }, + } }; - }, + } ]); diff --git a/app/components/directives/drop-zone.js b/app/components/directives/drop-zone.js index bbccae60..155ef447 100644 --- a/app/components/directives/drop-zone.js +++ b/app/components/directives/drop-zone.js @@ -1,47 +1,48 @@ -angular.module("web").directive("dropZone", function () { +angular.module('web').directive('dropZone', function() { return { link: linkFn, - restrict: "EA", + restrict: 'EA', transclude: false, scope: { - dropZone: "=", - }, + dropZone: '=' + } }; function linkFn(scope, ele, attr) { - $(document).on("dragenter", stopPrev); - $(document).on("dragover", stopPrev); - $(document).on("dragleave", stopPrev); - $(document).on("drop", stopPrev); + $(document).on('dragenter', stopPrev); + $(document).on('dragover', stopPrev); + $(document).on('dragleave', stopPrev); + $(document).on('drop', stopPrev); function stopPrev(e) { e.originalEvent.stopPropagation(); e.originalEvent.preventDefault(); } var shadow; - $(ele).on("dragenter", function () { - shadow = $("
") - .css({ - position: "absolute", - height: $(ele).height(), - width: $(ele).width(), - opacity: 0.5, - top: $(ele).offset().top, - left: $(ele).offset().left, - background: "yellow", - zIndex: 20, - boxShadow: "inset yellow 0 0 10px", - }) - .appendTo("body"); + + $(ele).on('dragenter', function() { + shadow = $('
') + .css({ + position: 'absolute', + height: $(ele).height(), + width: $(ele).width(), + opacity: 0.5, + top: $(ele).offset().top, + left: $(ele).offset().left, + background: 'yellow', + zIndex: 20, + boxShadow: 'inset yellow 0 0 10px' + }) + .appendTo('body'); shadow - .on("dragleave", function () { - shadow.remove(); - }) - .on("drop", function (e) { - shadow.remove(); - scope.dropZone(e); - }); + .on('dragleave', function() { + shadow.remove(); + }) + .on('drop', function(e) { + shadow.remove(); + scope.dropZone(e); + }); }); } }); diff --git a/app/components/directives/file-dialog-button.js b/app/components/directives/file-dialog-button.js index 6b407e6f..42ba58a8 100644 --- a/app/components/directives/file-dialog-button.js +++ b/app/components/directives/file-dialog-button.js @@ -1,15 +1,15 @@ -angular.module("web").directive("fileDialogButton", function () { +angular.module('web').directive('fileDialogButton', function() { return { link: linkFn, - restrict: "EA", + restrict: 'EA', transclude: false, scope: { - fileChange: "=", - }, + fileChange: '=' + } }; function linkFn(scope, ele, attr) { - $(ele).on("change", function (e) { + $(ele).on('change', function(e) { scope.fileChange.call({}, e.target.files); }); } diff --git a/app/components/directives/flv-player.js b/app/components/directives/flv-player.js index 2900b04c..16cfa917 100644 --- a/app/components/directives/flv-player.js +++ b/app/components/directives/flv-player.js @@ -1,34 +1,36 @@ -angular.module("web").directive("flvPlayer", [ - "$timeout", - function ($timeout) { +angular.module('web').directive('flvPlayer', [ + '$timeout', + function($timeout) { return { link: linkFn, - restrict: "EA", + restrict: 'EA', transclude: false, scope: { - src: "=", - autoplay: "=", //autoplay - }, + src: '=', + autoplay: '=' // autoplay + } }; function linkFn(scope, ele, attr) { - scope.$watch("src", init); + scope.$watch('src', init); function init() { - if (!scope.src) return; + if (!scope.src) { return; } + var src = - "http://localhost:" + + 'http://localhost:' + Global.staticServerPort + - "/flv-player.html?src=" + + '/flv-player.html?src=' + encodeURIComponent(scope.src) + - "&autoplay=" + - (scope.autoplay || ""); + '&autoplay=' + + (scope.autoplay || ''); + ele.html( - '