mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-11-02 21:41:28 +08:00
Move reload button into hidden class
This commit is contained in:
67
client/controls.js
vendored
67
client/controls.js
vendored
@ -1,7 +1,3 @@
|
||||
var BATCH_SIZE = 64;
|
||||
var CODEPOINTS = [0x4e00, 0x9fff];
|
||||
var FONT_LOADED_PROGRESS = 0.1;
|
||||
|
||||
Session.setDefault('controls.show_editor', false);
|
||||
|
||||
Template.content.helpers({
|
||||
@ -17,44 +13,7 @@ Template.controls.events({
|
||||
'click #restore-button': function() {
|
||||
Meteor.call('restore');
|
||||
},
|
||||
'click #reload-button': function() {
|
||||
Session.set('progress.value', 0);
|
||||
opentype.load('external/gkai00mp.ttf', function(err, font) {
|
||||
if (err) {
|
||||
console.log('Error loading font: ' + err);
|
||||
return;
|
||||
}
|
||||
Session.set('progress.value', FONT_LOADED_PROGRESS);
|
||||
var glyphs_to_save = [];
|
||||
for (var i = 0; i < font.glyphs.length; i++) {
|
||||
var glyph = font.glyphs.glyphs[i];
|
||||
if (CODEPOINTS[0] <= glyph.unicode && glyph.unicode <= CODEPOINTS[1]) {
|
||||
var name = 'uni' + glyph.unicode.toString(16).toUpperCase();
|
||||
glyphs_to_save.push({name: name, path: glyph.path.commands});
|
||||
}
|
||||
}
|
||||
save_glyphs(glyphs_to_save);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function save_glyphs(glyphs, index) {
|
||||
index = index || 0;
|
||||
if (index >= glyphs.length) {
|
||||
Session.set('progress.value', undefined);
|
||||
return;
|
||||
}
|
||||
var remainder = (1 - FONT_LOADED_PROGRESS)*index/glyphs.length;
|
||||
Session.set('progress.value', remainder + FONT_LOADED_PROGRESS);
|
||||
var max = Math.min(index + BATCH_SIZE, glyphs.length);
|
||||
var batch = [];
|
||||
for (var i = index; i < max; i++) {
|
||||
batch.push(glyphs[i]);
|
||||
}
|
||||
Meteor.call('save_glyphs', batch, function(err, result) {
|
||||
Meteor.setTimeout(function() { save_glyphs(glyphs, max); }, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Template.navbar.helpers({
|
||||
mode: function() {
|
||||
@ -72,29 +31,3 @@ Template.navbar.helpers({
|
||||
return Math.round(100*(value === undefined ? 0 : value));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Template.progress.helpers({
|
||||
percent: function() {
|
||||
var value = Session.get('progress.value');
|
||||
return Math.round(100*(value === undefined ? 1 : value));
|
||||
},
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
if (Session.get('progress.show')) {
|
||||
$('#progress').modal({background: 'static', keyboard: false});
|
||||
} else {
|
||||
$('#progress').modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
var progress = Session.get('progress.value');
|
||||
Session.set('progress.show', progress !== undefined);
|
||||
});
|
||||
|
||||
Meteor.startup(function() {
|
||||
Session.set('progress.show', false);
|
||||
Session.set('progress.value', undefined);
|
||||
});
|
||||
|
||||
@ -60,7 +60,6 @@
|
||||
<div id="right-controls" class="btn-group" role="group">
|
||||
<button id="backup-button" class="btn btn-success">Backup</button>
|
||||
<button id="restore-button" class="btn btn-info">Restore</button>
|
||||
<button id="reload-button" class="btn btn-warning">Reload</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
68
client/reload.js
Normal file
68
client/reload.js
Normal file
@ -0,0 +1,68 @@
|
||||
var BATCH_SIZE = 64;
|
||||
var CODEPOINTS = [0x4e00, 0x9fff];
|
||||
var FONT_LOADED_PROGRESS = 0.1;
|
||||
|
||||
Template.controls.events({
|
||||
'click #reload-button': function() {
|
||||
Session.set('progress.value', 0);
|
||||
opentype.load('external/gkai00mp.ttf', function(err, font) {
|
||||
if (err) {
|
||||
console.log('Error loading font: ' + err);
|
||||
return;
|
||||
}
|
||||
Session.set('progress.value', FONT_LOADED_PROGRESS);
|
||||
var glyphs_to_save = [];
|
||||
for (var i = 0; i < font.glyphs.length; i++) {
|
||||
var glyph = font.glyphs.glyphs[i];
|
||||
if (CODEPOINTS[0] <= glyph.unicode && glyph.unicode <= CODEPOINTS[1]) {
|
||||
var name = 'uni' + glyph.unicode.toString(16).toUpperCase();
|
||||
glyphs_to_save.push({name: name, path: glyph.path.commands});
|
||||
}
|
||||
}
|
||||
save_glyphs(glyphs_to_save);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function save_glyphs(glyphs, index) {
|
||||
index = index || 0;
|
||||
if (index >= glyphs.length) {
|
||||
Session.set('progress.value', undefined);
|
||||
return;
|
||||
}
|
||||
var remainder = (1 - FONT_LOADED_PROGRESS)*index/glyphs.length;
|
||||
Session.set('progress.value', remainder + FONT_LOADED_PROGRESS);
|
||||
var max = Math.min(index + BATCH_SIZE, glyphs.length);
|
||||
var batch = [];
|
||||
for (var i = index; i < max; i++) {
|
||||
batch.push(glyphs[i]);
|
||||
}
|
||||
Meteor.call('save_glyphs', batch, function(err, result) {
|
||||
Meteor.setTimeout(function() { save_glyphs(glyphs, max); }, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Template.progress.helpers({
|
||||
percent: function() {
|
||||
var value = Session.get('progress.value');
|
||||
return Math.round(100*(value === undefined ? 1 : value));
|
||||
},
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
if (Session.get('progress.show')) {
|
||||
$('#progress').modal({background: 'static', keyboard: false});
|
||||
} else {
|
||||
$('#progress').modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
Tracker.autorun(function() {
|
||||
var progress = Session.get('progress.value');
|
||||
Session.set('progress.show', progress !== undefined);
|
||||
});
|
||||
|
||||
Meteor.startup(function() {
|
||||
Session.set('progress.show', false);
|
||||
Session.set('progress.value', undefined);
|
||||
});
|
||||
Reference in New Issue
Block a user