Skip to content

Commit fc6c564

Browse files
committed
Translations support, ability to hide tools
1 parent 48b3a2c commit fc6c564

9 files changed

Lines changed: 60 additions & 15 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ Configuration
110110
|`backgroundFillColor` | Default background color when image created/erased | "#ffffff" |
111111
|`defaultFontSize` | Default font size in pixels | 24 |
112112
|`defaultSize` | default image size, should be string in format `<width>x<height>` in pixel, e.g. `'200x100'`. If value is `'fill'`(default) than all container size will be used | `'fill'` |
113+
|`hiddenTools` | List of tools that you do not want to see in Painterro
114+
e.g. something of this list `['crop', 'line', 'rect', 'ellipse', 'brush', 'text', 'rotate', 'resize', 'save', 'open', 'close']` | [] |
113115

114116
UI color scheme
115117
===============
@@ -138,6 +140,25 @@ Painterro({
138140
|`backgroundColor`| Background color of component area which left outside of image due to it size/ratio | '#999999' |
139141
|`dragOverBarColor`| Color of bar when dropping file to painterro | '#899dff' |
140142

143+
144+
Translation
145+
-----------
146+
147+
If you want to translate or change strings you can du this by passing `translation` parameter
148+
149+
```js
150+
Painterro({
151+
translation: {
152+
name: 'ua',
153+
strings: {
154+
apply: 'Застосувати'
155+
}
156+
}
157+
}).show()
158+
```
159+
For all values that can be translated see `js/translation.js`
160+
161+
141162
Saving image
142163
============
143164

build/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
// }
4545
// });
4646

47-
Painterro().show();
47+
Painterro({
48+
49+
}).show();
4850
</script>
4951
</body>
5052
</html>

css/styles.css

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@
186186
font-family: "Open Sans", sans-serif;
187187
font-size: 10px;
188188
float: right;
189-
padding: 4px 4px 4px 0;
190-
position: absolute;
191-
right: 110px;
192-
bottom: 0;
189+
padding: 22px 4px 4px 0;
193190
}
194191

195192
.ptro-wrapper .ptro-color-widget-wrapper,
@@ -236,6 +233,7 @@
236233
text-align: right;
237234
padding-right: 5px;
238235
float: none !important;
236+
font-size: 14px;
239237
}
240238

241239
.ptro-wrapper .ptro-color-edit {
@@ -261,6 +259,8 @@
261259
.ptro-wrapper .ptro-color-edit input.ptro-color-alpha {
262260
font-size: 14px;
263261
width: 55px;
262+
padding: 0 0 0 2px;
263+
line-height: 23px;
264264
}
265265

266266
.ptro-wrapper .ptro-color-alpha-label,
@@ -279,6 +279,9 @@
279279
margin: 0;
280280
}
281281

282+
.ptro-wrapper .ptro-color-edit button i {
283+
line-height: 16px;
284+
}
282285

