123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- define("webodf/editor/widgets/fontPicker", [
- "dijit/form/Select",
- "dojox/html/entities"],
- function (Select, htmlEntities) {
- "use strict";
-
- var FontPicker = function (callback) {
- var self = this,
- editorSession,
- select,
- documentFonts = [];
- select = new Select({
- name: 'FontPicker',
- disabled: true,
- maxHeight: 200,
- style: {
- width: '150px'
- }
- });
-
- select.domNode.setAttribute("translate", "no");
- select.domNode.classList.add("notranslate");
- select.dropDown.domNode.setAttribute("translate", "no");
- select.dropDown.domNode.classList.add("notranslate");
- this.widget = function () {
- return select;
- };
- this.value = function () {
- return select.get('value');
- };
- this.setValue = function (value) {
- select.set('value', value);
- };
-
- this.getFamily = function (name) {
- var i;
- for (i = 0; i < documentFonts.length; i += 1) {
- if ((documentFonts[i].name === name) && documentFonts[i].family) {
- return documentFonts[i].family;
- }
- }
- return name;
- };
-
- this.onAdd = null;
- this.onRemove = null;
- function populateFonts() {
- var i,
- name,
- family,
- editorFonts = editorSession ? editorSession.availableFonts : [],
- selectionList = [];
- documentFonts = editorSession ? editorSession.getDeclaredFonts() : [];
-
- for (i = 0; i < documentFonts.length; i += 1) {
- name = documentFonts[i].name;
- family = documentFonts[i].family || name;
- selectionList.push({
- label: '<span style="font-family: ' + htmlEntities.encode(family) + ';">' + htmlEntities.encode(name)+ '</span>',
- value: name
- });
- }
- if (editorFonts.length) {
-
- selectionList.push({
- type: 'separator'
- });
- }
-
- for (i = 0; i < editorFonts.length; i += 1) {
- selectionList.push({
- label: '<span style="font-family: ' + htmlEntities.encode(editorFonts[i]) + ';">' + htmlEntities.encode(editorFonts[i]) + '</span>',
- value: editorFonts[i]
- });
- }
- select.removeOption(select.getOptions());
- select.addOption(selectionList);
- }
- this.setEditorSession = function(session) {
- editorSession = session;
- populateFonts();
- select.setAttribute('disabled', !editorSession);
- };
- populateFonts();
- callback(self);
- };
- return FontPicker;
- });
|