1 Star 0 Fork 0

章文焱/backend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 29.06 KB
一键复制 编辑 原始数据 按行查看 历史
章文焱 提交于 2024-03-17 12:53 . first commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
var mod = angular.module('app', ['ngRoute', 'ngAnimate', 'ngMessages', 'ngMaterial', 'route-segment', 'view-segment', 'app.nw-manifest', 'app.socket', 'ui.ace', 'ui.modal', 'ui.bootstrap', 'app.local-storage', 'app.top', 'app.game', 'app.game.creep', 'app.game.spawn', 'app.game.source', 'app.game.energy', 'app.game.construction-site', 'app.game.constructed-wall', 'app.game.exit', 'app.game.extension', 'app.game.flag', 'app.game.room.walls', 'app.game.room.roads', 'app.game.room.display-options-block', 'app.game.room.rendered-svg-path', 'app.game.room.view-popup', 'ui.bootstrap.tabs', 'app.game.memory', 'app.game.console', 'app.game.script', 'luegg.directives', 'app.connection', 'app.game.room', 'app.game.room.dlg-creep', 'app.dialogs', 'app.constants', 'app.game.tutorial', 'app.static-maps', 'app.memory-storage', 'app.game.editor-panel', 'app.game.replay-list', 'app.api', 'app.config', 'app.login', 'app.register', 'app.auth', 'app.loader', 'app.game.lobby', 'ngAria', 'app.game.room.dlg-flag', 'app.game.room.spawn-properties', 'app.game.room.creep-properties', 'ui.drop', 'app.profile', 'app.profile.account', 'app.key-filter', 'app.game.keeper-lair', 'app.game.portal', 'app.game.lobby.survival', 'app.game.lobby.arena', 'app.game.room.dlg-arena-activation', 'ui.json-editor', 'app.profile.account.badge', 'app.badge', 'app.badge.paths', 'app.game.world-map', 'app.game.controller', 'app.game.dlg-world-activation', 'app.game.dlg-world-respawn', 'app.profile.early-preview-request', 'app.game.overview', 'app.game.overview.room', 'app.punchcard', 'app.game.lobby.world', 'app.ea', 'app.game.room.controller-properties', 'app.game.room.lab-properties', 'app.game.link', 'app.game.room.flag-properties', 'app.timeline-stats', 'app.profile.messages.respondent', 'app.profile.messages.index', 'app.game.storage', 'app.game.script.dlg-clone-branch', 'app.profile.cpu', 'app.game.tower', 'app.game.observer', 'app.game.disabled-object', 'app.game.power-bank', 'app.game.power-spawn', 'app.game.lobby.power', 'app.profile-stats', 'app.recaptcha', 'app.profile.account.subscription', 'app.game.mineral', 'app.game.extractor', 'app.game.lab', 'app.game.terminal', 'app.game.container', 'app.game.tutorial.section1', 'app.game.tutorial.section2', 'app.game.tutorial.section3', 'app.game.tutorial.section4', 'app.game.tutorial.section5', 'angularSpectrumColorpicker', 'app.game.market', 'app.game.nuke', 'app.game.nuker', 'app.dlg-version-updated', 'app.code-branches', 'app.nw-local-file-sync', 'app.game.rampart', 'app.game.room.rampart-properties', 'app.game.market.all-orders', 'app.game.market.my-orders', 'app.game.market.history', 'app.dlg-server-message', 'app.game.shards', 'app.game.room.dlg-display-options', 'app.routing-app2', 'app.profile.account.auth-tokens', 'app.profile.account.auth-tokens.noratelimit', 'app.profile.account.runtime', 'app.game.room.effect-icon', 'app.game.room.power-creep-properties', 'app.game.room.deposit-properties', 'app.game.room.invaderCore-properties']);
mod.config(['$locationProvider', '$routeProvider', '$routeSegmentProvider', '$mdThemingProvider', '$compileProvider', function ($locationProvider, $routeProvider, $routeSegmentProvider, $mdThemingProvider, $compileProvider) {
$locationProvider.hashPrefix('!');
$routeProvider.when('/order', { redirectTo: '/enter' });
$routeProvider.otherwise({ redirectTo: '/g' });
$mdThemingProvider.theme('default').dark().primaryColor('indigo', {
'hue-3': 'A400'
}).accentColor('teal', {
'default': '500'
}).warnColor('orange');
$mdThemingProvider.setDefaultTheme('default');
//$compileProvider.debugInfoEnabled(false);
if (1 || window.nw) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*((https?|ftp|file|blob|chrome-extension|steam):|data:image\/)/);
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|chrome-extension|steam):/);
}
}]);
mod.constant('uiAceConfig', {
ace: {
advanced: {
enableTern: {
defs: ['ecma5', 'ecma6', 'screeps'],
plugins: {
doc_comment: {
fullDocs: true
}
},
useWorker: true,
switchToDoc: function switchToDoc(name, start) {
console.log('switchToDoc called but not defined. name=' + name + '; start=', start);
},
startedCb: function startedCb() {}
},
/**
* when using tern, it takes over Ace's built in snippets support.
* this setting affects all modes when using tern, not just javascript.
*/
enableSnippets: true,
/**
* when using tern, Ace's basic text auto completion is enabled still by deafult.
* This settings affects all modes when using tern, not just javascript.
* For javascript mode the basic auto completion will be added to completion results if tern fails to find completions or if you double tab the hotkey for get completion (default is ctrl+space, so hit ctrl+space twice rapidly to include basic text completions in the result)
*/
enableBasicAutocompletion: true
}
}
});
mod.constant('AppInstanceId', new Date().getTime());
mod.constant('ResourceTypeNames', {
token: "subscription token",
energy: 'energy',
power: 'power',
H: 'hydrogen',
O: 'oxygen',
U: 'utrium',
L: 'lemergium',
K: 'keanium',
Z: 'zynthium',
X: 'catalyst',
OH: 'hydroxide',
ZK: 'zynthium keanite',
UL: 'utrium lemergite',
G: 'ghodium',
UH: 'utrium hydride',
UO: 'utrium oxide',
KH: 'keanium hydride',
KO: 'keanium oxide',
LH: 'lemergium hydride',
LO: 'lemergium oxide',
ZH: 'zynthium hydride',
ZO: 'zynthium oxide',
GH: 'ghodium hydride',
GO: 'ghodium oxide',
UH2O: 'utrium acid',
UHO2: 'utrium alkalide',
KH2O: 'keanium acid',
KHO2: 'keanium alkalide',
LH2O: 'lemergium acid',
LHO2: 'lemergium alkalide',
ZH2O: 'zynthium acid',
ZHO2: 'zynthium alkalide',
GH2O: 'ghodium acid',
GHO2: 'ghodium alkalide',
XUH2O: 'catalyzed utrium acid',
XUHO2: 'catalyzed utrium alkalide',
XKH2O: 'catalyzed keanium acid',
XKHO2: 'catalyzed keanium alkalide',
XLH2O: 'catalyzed lemergium acid',
XLHO2: 'catalyzed lemergium alkalide',
XZH2O: 'catalyzed zynthium acid',
XZHO2: 'catalyzed zynthium alkalide',
XGH2O: 'catalyzed ghodium acid',
XGHO2: 'catalyzed ghodium alkalide',
ops: 'ops',
silicon: 'silicon',
metal: 'metal',
biomass: 'biomass',
mist: 'mist',
utrium_bar: 'utrium bar',
lemergium_bar: 'lemergium bar',
zynthium_bar: 'zynthium bar',
keanium_bar: 'keanium bar',
ghodium_melt: 'ghodium melt',
oxidant: 'oxidant',
reductant: 'reductant',
purifier: 'purifier',
battery: 'battery',
composite: 'composite',
crystal: 'crystal',
liquid: 'liquid',
wire: 'wire',
switch: 'switch',
transistor: 'transistor',
microchip: 'microchip',
circuit: 'circuit',
device: 'device',
cell: 'cell',
phlegm: 'phlegm',
tissue: 'tissue',
muscle: 'muscle',
organoid: 'organoid',
organism: 'organism',
alloy: 'alloy',
tube: 'tube',
fixtures: 'fixtures',
frame: 'frame',
hydraulics: 'hydraulics',
machine: 'machine',
condensate: 'condensate',
concentrate: 'concentrate',
extract: 'extract',
spirit: 'spirit',
emanation: 'emanation',
essence: 'essence'
});
mod.run(['$routeSegment', '$rootScope', 'Socket', '$http', 'MemoryStorage', 'LocalStorage', 'Connection', 'Auth', 'Loader', '$mdAria', '$interval', '$document', '$injector', function ($routeSegment, $rootScope, Socket, $http, MemoryStorage, LocalStorage, Connection, Auth, Loader, $mdAria, $interval, $document, $injector) {
$rootScope.$routeSegment = $routeSegment;
$rootScope._ = _;
$rootScope.isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
$rootScope.Me = function () {
return Auth.Me;
};
$rootScope.Loader = Loader;
$rootScope.Math = Math;
$rootScope.isOffServer = function () {
return $injector.get('Api').options.official;
};
$rootScope.isShards = function () {
return _.some($injector.get('Api').options.serverData.shards);
};
$rootScope.isMultiShard = function () {
var serverData = $injector.get('Api').options.serverData;
return serverData.shards && serverData.shards.length > 1;
};
if (LocalStorage.get('firstVisit', false, '') === false) {
var time = new Date().getTime();
LocalStorage.put('firstVisit', time, '');
}
$interval.bindToScope = function ($scope, fn, timeout) {
var interval = $interval(fn, timeout);
$scope.$on('$destroy', function () {
return $interval.cancel(interval);
});
};
$document.bindToScope = function (scope, event, fn) {
var applyFn = function applyFn(event) {
return scope.$apply(function () {
return fn(event);
});
};
$document.bind(event, applyFn);
scope.$on('$destroy', function () {
return $document.unbind(event, applyFn);
});
};
if (window.nw) {
$rootScope.nw = true;
var greenworks = require('./greenworks');
if (!greenworks.initAPI()) {
console.error('Could not init steamworks');
}
} else {
Loader.registerPre($injector.get('Api').get('version').then(function (data) {
$injector.get('Api').options.serverData = data.serverData;
}));
}
}]);
mod.directive('appShowWhenSteamOverlay', ['$animate', '$timeout', function ($animate, $timeout) {
return {
link: function link($scope, elm, attrs) {
var active = false,
timeout;
function forceRefresh() {
if (!active) {
return;
}
setTimeout(function () {
elm[0].getContext('2d').clearRect(0, 0, 1, 1);
window.requestAnimationFrame(forceRefresh);
}, 1000 / 30);
}
function update(isVisible) {
$animate[isVisible ? 'removeClass' : 'addClass'](elm, 'ng-hide');
active = isVisible;
if (active) {
forceRefresh();
if (timeout) {
$timeout.cancel(timeout);
timeout = null;
}
}
}
var greenworks = require('./greenworks');
greenworks.on('game-overlay-activated', function (isActive) {
return $scope.$apply(function () {
if (isActive) {
update(true);
} else {
if (timeout) {
$timeout.cancel(timeout);
}
timeout = $timeout(2000);
timeout.then(function () {
if (active) {
update(false);
}
});
}
});
});
$scope.$on('$destroy', function () {
return active = false;
});
}
};
}]);
mod.directive('appCustomValidator', function () {
return {
require: 'ngModel',
link: function link($scope, elm, attrs, ngModel) {
var info = $scope.$eval(attrs.appCustomValidator);
for (var key in info) {
if (info[key]().$$state) ngModel.$asyncValidators[key] = info[key];
}
for (var key in info) {
if (!info[key]().$$state) ngModel.$validators[key] = info[key];
}
}
};
});
mod.directive('appController', function () {
return {
controller: '@',
priority: -10000
};
});
mod.directive('appAutofocus', function () {
return {
link: function link($scope, elm, attrs) {
if (!attrs.appAutofocus || $scope.$eval(attrs.appAutofocus)) setTimeout(function () {
elm.focus();
}, 100);
}
};
});
mod.directive('appSubmit', ['$parse', function ($parse) {
return {
controller: ['$scope', '$attrs', function controller($scope, $attrs) {
var _this = this;
this.loadingCnt = false;
this.recaptchaWidgetId = null;
this.onSubmit = function (recaptcha) {
$scope.$apply(function () {
_this.loadingCnt = false;
var promise = $parse($attrs.appSubmit)($scope, { $recaptcha: recaptcha });
if (promise && promise.then) {
_this.loadingCnt = true;
promise.catch(function () {
$scope.$broadcast('form fail');
})['finally'](function () {
_this.loadingCnt = false;
});
}
});
};
}],
link: function link($scope, elm, attrs, ctrl) {
elm.submit(function (event) {
event.preventDefault();
if (ctrl.recaptchaWidgetId !== null) {
grecaptcha.reset(ctrl.recaptchaWidgetId);
$scope.$apply(function () {
ctrl.loadingCnt = true;
grecaptcha.execute(ctrl.recaptchaWidgetId);
});
} else {
ctrl.onSubmit();
}
});
}
};
}]);
mod.directive('appFormFailAnim', ['$animate', function ($animate) {
return {
link: function link($scope, elm, attrs) {
$scope.$on('form fail', function () {
$animate.addClass(elm, attrs.appFormFailAnim).then(function () {
return $animate.removeClass(elm, attrs.appFormFailAnim);
});
});
}
};
}]);
mod.directive('appSubmitAnimated', function () {
return {
require: '^appSubmit',
link: function link($scope, elm, attrs, ctrl) {
$scope.$watch(function () {
return ctrl.loadingCnt;
}, function (val) {
elm.toggleClass('striped', val);
val ? elm.attr('disabled', 'disabled') : elm.removeAttr('disabled');
});
}
};
});
mod.directive('appSubmitRecaptcha', ['Recaptcha', function (Recaptcha) {
return {
require: '^appSubmit',
link: function link($scope, elm, attrs, ctrl) {
if (Recaptcha.disabled) {
return;
}
$scope.$watch(function () {
return Recaptcha.loaded;
}, function (val) {
if (!val) {
return;
}
console.log('recaptcha loaded');
ctrl.recaptchaWidgetId = grecaptcha.render(elm[0], {
sitekey: '6Lc-Q0IUAAAAACrAWi56MDdxAjK98uiNO1klxDic',
theme: 'dark',
size: 'invisible',
badge: attrs.appSubmitRecaptcha || 'bottomright',
callback: function callback(token) {
console.log('recaptcha completed', token);
ctrl.onSubmit(token);
}
});
});
}
};
}]);
mod.directive('appFocusOnEvent', function () {
return {
link: function link($scope, elm, attrs) {
$scope.$on(attrs.appFocusOnEvent, function () {
setTimeout(function () {
elm.focus();
elm.find('input, textarea').focus();
}, 100);
});
}
};
});
mod.directive('appCursorToEndOnEvent', function () {
return {
link: function link($scope, elm, attrs) {
$scope.$on(attrs.appCursorToEndOnEvent, function () {
if (elm.get(0).setSelectionRange) {
elm.get(0).setSelectionRange(elm.val().length, elm.val().length);
}
});
}
};
});
mod.directive('appStopClickPropagation', function () {
return function ($scope, element, attrs) {
element.click(function (e) {
if (attrs.appStopClickPropagation.charAt(0) == "~") {
var m = attrs.appStopClickPropagation.match(/^~(.*)$/);
if (!m[1] || $scope.$eval(m[1])) {
e.stopImmediatePropagation();
}
} else if (attrs.appStopClickPropagation == "" || $scope.$eval(attrs.appStopClickPropagation)) e.stopPropagation();
});
};
});
mod.directive('appStopPropagation', function () {
return function ($scope, element, attrs) {
element.bind(attrs.appStopPropagation, function (e) {
e.stopPropagation();
});
};
});
mod.directive('appClickAnimated', ['$parse', function ($parse) {
return {
scope: true,
link: function link($scope, element, attrs) {
element.bind('click', function (event) {
element.addClass('striped');
element.attr('disabled', 'disabled');
$scope.$apply(function () {
var resultPromise = $parse(attrs.appClickAnimated)($scope, { $event: event });
resultPromise['finally'](function () {
element.removeClass('striped');
if (attrs.ngDisabled) {
var value = $scope.$eval(attrs.ngDisabled);
value ? element.attr('disabled', 'disabled') : element.removeAttr('disabled');
} else element.removeAttr('disabled');
});
});
});
}
};
}]);
mod.directive('appOnCtrlEnter', function () {
return {
link: function link($scope, elm, attrs) {
elm.find('textarea').keydown(function (event) {
if ((event.ctrlKey || event.shiftKey) && event.keyCode == 13 || event.ctrlKey && event.keyCode == 83) {
event.preventDefault();
$scope.$apply(function () {
return $scope.$eval(attrs.appOnCtrlEnter);
});
}
});
}
};
});
mod.directive('appFacebookParse', ['$timeout', function ($timeout) {
return {
link: function link($scope, elm, attrs) {
$timeout(function () {
FB.XFBML.parse();
}, 10);
}
};
}]);
mod.directive('appAutoScrollWatch', function () {
return {
priority: 100000,
link: function link($scope, elm, attrs) {
var boundToBottom = 0;
$scope.$watch(attrs.appAutoScrollWatch, function () {
if (boundToBottom !== null) {
setTimeout(function () {
elm[0].scrollTop = elm[0].scrollHeight - elm.height() - boundToBottom;
if (boundToBottom) boundToBottom = 0;
}, 0);
}
});
elm.scroll(function () {
if (boundToBottom === 0 || boundToBottom === null) {
boundToBottom = elm[0].scrollTop == elm[0].scrollHeight - elm.height() ? 0 : null;
}
});
$scope.$on('save scroll', function () {
boundToBottom = elm[0].scrollHeight - elm.height() - elm[0].scrollTop;
});
}
};
});
mod.directive('appEnterSubmit', function () {
return {
link: function link($scope, elm) {
elm.keydown(function (event) {
if (event.keyCode == 13 && event.ctrlKey) {
$(elm.get(0).form).submit();
event.preventDefault();
}
});
}
};
});
mod.directive('appClickSelectAll', function () {
return {
link: function link($scope, elm, attrs) {
elm.click(function () {
return elm[0].select();
});
}
};
});
mod.directive('appButtonCopyInput', function () {
return {
link: function link($scope, elm, attrs) {
elm.find('button').click(function () {
elm.find('input')[0].select();
document.execCommand('copy');
});
}
};
});
mod.directive('appNwExternalLink', function () {
return {
link: function link($scope, elm, attrs) {
if (!window.nw) {
return;
}
elm.click(function (e) {
nw.Shell.openExternal(attrs.appNwExternalLink || elm.attr('href'));
e.preventDefault();
});
}
};
});
mod.filter('empty', function () {
return function (val) {
if (_.isObject(val)) {
if (_.isArray(val)) return val.length == 0;else {
for (var i in val) {
if (!_.isFunction(val[i]) && val[i] !== null && val[i] !== undefined) return false;
}return true;
}
}
return val === null || val === undefined;
};
});
mod.filter('keys', function () {
return function (value) {
return _.keys(value);
};
});
mod.filter('sort', function () {
return function (value) {
return value.sort();
};
});
mod.filter('trust', ['$sce', function ($sce) {
return function (val) {
return $sce.trustAsHtml(val);
};
}]);
mod.filter('bust', function () {
return function (val) {
return val + '?bust=__bust__';
};
});
mod.filter('readableDate', ['$locale', function ($locale) {
return function (value) {
var now = new Date();
var time = new Date(value);
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
if (time.getTime() > now.getTime() - 60 * 1000) return 'Just now';
if (time.getTime() > now.getTime() - 3600 * 1000) {
var minutesAgo = Math.round((now.getTime() - time.getTime()) / 1000 / 60);
return minutesAgo + (minutesAgo != 1 ? ' minutes ago' : ' minute ago');
}
if (time.getTime() >= today.getTime()) return 'Today at ' + time.toLocaleTimeString();
if (time.getTime() > new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0).getTime()) return 'Yesterday at ' + time.toLocaleTimeString();
if (time.getTime() > new Date(now.getFullYear(), now.getMonth(), now.getDate() - 4, 0, 0, 0).getTime()) {
var days = Math.round((today.getTime() - new Date(time.getFullYear(), time.getMonth(), time.getDate(), 0, 0, 0)) / 24 / 3600 / 1000);
return days + ' days ago';
}
return time.toLocaleDateString();
};
}]);
mod.factory('$mdAria', function () {
return {
expect: angular.noop,
expectWithText: angular.noop
};
});
mod.filter('pad', function () {
return function (val) {
if (val < 10) return '0' + val;
return val;
};
});
mod.filter('round', function () {
return function (val) {
val = Math.round(val | 0);
var log = Math.floor(Math.log10 ? Math.log10(val) : Math.log(val) / Math.LN10 + 0.00000001),
log3 = Math.floor(log / 3),
round = 100;
if (log > 3) {
if (log - log3 * 3 > 0) {
round = 10;
}
if (log - log3 * 3 > 1) {
round = 1;
}
val = Math.floor(val / Math.pow(10, 3 * log3) * round) / round;
val = "" + val;
if (val.length < 3 && !/\./.test(val)) {
val += ".0";
}
val += { 0: '', 1: 'K', 2: 'M', 3: 'B' }[log3];
}
return "" + val;
};
});
mod.filter('marked', ['$sce', function ($sce) {
function unescape(html) {
// explicitly match decimal, hex, and named HTML entities
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function (_, n) {
n = n.toLowerCase();
if (n === 'colon') return ':';
if (n.charAt(0) === '#') {
return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
}
return '';
});
}
var renderer = new marked.Renderer();
renderer.link = function (href, title, text) {
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase();
} catch (e) {
return '';
}
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
return '';
}
}
var out = '<a href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
out += 'onclick="if(window.nw) {nw.Shell.openExternal(this.href); return false;}">' + text + '</a>';
return out;
};
var options = _.extend({}, marked.defaults, { breaks: true, sanitize: true, code: true, renderer: renderer });
var lexer = new marked.Lexer(options);
var parser = new marked.Parser(options);
return function (value) {
value = parser.parse(lexer.lex(value));
return $sce.trustAsHtml(value);
};
}]);
mod.filter('truncate', function () {
return function (value, length) {
if (value.length <= length) {
return value;
}
return value.substring(0, length) + '...';
};
});
mod.filter('elapsedDays', function () {
function pad(val) {
if (val < 10) return '0' + val;
return val;
}
var filter = function filter(value) {
var elapsed = value - Date.now();
if (elapsed < 0) {
return null;
}
if (elapsed > 48 * 3600 * 1000) {
return Math.floor(elapsed / 24 / 3600 / 1000) + ' days';
} else {
return pad(Math.floor(elapsed / 60 / 60 / 1000)) + ':' + pad(Math.floor(elapsed / 60 / 1000) % 60) + ':' + pad(Math.floor(elapsed / 1000) % 60);
}
};
filter.$stateful = true;
return filter;
});
mod.filter('capitalize', function () {
return function (value) {
return value.charAt(0).toUpperCase() + value.slice(1);
};
});
mod.directive('appSpectrum', function () {
return {
link: function link($scope, elm, attrs) {
$(elm).spectrum({
preferredFormat: "hex",
showInput: true
});
$(elm).on('change.spectrum', function () {
return $scope.$apply();
});
}
};
});
mod.directive('appVisible', ['$animate', function ($animate) {
return {
restrict: 'A',
link: function link(scope, element, attr) {
scope.$watch(attr.appVisible, function (value) {
$animate[value ? 'removeClass' : 'addClass'](element, 'invisible');
});
}
};
}]);
mod.directive('appAttr', function () {
return {
link: function link($scope, elm, attrs) {
var m = attrs.appAttr.split('#');
$scope.$watch(m[1], function (val) {
return elm[0].setAttribute(m[0], val);
});
}
};
});
mod.directive("appFileInput", function () {
return {
require: "ngModel",
link: function postLink($scope, elem, attrs, ngModel) {
elem.on("change", function (e) {
var files = elem[0].files;
ngModel.$setViewValue(files);
});
$scope.$on('appFileDrop', function (event, files) {
console.log('drop', files);
ngModel.$setViewValue(files);
});
}
};
});
mod.directive('appFileDrop', function () {
return function ($scope, elm, attrs) {
elm.addClass('file-drop');
elm.on('dragenter', function (e) {
e.stopPropagation();
e.preventDefault();
elm.addClass('file-drop--active');
});
elm.on('dragover', function (e) {
e.stopPropagation();
e.preventDefault();
elm.addClass('file-drop--active');
});
elm.on('dragexit dragleave', function (e) {
elm.removeClass('file-drop--active');
});
elm.on('drop', function (e) {
e.stopPropagation();
e.preventDefault();
elm.removeClass('file-drop--active');
if (e.originalEvent.dataTransfer) {
$scope.$apply(function () {
$scope.$broadcast('appFileDrop', e.originalEvent.dataTransfer.files);
});
}
});
};
});
mod.filter('routeSegmentUrlStateless', ['$routeSegment', function ($routeSegment) {
var filter = function filter(segmentName, params) {
return $routeSegment.getSegmentUrl(segmentName, params);
};
// this is the only change from standard routeSegmentUrl:
// filter.$stateful = true;
return filter;
}]);
angular.module('ngAria', []);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangwenyan/backend.git
git@gitee.com:zhangwenyan/backend.git
zhangwenyan
backend
backend
master

搜索帮助