283286
.ptro-wrapper .ptro-color-edit button:active {
284287
outline: none;

js/colorPicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,12 @@ export class ColorPicker {
257257
'<i class="ptro-icon ptro-icon-pipette"></i>' +
258258
'</button>' +
259259
'<input class="ptro-color" type="text" size="7"/>' +
260-
`<span style="float:right"><span class="ptro-color-alpha-label" title="${Translation.get().tr('alphaFull')}">${Translation.get().tr('alpha')}</span>` +
260+
`<span style="float:right"><span class="ptro-color-alpha-label" ` +
261+
`title="${Translation.get().tr('alphaFull')}">${Translation.get().tr('alpha')}</span>` +
261262
'<input class="ptro-color-alpha ptro-input" type="number" min="0" max="1" step="0.1"/></span>' +
262263
'<div><button class="ptro-named-btn ptro-close ptro-color-control" ' +
263-
'style="margin-top: 8px;position: absolute; top: 225px; right: 10px;width: 50px;">Close</button></div>' +
264+
'style="margin-top: 8px;position: absolute; top: 225px; right: 10px;width: 50px;">'+
265+
`${Translation.get().tr('close')}</button></div>` +
264266
'</div>' +
265267
'</div>' +
266268
'</div>' +

js/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PainterroProc {
2525
constructor(params) {
2626
addDocumentObjectHelpers();
2727
this.params = setDefaults(params);
28+
2829
this.tools = [{
2930
name: 'crop',
3031
activate: () => {
@@ -332,6 +333,7 @@ class PainterroProc {
332333
this.hide();
333334
},
334335
},];
336+
335337
this.activeTool = undefined;
336338
this.zoom = false;
337339
this.ratioRelation = undefined;
@@ -351,7 +353,7 @@ class PainterroProc {
351353
}
352354
let bar = '';
353355
let rightBar = '';
354-
for(let b of this.tools) {
356+
for(let b of this.tools.filter((t) => !this.params.hiddenTools.includes(t.name))) {
355357
const id = genId();
356358
b.buttonId = id;
357359
const btn = `<button class="ptro-icon-btn ptro-color-control" title="${tr('tools.'+b.name)}" `+
@@ -377,8 +379,8 @@ class PainterroProc {
377379
'<div class="ptro-bar ptro-color-main">' +
378380
'<span>' + bar + '</span>' +
379381
'<span class="tool-controls"></span>' +
380-
'<span class="ptro-info"></span>' +
381382
'<span class="ptro-bar-right">' + rightBar + '</span>' +
383+
'<span class="ptro-info"></span>' +
382384
'<input id="ptro-file-input" type="file" style="display: none;" accept="image/x-png,image/gif,image/jpeg" />' +
383385
'</div>' +
384386
`<style>${this.params.styles}</style>`;
@@ -431,7 +433,7 @@ class PainterroProc {
431433
}
432434
};
433435

434-
for(let b of this.tools) {
436+
for(let b of this.tools.filter((t) => !this.params.hiddenTools.includes(t.name))) {
435437
this._getBtnEl(b).onclick = () => {
436438
const currentActive = this.activeTool;
437439
this.closeActiveTool();

js/params.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HexToRGBA } from './colorPicker';
2+
import { Translation } from './translation';
23

34
export function setDefaults(params) {
45
params = params || {};
@@ -13,6 +14,7 @@ export function setDefaults(params) {
1314
params.defaultLineWidth = params.defaultLineWidth || 5;
1415
params.defaultFontSize = params.defaultFontSize || 24;
1516
params.backgroundFillColor = params.backgroundFillColor || "#ffffff";
17+
params.hiddenTools = params.hiddenTools || [];
1618

1719
params.colorScheme = params.colorScheme || {};
1820
params.colorScheme.main = params.colorScheme.main || "#dbebff";
@@ -40,6 +42,12 @@ export function setDefaults(params) {
4042
}
4143
}
4244

45+
if (params.translation) {
46+
const name = params.translation.name;
47+
Translation.get().addTranslation(name, params.translation.strings)
48+
Translation.get().activate(name)
49+
}
50+
4351
params.styles =
4452
`.ptro-color-main{background-color: ${params.colorScheme.main}}
4553
.ptro-color-control{

js/resizer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,15 @@ export class Resizer {
9393
'<table>' +
9494
'<tr>'+
9595
`<td class="ptro-label ptro-resize-table-left">${Translation.get().tr("width")}</td>` +
96-
'<td><input class="ptro-input ptro-resize-width-input" type="number" min="0" max="3000" step="1"/></span></td>' +
96+
'<td>' +
97+
'<input class="ptro-input ptro-resize-width-input" type="number" min="0" max="3000" step="1"/>' +
98+
'</td>' +
9799
'</tr>' +
98100
'<tr>'+
99101
`<td class="ptro-label ptro-resize-table-left">${Translation.get().tr("height")}</td>` +
100-
'<td><input class="ptro-input ptro-resize-heigth-input" type="number" min="0" max="3000" step="1"/></span></td>' +
102+
'<td>' +
103+
'<input class="ptro-input ptro-resize-heigth-input" type="number" min="0" max="3000" step="1"/>' +
104+
'</td>' +
101105
'</tr>' +
102106
'</table>' +
103107
'</div>' +
@@ -108,9 +112,11 @@ export class Resizer {
108112
'</div>' +
109113
'<div>' +
110114
'<button class="ptro-named-btn ptro-apply ptro-color-control" ' +
111-
'style="margin-top: 8px;position: absolute; top: 95px; right: 75px;width: 50px;">Apply</button></div>' +
115+
'style="margin-top: 8px;position: absolute; top: 95px; right: 75px;">' +
116+
`${Translation.get().tr("apply")}</button></div>` +
112117
'<button class="ptro-named-btn ptro-close ptro-color-control" ' +
113-
'style="margin-top: 8px;position: absolute; top: 95px; right: 10px;width: 55px;">Cancel</button></div>' +
118+
'style="margin-top: 8px;position: absolute; top: 95px; right: 10px;">'+
119+
`${Translation.get().tr("cancel")}</button></div>` +
114120
'</div>' +
115121
'</div>';
116122
}

js/translation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class Translation {
2121
fontNameFull: 'Font name',
2222
apply: 'Apply',
2323
cancel: 'Cancel',
24+
close: 'Close',
2425
width: 'Width',
2526
height: 'Height',
2627
keepRatio: 'Keep width/height ratio',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "painterro",
3-
"version": "0.1.9",
3+
"version": "0.2.0",
44
"description": "Embуedded html image editor",
55
"main": "build/painterro.commonjs2.js",
66
"scripts": {

0 commit comments

Comments
 (0)