mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-62497 javascript: fix truncate.js
There was some code in the charLengthAt function which was requiring that the "this" context not be null however it was unnecessary because it never uses "this" and for some reason it was being set to null after the ES6 transpiling.
This commit is contained in:
parent
195ea4480b
commit
78610b53c7
2
lib/amd/build/truncate.min.js
vendored
2
lib/amd/build/truncate.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("core/truncate",["jquery"],function(a){var b=/(\s*\S+|\s)$/,c=/^(\S*)/,d=/\s/,e=function(a,b){if(null==this){throw TypeError()}var c=a+"",d=c.length,e=b?+b:0;if(e!=e){e=0}if(-1>=e||e>=d){return""}e=0|e;var f=c.charCodeAt(e),g,h=e+1,i=1;if(55296<=f&&56319>=f&&d>h){g=c.charCodeAt(h);if(56320<=g&&57343>=g){i=2}}return i},f=function(a){for(var b=0,c=0;c<a.length;c+=e(a,c)){b++}return b},g=function(a,b){if(!a.length){return 0}var c=0,d=0;do{c+=e(a,c);d++}while(c<a.length&&d<b);return c};a.truncate=function(b,c){return a("<div></div>").append(b).truncate(c).html()};a.fn.truncate=function(e){if(!isNaN(parseFloat(e)))e={length:e};var h=a.extend({},a.truncate.defaults,e);return this.each(function(){var e=a(this);if(h.noBreaks)e.find("br").replaceWith(" ");var j=h.ellipsis.length,k=e.text(),l=f(k),m=l-h.length+j;if(l<h.length)return;if(h.stripTags)e.text(k);if(h.words&&0<m){var n=k.slice(0,g(k,h.length-j)+1),o=n.replace(b,""),p=f(o),q=n.match(d)?!1:!0;if(h.keepFirstWord&&0===p){m=l-f(c.exec(k)[0])-j}else if(q&&0===p){m=l-h.length+j}else{m=l-p-1}}if(m>l){m=l-h.length}if(0>m||!m&&!h.truncated)return;a.each(e.contents().get().reverse(),function(b,c){var d=a(c),e=d.text(),i=f(e);if(i<=m){h.truncated=!0;m-=i;d.remove();return}if(3===c.nodeType){var k=i-m;k=0<=k?g(e,k):0;a(c.splitText(k)).replaceWith(h.ellipsis);return!1}d.truncate(a.extend(h,{length:i-m+j}));return!1})})};a.truncate.defaults={stripTags:!1,words:!1,keepFirstWord:!1,noBreaks:!1,length:1/0,ellipsis:"\u2026"};return{truncate:a.truncate}});
|
||||
define ("core/truncate",["jquery"],function(a){var b=/(\s*\S+|\s)$/,c=/^(\S*)/,d=/\s/,e=function(a,b){var c=a+"",d=c.length,e=b?+b:0;if(e!=e){e=0}if(-1>=e||e>=d){return""}e=0|e;var f=c.charCodeAt(e),g,h=e+1,i=1;if(55296<=f&&56319>=f&&d>h){g=c.charCodeAt(h);if(56320<=g&&57343>=g){i=2}}return i},f=function(a){for(var b=0,c=0;c<a.length;c+=e(a,c)){b++}return b},g=function(a,b){if(!a.length){return 0}var c=0,d=0;do{c+=e(a,c);d++}while(c<a.length&&d<b);return c};a.truncate=function(b,c){return a("<div></div>").append(b).truncate(c).html()};a.fn.truncate=function(e){if(!isNaN(parseFloat(e)))e={length:e};var h=a.extend({},a.truncate.defaults,e);return this.each(function(){var e=a(this);if(h.noBreaks)e.find("br").replaceWith(" ");var j=h.ellipsis.length,k=e.text(),l=f(k),m=l-h.length+j;if(l<h.length)return;if(h.stripTags)e.text(k);if(h.words&&0<m){var n=k.slice(0,g(k,h.length-j)+1),o=n.replace(b,""),p=f(o),q=n.match(d)?!1:!0;if(h.keepFirstWord&&0===p){m=l-f(c.exec(k)[0])-j}else if(q&&0===p){m=l-h.length+j}else{m=l-p-1}}if(m>l){m=l-h.length}if(0>m||!m&&!h.truncated)return;a.each(e.contents().get().reverse(),function(b,c){var d=a(c),e=d.text(),i=f(e);if(i<=m){h.truncated=!0;m-=i;d.remove();return}if(3===c.nodeType){var k=i-m;k=0<=k?g(e,k):0;a(c.splitText(k)).replaceWith(h.ellipsis);return!1}d.truncate(a.extend(h,{length:i-m+j}));return!1})})};a.truncate.defaults={stripTags:!1,words:!1,keepFirstWord:!1,noBreaks:!1,length:1/0,ellipsis:"\u2026"};return{truncate:a.truncate}});
|
||||
//# sourceMappingURL=truncate.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -50,9 +50,6 @@ define(['jquery'], function($) {
|
||||
// implementation. Much love.
|
||||
// see: https://github.com/mathiasbynens/String.prototype.at/blob/master/at.js
|
||||
var charLengthAt = function(text, position) {
|
||||
if (this == null) {
|
||||
throw TypeError();
|
||||
}
|
||||
var string = String(text);
|
||||
var size = string.length;
|
||||
// `ToInteger`
|
||||
|
Loading…
x
Reference in New Issue
Block a user