Skip to content

Commit

Permalink
no pollute prototype (#28262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ycw committed May 3, 2024
1 parent f91fe5f commit a980f81
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
6 changes: 0 additions & 6 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@
window.URL = window.URL || window.webkitURL;
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;

Number.prototype.format = function () {

return this.toString().replace( /(\d)(?=(\d{3})+(?!\d))/g, '$1,' );

};

//

const editor = new Editor();
Expand Down
9 changes: 8 additions & 1 deletion editor/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ Editor.prototype = {

save: save,
saveArrayBuffer: saveArrayBuffer,
saveString: saveString
saveString: saveString,
formatNumber: formatNumber

}

Expand Down Expand Up @@ -788,4 +789,10 @@ function saveString( text, filename ) {

}

function formatNumber( number ) {

return new Intl.NumberFormat( 'en-us', { useGrouping: true } ).format( number );

}

export { Editor };
2 changes: 1 addition & 1 deletion editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Loader( editor ) {
const reader = new FileReader();
reader.addEventListener( 'progress', function ( event ) {

const size = '(' + Math.floor( event.total / 1000 ).format() + ' KB)';
const size = '(' + editor.utils.formatNumber( Math.floor( event.total / 1000 ) ) + ' KB)';
const progress = Math.floor( ( event.loaded / event.total ) * 100 ) + '%';

console.log( 'Loading', filename, size, progress );
Expand Down
6 changes: 3 additions & 3 deletions editor/js/Sidebar.Geometry.BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function SidebarGeometryBufferGeometry( editor ) {
if ( index !== null ) {

containerAttributes.add( new UIText( strings.getKey( 'sidebar/geometry/buffer_geometry/index' ) ).setWidth( '80px' ) );
containerAttributes.add( new UIText( ( index.count ).format() ).setFontSize( '12px' ) );
containerAttributes.add( new UIText( editor.utils.formatNumber( index.count ) ).setFontSize( '12px' ) );
containerAttributes.add( new UIBreak() );

}
Expand All @@ -47,7 +47,7 @@ function SidebarGeometryBufferGeometry( editor ) {
const attribute = attributes[ name ];

containerAttributes.add( new UIText( name ).setWidth( '80px' ) );
containerAttributes.add( new UIText( ( attribute.count ).format() + ' (' + attribute.itemSize + ')' ).setFontSize( '12px' ) );
containerAttributes.add( new UIText( editor.utils.formatNumber( attribute.count ) + ' (' + attribute.itemSize + ')' ).setFontSize( '12px' ) );
containerAttributes.add( new UIBreak() );

}
Expand Down Expand Up @@ -76,7 +76,7 @@ function SidebarGeometryBufferGeometry( editor ) {
const morphTargets = morphAttributes[ name ];

containerMorphAttributes.add( new UIText( name ).setWidth( '80px' ) );
containerMorphAttributes.add( new UIText( ( morphTargets.length ).format() ).setFontSize( '12px' ) );
containerMorphAttributes.add( new UIText( editor.utils.formatNumber( morphTargets.length ) ).setFontSize( '12px' ) );
containerMorphAttributes.add( new UIBreak() );

}
Expand Down
6 changes: 3 additions & 3 deletions editor/js/Viewport.Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function ViewportInfo( editor ) {

}

objectsText.setValue( objects.format() );
verticesText.setValue( vertices.format() );
trianglesText.setValue( triangles.format() );
objectsText.setValue( editor.utils.formatNumber( objects ) );
verticesText.setValue( editor.utils.formatNumber( vertices ) );
trianglesText.setValue( editor.utils.formatNumber( triangles ) );

const pluralRules = new Intl.PluralRules( editor.config.getKey( 'language' ) );

Expand Down

0 comments on commit a980f81

Please sign in to comment.