Ma Liming 3 weeks ago
committed by GitHub
parent
commit
c8fce7d4d5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      docs/en/framework/ui/mvc-razor-pages/bundling-minification.md
  2. 2
      docs/en/framework/ui/mvc-razor-pages/overall.md
  3. 2
      docs/en/framework/ui/mvc-razor-pages/theming.md
  4. 6
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs
  5. 17
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs
  6. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js
  7. 6
      npm/packs/timeago/abp.resourcemapping.js
  8. 2
      npm/packs/timeago/package.json
  9. 164
      npm/packs/timeago/src/abp.timeago.js

2
docs/en/framework/ui/mvc-razor-pages/bundling-minification.md

@ -386,7 +386,7 @@ Configure<AbpBundlingOptions>(options =>
````html
<link rel="preload" href="/__bundles/Basic.Global.F4FA61F368098407A4C972D0A6914137.css?_v=637697363694828051" as="style" onload="this.rel='stylesheet'"/>
<script defer src="/libs/timeago/locales/jquery.timeago.en.js?_v=637674729040000000"></script>
<script defer src="/libs/timeago/timeago.full.min.js?_v=637674729040000000"></script>
````
### External/CDN file Support

2
docs/en/framework/ui/mvc-razor-pages/overall.md

@ -63,7 +63,7 @@ There are a set of standard JavaScript/CSS libraries that comes pre-installed an
- [JQuery Form](https://github.com/jquery-form/form) for AJAX forms.
- [bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) to show date pickers.
- [Select2](https://select2.org/) for better select/combo boxes.
- [Timeago](http://timeago.yarp.com/) to show automatically updating fuzzy timestamps.
- [timeago.js](https://timeago.org/) to show automatically updating fuzzy timestamps.
- [malihu-custom-scrollbar-plugin](https://github.com/malihu/malihu-custom-scrollbar-plugin) for custom scrollbars.
You can use these libraries directly in your applications, without needing to manually import your page.

2
docs/en/framework/ui/mvc-razor-pages/theming.md

@ -50,7 +50,7 @@ All the themes must depend on the [@abp/aspnetcore.mvc.ui.theme.shared](https://
* [JQuery Form](https://github.com/jquery-form/form) for AJAX forms.
* [bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) to show date pickers.
* [Select2](https://select2.org/) for better select/combo boxes.
* [Timeago](http://timeago.yarp.com/) to show automatically updating fuzzy timestamps.
* [timeago.js](https://timeago.org/) to show automatically updating fuzzy timestamps.
* [malihu-custom-scrollbar-plugin](https://github.com/malihu/malihu-custom-scrollbar-plugin) for custom scrollbars.
These libraries are selected as the base libraries and available to the applications and modules.

6
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs

@ -2,7 +2,6 @@
using Volo.Abp.AspNetCore.Mvc.UI.Packages.BootstrapDatepicker;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.Moment;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
@ -38,11 +37,6 @@ public class AbpAspNetCoreMvcUiPackagesModule : AbpModule
new NameValue("zh-Hant", "zh-tw"),
new NameValue("de-DE", "de"));
//Timeago
options.AddLanguageFilesMapOrUpdate(TimeagoScriptContributor.PackageName,
new NameValue("zh-Hans", "zh-CN"),
new NameValue("zh-Hant", "zh-TW"));
//JQueryValidation
options.AddLanguageFilesMapOrUpdate(JQueryValidationScriptContributor.PackageName,
new NameValue("zh-Hans", "zh"),

17
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs

@ -1,8 +1,6 @@
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQuery;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago;
@ -10,20 +8,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago;
[DependsOn(typeof(JQueryScriptContributor))]
public class TimeagoScriptContributor : BundleContributor
{
public const string PackageName = "jquery.timeago";
public override void ConfigureBundle(BundleConfigurationContext context)
{
context.Files.AddIfNotContains("/libs/timeago/jquery.timeago.js");
}
public override void ConfigureDynamicResources(BundleConfigurationContext context)
{
var fileName = context.LazyServiceProvider.LazyGetRequiredService<IOptions<AbpLocalizationOptions>>().Value.GetCurrentUICultureLanguageFilesMap(PackageName);
var filePath = $"/libs/timeago/locales/jquery.timeago.{fileName}.js";
if (context.FileProvider.GetFileInfo(filePath).Exists)
{
context.Files.Add(filePath);
}
context.Files.AddIfNotContains("/libs/timeago/timeago.full.min.js");
context.Files.AddIfNotContains("/libs/abp/timeago/abp.timeago.js");
}
}

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js

@ -72,7 +72,7 @@
}
abp.dom.initializers.initializeTimeAgos = function ($timeagos) {
$timeagos.timeago();
abp.timeago.render($timeagos.toArray());
}
abp.dom.initializers.initializeAutocompleteSelects = function ($autocompleteSelects) {
@ -217,6 +217,7 @@
args.$el.findWithSelf('[data-bs-toggle="tooltip"]').each(function () {
$('#' + $(this).attr('aria-describedby')).remove();
});
abp.timeago.cancel(args.$el.findWithSelf('[timeago-id]').toArray());
});
abp.event.on('abp.configurationInitialized', function () {

6
npm/packs/timeago/abp.resourcemapping.js

@ -1,6 +1,6 @@
module.exports = {
mappings: {
"@node_modules/timeago/jquery.timeago.js": "@libs/timeago/",
"@node_modules/timeago/locales/*.*": "@libs/timeago/locales/"
"@node_modules/timeago.js/dist/*.js": "@libs/timeago/",
"@node_modules/@abp/timeago/src/*.*": "@libs/abp/timeago/"
}
}
}

2
npm/packs/timeago/package.json

@ -11,7 +11,7 @@
},
"dependencies": {
"@abp/jquery": "~10.7.0-rc.3",
"timeago": "^1.6.7"
"timeago.js": "^4.0.2"
},
"gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431",
"homepage": "https://abp.io",

164
npm/packs/timeago/src/abp.timeago.js

@ -0,0 +1,164 @@
var abp = abp || {};
(function ($) {
if (typeof timeago === 'undefined') {
throw "abp/timeago library requires the timeago.js library included to the page!";
}
abp.timeago = abp.timeago || {};
// ABP culture name -> timeago.js locale name (only the ones that don't match the two-letter language code)
abp.timeago.localeMap = {
'en': 'en_US',
'zh': 'zh_CN',
'zh-Hans': 'zh_CN',
'zh-Hant': 'zh_TW',
'zh-CN': 'zh_CN',
'zh-TW': 'zh_TW',
'pt': 'pt_BR',
'nb': 'nb_NO',
'no': 'nb_NO',
'nn': 'nn_NO',
'hi': 'hi_IN',
'id': 'id_ID',
'bn': 'bn_IN'
};
abp.timeago.getLocale = function (cultureName) {
cultureName = cultureName || (abp.localization && abp.localization.currentCulture && abp.localization.currentCulture.cultureName) || 'en';
if (abp.timeago.localeMap[cultureName]) {
return abp.timeago.localeMap[cultureName];
}
var language = cultureName.split('-')[0];
return abp.timeago.localeMap[language] || language;
};
abp.timeago.format = function (date, options) {
return timeago.format(date, abp.timeago.getLocale(), options);
};
var toNodeList = function (nodes) {
if (!nodes) {
return [];
}
return Array.prototype.filter.call(nodes.nodeType ? [nodes] : nodes, function (node) {
return node && node.getAttribute;
});
};
// <time> elements carry the date in the "datetime" attribute, other elements may carry it in "title"
var getDateAttribute = function (node) {
var datetime = node.getAttribute('datetime');
if (datetime || node.tagName === 'TIME') {
return datetime;
}
return node.getAttribute('title');
};
abp.timeago.render = function (nodes, options) {
var nodeList = toNodeList(nodes).filter(function (node) {
var datetime = getDateAttribute(node);
if (!datetime) {
return false;
}
node.setAttribute('datetime', datetime);
return true;
});
if (!nodeList.length) {
return nodeList;
}
return timeago.render(nodeList, abp.timeago.getLocale(), options);
};
abp.timeago.cancel = function (nodes) {
if (nodes === undefined) {
timeago.cancel();
return;
}
toNodeList(nodes).forEach(function (node) {
timeago.cancel(node);
});
};
// Locales that ship with ABP's default languages but are missing in timeago.full.min.js
var slavicIndex = function (number, index) {
return (index % 2 === 1 && number >= 5) ? 1 : 0;
};
timeago.register('cs', function (number, index) {
return [
[['právě teď', 'právě teď']],
[['před %s vteřinami', 'za %s vteřiny'], ['před %s vteřinami', 'za %s vteřin']],
[['před minutou', 'za minutu']],
[['před %s minutami', 'za %s minuty'], ['před %s minutami', 'za %s minut']],
[['před hodinou', 'za hodinu']],
[['před %s hodinami', 'za %s hodiny'], ['před %s hodinami', 'za %s hodin']],
[['včera', 'zítra']],
[['před %s dny', 'za %s dny'], ['před %s dny', 'za %s dnů']],
[['minulý týden', 'příští týden']],
[['před %s týdny', 'za %s týdny'], ['před %s týdny', 'za %s týdnů']],
[['minulý měsíc', 'příští měsíc']],
[['před %s měsíci', 'za %s měsíce'], ['před %s měsíci', 'za %s měsíců']],
[['před rokem', 'příští rok']],
[['před %s lety', 'za %s roky'], ['před %s lety', 'za %s let']]
][index][slavicIndex(number, index)];
});
timeago.register('sk', function (number, index) {
return [
[['práve teraz', 'práve teraz']],
[['pred %s sekundami', 'o %s sekundy'], ['pred %s sekundami', 'o %s sekúnd']],
[['pred minútou', 'o minútu']],
[['pred %s minútami', 'o %s minúty'], ['pred %s minútami', 'o %s minút']],
[['pred hodinou', 'o hodinu']],
[['pred %s hodinami', 'o %s hodiny'], ['pred %s hodinami', 'o %s hodín']],
[['pred %s dňom', 'o %s deň']],
[['pred %s dňami', 'o %s dni'], ['pred %s dňami', 'o %s dní']],
[['pred %s týždňom', 'o %s týždeň']],
[['pred %s týždňami', 'o %s týždne'], ['pred %s týždňami', 'o %s týždňov']],
[['pred %s mesiacom', 'o %s mesiac']],
[['pred %s mesiacmi', 'o %s mesiace'], ['pred %s mesiacmi', 'o %s mesiacov']],
[['pred %s rokom', 'o %s rok']],
[['pred %s rokmi', 'o %s roky'], ['pred %s rokmi', 'o %s rokov']]
][index][slavicIndex(number, index)];
});
if (!$) {
return;
}
$.timeago = function (date) {
if (date && date.jquery) {
date = date[0];
}
if (date && date.nodeType === 1) {
date = getDateAttribute(date);
}
return abp.timeago.format(date);
};
$.fn.timeago = function (action, options) {
if (action === 'dispose') {
abp.timeago.cancel(this.toArray());
return this;
}
if (action === 'update' && options !== undefined && options !== null) {
this.attr('datetime', options instanceof Date ? options.toISOString() : options);
}
abp.timeago.render(this.toArray());
return this;
};
})(window.jQuery);
Loading…
Cancel
Save