-
Notifications
You must be signed in to change notification settings - Fork 7
/
font-selector.js
98 lines (88 loc) · 2.67 KB
/
font-selector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var Smm = {
fontDirectory: 'font-selector/fonts/',
imageDirectory: 'font-selector/fonts/font-images/',
selectorId: 'font-selector',
visible: false //Status of font-selector
};
Smm.fonts = {
BrushScript: {
cssFile: 'BrushScript.css',
imageFile: 'brush-script.png',
loadType: 'custom',
loaded: false
},
CloisterBlackLight: {
cssFile: 'CloisterBlackLight.css',
imageFile: 'cloister.png',
loadType: 'custom',
loaded: false
},
Cooper: {
cssFile: 'Cooper.css',
imageFile: 'cooper.png',
loadType: 'custom',
loaded: false
}
};
Smm.loadFont = function(fontFace, active, loading){
console.log('Loading font: ' + fontFace);
if(Smm.fonts[fontFace]['loaded'] === false){
console.log('Font not loaded... Getting css file now');
Smm.fonts[fontFace]['loaded'] = true;
WebFont.load({
custom: {
families: [fontFace],
urls: [ Smm.fontDirectory + Smm.fonts[fontFace]['cssFile'] ]
},
loading: loading,
active: active
});
}
else {
console.log('Font already loaded, using file.');
active();
}
};
Smm.init = function(divId){
$('#tool_font_family').css('position','relative').append('<div id="font-selector"></div>');
var selector = $('#'+Smm.selectorId);
$.each(Smm.fonts, function(index,value){
selector.append('<div class="font-item" font-name="' + index + '"><img src="' + Smm.imageDirectory + value['imageFile'] + '" /></div>');
});
$("#close-selector").click(Smm.hideSelector);
$(".font-item").click(Smm.selectFont);
$('#font_family_dropdown button').unbind('mousedown').bind('mousedown',function(event){
if (Smm.visible === false) {
Smm.showSelector();
} else {
Smm.hideSelector();
}
});
$(window).mouseup(function(evt) {
if(!Smm.visible === true) {
Smm.hideSelector();
}
Smm.visible = false;
});
$('#'+Smm.selectorId).mouseup(function(){
Smm.showSelector();
});
};
Smm.showSelector = function(){
$('#'+Smm.selectorId).show();
Smm.visible = true;
};
Smm.hideSelector = function(){
$('#'+Smm.selectorId).hide();
Smm.visible = false;
};
Smm.selectFont = function(){
var font = $(this).attr('font-name');
var active = function(){
svgCanvas.setFontFamily(font);
};
var loading = function(){
};
Smm.loadFont(font, active, loading);
Smm.hideSelector();
}