- Created reusable utility modules:
* static/js/utils/stringUtils.js - string operations (esc, norm, escAttr, truncate, getInitials)
* static/js/utils/timing.js - timing utilities (debounce, throttle, delay, poll, once)
* static/js/utils/scroll.js - scroll helpers (smoothScrollTo, scrollToTop, isElementInViewport, etc.)
- Updated static/js/utils/index.js:
* Exports all utilities from a single entry point
* Provides centralized access to all utility functions
- Modified base.html:
* Removed inline esc() and norm() function definitions
* Added ES6 module imports for utilities
* Exported utilities to window for backward compatibility
* All existing code continues to work without changes
Benefits:
- Eliminates code duplication (esc/norm found in 9 templates)
- Centralizes utility functions for easier maintenance
- Enables future improvements (testing, optimization)
- Maintains backward compatibility with existing templates
Tests: All 12 static file tests passing ✅
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
/**
|
||
* JavaScript Utilities Index
|
||
*
|
||
* Этот файл служит единой точкой входа для всех JS утилит.
|
||
* Экспортирует все утилиты для удобного импорта.
|
||
*
|
||
* Использование в шаблонах:
|
||
* <script type="module">
|
||
* import { esc, norm, debounce } from '{% static "js/utils/index.js" %}';
|
||
* </script>
|
||
*
|
||
* Или импорт конкретной утилиты:
|
||
* import { esc } from '{% static "js/utils/stringUtils.js" %}';
|
||
*/
|
||
|
||
// Утилиты работы со строками
|
||
export {
|
||
esc,
|
||
norm,
|
||
escAttr,
|
||
truncate,
|
||
getInitials
|
||
} from './stringUtils.js';
|
||
|
||
// Утилиты для работы со временем
|
||
export {
|
||
debounce,
|
||
throttle,
|
||
delay,
|
||
poll,
|
||
once
|
||
} from './timing.js';
|
||
|
||
// Утилиты прокрутки
|
||
export {
|
||
smoothScrollTo,
|
||
scrollToTop,
|
||
scrollToBottom,
|
||
isElementInViewport,
|
||
getScrollPosition,
|
||
onScrollThreshold
|
||
} from './scroll.js';
|
||
|
||
// Версия утилит
|
||
export const UTILS_VERSION = '1.0.0';
|