|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | exports.type = 'perItem';
|
|---|
| 4 |
|
|---|
| 5 | exports.active = true;
|
|---|
| 6 |
|
|---|
| 7 | exports.description = 'cleanups attributes from newlines, trailing and repeating spaces';
|
|---|
| 8 |
|
|---|
| 9 | exports.params = {
|
|---|
| 10 | newlines: true,
|
|---|
| 11 | trim: true,
|
|---|
| 12 | spaces: true
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | var regNewlinesNeedSpace = /(\S)\r?\n(\S)/g,
|
|---|
| 16 | regNewlines = /\r?\n/g,
|
|---|
| 17 | regSpaces = /\s{2,}/g;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Cleanup attributes values from newlines, trailing and repeating spaces.
|
|---|
| 21 | *
|
|---|
| 22 | * @param {Object} item current iteration item
|
|---|
| 23 | * @param {Object} params plugin params
|
|---|
| 24 | * @return {Boolean} if false, item will be filtered out
|
|---|
| 25 | *
|
|---|
| 26 | * @author Kir Belevich
|
|---|
| 27 | */
|
|---|
| 28 | exports.fn = function(item, params) {
|
|---|
| 29 |
|
|---|
| 30 | if (item.isElem()) {
|
|---|
| 31 |
|
|---|
| 32 | item.eachAttr(function(attr) {
|
|---|
| 33 |
|
|---|
| 34 | if (params.newlines) {
|
|---|
| 35 | // new line which requires a space instead of themselve
|
|---|
| 36 | attr.value = attr.value.replace(regNewlinesNeedSpace, function(match, p1, p2) {
|
|---|
| 37 | return p1 + ' ' + p2;
|
|---|
| 38 | });
|
|---|
| 39 |
|
|---|
| 40 | // simple new line
|
|---|
| 41 | attr.value = attr.value.replace(regNewlines, '');
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | if (params.trim) {
|
|---|
| 45 | attr.value = attr.value.trim();
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | if (params.spaces) {
|
|---|
| 49 | attr.value = attr.value.replace(regSpaces, ' ');
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | });
|
|---|
| 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.