123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- define("webodf/editor/widgets/paragraphStyles", [
- "dijit/form/Select",
- "dojox/html/entities",
- "webodf/editor/EditorSession"],
- function (Select, htmlEntities, EditorSession) {
- "use strict";
-
- var ParagraphStyles = function (callback) {
- var self = this,
- editorSession,
- select,
- defaultStyleUIId = ":default";
- this.widget = function () {
- return select;
- };
-
- this.value = function () {
- var value = select.get('value');
- if (value === defaultStyleUIId) {
- value = "";
- }
- return value;
- };
- this.setValue = function (value) {
- if (value === "") {
- value = defaultStyleUIId;
- }
- select.set('value', value, false);
- };
-
- this.onAdd = null;
- this.onRemove = null;
-
- this.onChange = function () {};
-
- function populateStyles() {
- var i, selectionList, availableStyles;
-
- selectionList = [{
- label: runtime.tr("Default Style"),
- value: defaultStyleUIId
- }];
- availableStyles = editorSession ? editorSession.getAvailableParagraphStyles() : [];
- for (i = 0; i < availableStyles.length; i += 1) {
- selectionList.push({
- label: htmlEntities.encode(availableStyles[i].displayName) || htmlEntities.encode(availableStyles[i].name),
- value: availableStyles[i].name
- });
- }
- select.removeOption(select.getOptions());
- select.addOption(selectionList);
- }
- function addStyle(styleInfo) {
- var stylens = "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
- newStyleElement;
- if (styleInfo.family !== 'paragraph') {
- return;
- }
- newStyleElement = editorSession.getParagraphStyleElement(styleInfo.name);
- select.addOption({
- label: htmlEntities.encode(newStyleElement.getAttributeNS(stylens, 'display-name')),
- value: styleInfo.name
- });
- if (self.onAdd) {
- self.onAdd(styleInfo.name);
- }
- }
- function removeStyle(styleInfo) {
- if (styleInfo.family !== 'paragraph') {
- return;
- }
- select.removeOption(styleInfo.name);
- if (self.onRemove) {
- self.onRemove(styleInfo.name);
- }
- }
- function handleCursorMoved(cursor) {
- var disabled = cursor.getSelectionType() === ops.OdtCursor.RegionSelection;
- select.setAttribute('disabled', disabled);
- }
- this.setEditorSession = function(session) {
- if (editorSession) {
- editorSession.unsubscribe(EditorSession.signalCommonStyleCreated, addStyle);
- editorSession.unsubscribe(EditorSession.signalCommonStyleDeleted, removeStyle);
- editorSession.unsubscribe(EditorSession.signalCursorMoved, handleCursorMoved);
- }
- editorSession = session;
- if (editorSession) {
- editorSession.subscribe(EditorSession.signalCommonStyleCreated, addStyle);
- editorSession.subscribe(EditorSession.signalCommonStyleDeleted, removeStyle);
- editorSession.subscribe(EditorSession.signalCursorMoved, handleCursorMoved);
- }
- select.setAttribute('disabled', !editorSession);
- populateStyles();
- };
-
- function init() {
- select = new Select({
- name: 'ParagraphStyles',
- maxHeight: 200,
- style: {
- width: '100px'
- }
- });
-
- select.domNode.setAttribute("translate", "no");
- select.domNode.classList.add("notranslate");
- select.dropDown.domNode.setAttribute("translate", "no");
- select.dropDown.domNode.classList.add("notranslate");
- populateStyles();
-
-
-
-
-
- select.onChange = function () {
- self.onChange(self.value());
- };
- return callback(self);
- }
- init();
- };
- return ParagraphStyles;
- });
|