mathjax.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. CKEDITOR.dialog.add( 'asciisvg', function( editor ) {
  2. var lang = editor.lang.asciisvg;
  3. function getValues(dialog) {
  4. var dialogContents = dialog.definition.contents[0];
  5. var pageId = dialogContents.id;
  6. var dialogFieldValues = {};
  7. for (var i = 0; i < dialogContents.elements.length-1; i++) {
  8. for (var j = 0; j < dialogContents.elements[i].children.length; j++) {
  9. var fieldId = dialogContents.elements[i].children[j].id;
  10. if (isNaN(dialog.getValueOf(pageId, fieldId))) {
  11. dialogFieldValues[fieldId] = dialog.getValueOf(pageId, fieldId);
  12. } else {
  13. dialogFieldValues[fieldId] = Number(dialog.getValueOf(pageId, fieldId));
  14. }
  15. }
  16. }
  17. stroke = dialogFieldValues.color;
  18. strokewidth = dialogFieldValues.width;
  19. strokedasharray = dialogFieldValues.line;
  20. xmin = dialogFieldValues.xmin;
  21. xmax = dialogFieldValues.xmax;
  22. xscl = dialogFieldValues.xscl;
  23. ymin = dialogFieldValues.ymin;
  24. ymax = dialogFieldValues.ymax;
  25. yscl = dialogFieldValues.yscl;
  26. width = dialogFieldValues.resizeTo;
  27. height = dialogFieldValues.by;
  28. return dialogFieldValues;
  29. }
  30. function updateFields(control) {
  31. var dialog = control.getDialog();
  32. var pageId = (dialog.definition.contents[0]).id;
  33. var equationTypeField = dialog.getContentElement(pageId, 'equationType');
  34. var equationField = dialog.getContentElement(pageId, 'equation');
  35. var extraField = dialog.getContentElement(pageId, 'extraField');
  36. var extraFieldIsVisible = extraField.getElement().isVisible();
  37. var value = control.getValue();
  38. if (value.indexOf(',') > -1) {
  39. value = value.split(',');
  40. } else {
  41. value = [value];
  42. }
  43. var found = false;
  44. var i = 0;
  45. while (found === false && i < equationTypeField.items.length) {
  46. if (equationTypeField.items[i][1] === value[0]) {
  47. found = true;
  48. } else {
  49. i++;
  50. }
  51. }
  52. equationTypeField.getInputElement().$.selectedIndex = i;
  53. switch (value[0]) {
  54. case 'func':
  55. if (extraFieldIsVisible === true) {
  56. extraField.getElement().hide();
  57. }
  58. equationField.setLabel(lang.FOfX);
  59. dialog.setValueOf(pageId, 'equation', lang.SinOfX);
  60. break;
  61. case 'polar':
  62. if (extraFieldIsVisible === true) {
  63. extraField.getElement().hide();
  64. }
  65. equationField.setLabel(lang.ROfT);
  66. dialog.setValueOf(pageId, 'equation', lang.T);
  67. break;
  68. case 'param':
  69. equationField.setLabel(lang.FOfT);
  70. dialog.setValueOf(pageId, 'equation', lang.SinOfT);
  71. extraField.setLabel(lang.GOfT);
  72. dialog.setValueOf(pageId, 'extraField', lang.CosOfT);
  73. if (extraFieldIsVisible === false) {
  74. extraField.getElement().show();
  75. }
  76. break;
  77. case 'slope':
  78. equationField.setLabel(lang.DySplitDxOfXAndY);
  79. dialog.setValueOf(pageId, 'equation', lang.XByY);
  80. extraField.setLabel(lang.Every);
  81. dialog.setValueOf(pageId, 'extraField', '1');
  82. if (extraFieldIsVisible === false) {
  83. extraField.getElement().show();
  84. }
  85. break;
  86. case 'label':
  87. if (extraFieldIsVisible === true) {
  88. extraField.getElement().hide();
  89. }
  90. equationField.setLabel(lang.Label);
  91. dialog.setValueOf(pageId, 'equation', lang.Text);
  92. break;
  93. }
  94. var fromField = dialog.getContentElement(pageId, 'from');
  95. var toField = dialog.getContentElement(pageId, 'to');
  96. if (value[0] === 'label') {
  97. fromField.setLabel(lang.XPosition);
  98. toField.setLabel(lang.YPosition);
  99. dialog.setValueOf(pageId, 'from', '0');
  100. dialog.setValueOf(pageId, 'to', '0');
  101. } else {
  102. fromField.setLabel(lang.From);
  103. toField.setLabel(lang.To);
  104. dialog.setValueOf(pageId, 'from', '-7.5');
  105. dialog.setValueOf(pageId, 'to', '7.5');
  106. }
  107. if (value.length > 1) {
  108. dialog.setValueOf(pageId, 'startWith', value[3]);
  109. dialog.setValueOf(pageId, 'endWith', value[4]);
  110. dialog.setValueOf(pageId, 'from', value[5]);
  111. dialog.setValueOf(pageId, 'to', value[6]);
  112. dialog.setValueOf(pageId, 'color', value[7]);
  113. dialog.setValueOf(pageId, 'width', value[8]);
  114. dialog.setValueOf(pageId, 'line', value[9]);
  115. } else {
  116. var fieldsToDefault = ['color','width','line','startWith','endWith'];
  117. for (var i = 0; i < fieldsToDefault.length; i++) {
  118. dialog.setValueOf(pageId, fieldsToDefault[i], dialog.getContentElement(pageId, fieldsToDefault[i]).default);
  119. }
  120. }
  121. }
  122. function addGraph(dialog) {
  123. var pageId = (dialog.definition.contents[0]).id;
  124. var equationTypeField = dialog.getContentElement(pageId, 'equationType');
  125. var selectedIndex = equationTypeField.getInputElement().$.selectedIndex;
  126. var equationType = [equationTypeField.items[selectedIndex][0]];
  127. var equation = [dialog.getValueOf(pageId, 'equation')];
  128. var graphEquation = [[],[]];
  129. // Check if there is more than one equal sign (more than one equation type)
  130. if (equationType[0].split('=').length - 1 > 1) {
  131. equationType = equationType[0].split(',');
  132. var extraField = dialog.getValueOf(pageId, 'extraField');
  133. equation = [equation[0], extraField];
  134. }
  135. // Store left and right parts of the graph equations
  136. for (var i = 0; i < equationType.length; i++) {
  137. // Left part of the graph equations
  138. if (equationType[0].indexOf('=') > -1) {
  139. graphEquation[0][i] = equationType[i].substring(0, equationType[i].indexOf('='));
  140. } else {
  141. graphEquation[0][i] = equationType[i];
  142. }
  143. // Right part of the graph equations
  144. graphEquation[1][i] = equation[i];
  145. }
  146. // Convert graphEquation arrays to strings separated by commas
  147. graphEquation[0] = graphEquation[0].join();
  148. graphEquation[1] = graphEquation[1].join();
  149. // Add square brackets if there is more than one equation type
  150. if (equationType.length > 1) {
  151. graphEquation = '['+graphEquation[0]+']=['+graphEquation[1]+']';
  152. } else {
  153. graphEquation = graphEquation[0]+'='+graphEquation[1];
  154. equation = equation[0];
  155. }
  156. var graphsField = dialog.getContentElement(pageId, 'graphs');
  157. // Add graph equation to graphs select
  158. var values = getValues(dialog);
  159. graphsField.items.push(graphEquation);
  160. var sscr = values.equationType+','+values.equation+','+values.extraField+','+values.startWith+','+values.endWith+','+values.from+','+values.to+','+values.color+','+values.width+','+values.line;
  161. graphsField.add(graphEquation, sscr);
  162. sscr = xmin+','+xmax+','+ymin+','+ymax+','+xscl+','+yscl+','+(xscl||yscl)+','+xgrid+','+ygrid+','+width+','+height;
  163. var graphsFieldLastIndex = graphsField.getInputElement().$.options.length-1;
  164. graphsField.getInputElement().$.selectedIndex = graphsFieldLastIndex;
  165. picture.sscr = sscr;
  166. switch(values.equationType) {
  167. case 'func':
  168. var functionCall = values.equation;
  169. plot(functionCall, values.from, values.to, null, null, values.startWith, values.endWith);
  170. break;
  171. case 'polar':
  172. var functionCall = ["cos(t)*("+values.equation+")","sin(t)*("+values.equation+")"];
  173. plot(functionCall, values.from, values.to, null, null, values.startWith, values.endWith);
  174. break;
  175. case 'param':
  176. var functionCall = [values.equation, values.extraField];
  177. plot(functionCall, values.from, values.to, null, null, values.startWith, values.endWith);
  178. break;
  179. case 'slope':
  180. slopefield(values.equation, values.extraField, values.extraField);
  181. plot(null, values.from, values.to, null, null, values.startWith, values.endWith);
  182. break;
  183. case 'label':
  184. text([values.from, values.to], values.equation);
  185. break;
  186. }
  187. }
  188. function removeSelectedGraph(dialog) {
  189. var pageId = (dialog.definition.contents[0]).id;
  190. var graphsField = dialog.getContentElement(pageId, 'graphs');
  191. var selectedIndex = graphsField.getInputElement().$.selectedIndex;
  192. graphsField.items.splice(selectedIndex, 1);
  193. graphsField.remove(selectedIndex);
  194. }
  195. function updateGraphs(dialog) {
  196. initialized = false;
  197. var sscr = xmin+','+xmax+','+ymin+','+ymax+','+xscl+','+yscl+','+(xscl||yscl)+','+xgrid+','+ygrid;
  198. picture.sscr = sscr;
  199. parseShortScript(sscr, width, height);
  200. var pageId = (dialog.definition.contents[0]).id;
  201. var graphsField = dialog.getContentElement(pageId, 'graphs');
  202. for (var i = 0; i < graphsField.items.length; i++) {
  203. var values = (graphsField.getInputElement().$.options[i].getAttribute('value')).split(',');
  204. stroke = values[7];
  205. strokewidth = values[8];
  206. strokedasharray = values[9];
  207. for (var j = 0; j < values.length; j++) {
  208. if (!isNaN(values[j])) {
  209. values[j] = Number(values[j]);
  210. }
  211. }
  212. switch(values[0]) {
  213. case 'func':
  214. var functionCall = values[1];
  215. plot(functionCall, values[5], values[6], null, null, values[3], values[4]);
  216. break;
  217. case 'polar':
  218. var functionCall = ["cos(t)*("+values[1]+")","sin(t)*("+values[1]+")"];
  219. plot(functionCall, values[5], values[6], null, null, values[3], values[4]);
  220. break;
  221. case 'param':
  222. var functionCall = [values[1], values[2]];
  223. plot(functionCall, values[5], values[6], null, null, values[3], values[4]);
  224. break;
  225. case 'slope':
  226. slopefield(values[1], values[2], values[2]);
  227. plot(null, values[5], values[6], null, null, values[3], values[4]);
  228. break;
  229. case 'label':
  230. text([values[5], values[6]], values[1]);
  231. break;
  232. }
  233. }
  234. }
  235. return {
  236. title: lang.GraphEditor,
  237. minWidth: 350,
  238. minHeight: 100,
  239. contents: [
  240. {
  241. id: 'info',
  242. elements: [
  243. {
  244. type: 'hbox',
  245. widths: ['20%', '20%', '20%', '20%', '20%'],
  246. children: [
  247. {
  248. id: 'equationType',
  249. type: 'select',
  250. label: lang.EquationType,
  251. items: [
  252. [lang.YEqualsFOfX, 'func'],
  253. [lang.REqualsFOfT, 'polar'],
  254. [lang.XEqualsFOfTCommaYEqualsGOfT, 'param'],
  255. [lang.DySplitDxEqualsFOfXAndY, 'slope'],
  256. [lang.Label, 'label']
  257. ],
  258. default: 'func',
  259. onChange: function (api) {
  260. updateFields(this);
  261. }
  262. },
  263. {
  264. id: 'equation',
  265. type: 'text',
  266. label: lang.FOfX,
  267. default: lang.XSquared
  268. },
  269. {
  270. id: 'extraField',
  271. type: 'text',
  272. label: '',
  273. default: ''
  274. },
  275. {
  276. id: 'from',
  277. type: 'text',
  278. label: lang.From,
  279. default: '-7.5'
  280. },
  281. {
  282. id: 'to',
  283. type: 'text',
  284. label: lang.To,
  285. default: '7.5'
  286. }
  287. ]
  288. },
  289. {
  290. type: 'hbox',
  291. widths: ['20%', '20%', '20%', '20%', '20%'],
  292. children: [
  293. {
  294. id: 'color',
  295. type: 'select',
  296. label: lang.Color,
  297. items: [
  298. [lang.Black, 'black'],
  299. [lang.Red, 'red'],
  300. [lang.Orange, 'orange'],
  301. [lang.Yellow, 'yellow'],
  302. [lang.Green, 'green'],
  303. [lang.Blue, 'blue'],
  304. [lang.Purple, 'purple']
  305. ],
  306. default: 'black'
  307. },
  308. {
  309. id: 'width',
  310. type: 'select',
  311. label: lang.Width,
  312. items: [
  313. ['1'],
  314. ['2'],
  315. ['3'],
  316. ['4']
  317. ],
  318. default: '1'
  319. },
  320. {
  321. id: 'line',
  322. type: 'select',
  323. label: lang.Line,
  324. items: [
  325. [lang.Solid, '0'],
  326. [lang.Dotted, '1'],
  327. [lang.Dashed, '2'],
  328. [lang.TightDash, '3'],
  329. [lang.DashDot, '4']
  330. ],
  331. default: '0'
  332. },
  333. {
  334. id: 'startWith',
  335. type: 'select',
  336. label: lang.StartWith,
  337. items: [
  338. [lang.None, '0'],
  339. [lang.Arrow, '1'],
  340. [lang.OpenDot, '2'],
  341. [lang.Dot, '3']
  342. ],
  343. default: '0'
  344. },
  345. {
  346. id: 'endWith',
  347. type: 'select',
  348. label: lang.EndWith,
  349. items: [
  350. [lang.None, '0'],
  351. [lang.Arrow, '1'],
  352. [lang.OpenDot, '2'],
  353. [lang.Dot, '3']
  354. ],
  355. default: '0'
  356. }
  357. ]
  358. },
  359. {
  360. type: 'hbox',
  361. widths: ['17%', '17%', '16%', '17%', '17%', '16%'],
  362. children: [
  363. {
  364. id: 'xmin',
  365. type: 'text',
  366. label: lang.XMin,
  367. default: '-7.5'
  368. },
  369. {
  370. id: 'xmax',
  371. type: 'text',
  372. label: lang.XMax,
  373. default: '7.5'
  374. },
  375. {
  376. id: 'xscl',
  377. type: 'text',
  378. label: lang.XScl,
  379. default: '1'
  380. },
  381. {
  382. id: 'ymin',
  383. type: 'text',
  384. label: lang.YMin,
  385. default: '-5'
  386. },
  387. {
  388. id: 'ymax',
  389. type: 'text',
  390. label: lang.YMax,
  391. default: '5'
  392. },
  393. {
  394. id: 'yscl',
  395. type: 'text',
  396. label: lang.YScl,
  397. default: '1'
  398. }
  399. ]
  400. },
  401. {
  402. type: 'hbox',
  403. widths: ['20%', '20%', '20%', '20%', '20%'],
  404. children: [
  405. {
  406. type: 'checkbox',
  407. id: 'showAxisLabels',
  408. label: lang.ShowAxisLabels,
  409. default: 'checked',
  410. onClick: function() {
  411. if (this.getValue()) {
  412. xscl = 1;
  413. xtick = 1;
  414. yscl = 1;
  415. ytick = 1;
  416. } else {
  417. xscl = null;
  418. xtick = null;
  419. yscl = null;
  420. ytick = null;
  421. }
  422. updateGraphs(this.getDialog());
  423. }
  424. },
  425. {
  426. type: 'checkbox',
  427. id: 'showXYGrid',
  428. label: lang.ShowXYGrid,
  429. default: 'checked',
  430. onClick: function() {
  431. if (this.getValue()) {
  432. xgrid = 1;
  433. ygrid = 1;
  434. } else {
  435. xgrid = 0;
  436. ygrid = 0;
  437. }
  438. updateGraphs(this.getDialog());
  439. }
  440. },
  441. {
  442. id: 'resizeTo',
  443. type: 'text',
  444. label: lang.ResizeTo,
  445. default: defaultwidth
  446. },
  447. {
  448. id: 'by',
  449. type: 'text',
  450. label: lang.By,
  451. default: defaultheight
  452. },
  453. {
  454. type: 'button',
  455. id: 'update',
  456. label: lang.Update,
  457. title: lang.Update,
  458. onClick: function() {
  459. var dialog = this.getDialog();
  460. var pageId = (dialog.definition.contents[0]).id;
  461. width = dialog.getValueOf(pageId, 'resizeTo');
  462. height = dialog.getValueOf(pageId, 'by');
  463. updateGraphs(dialog);
  464. }
  465. }
  466. ]
  467. },
  468. {
  469. type: 'hbox',
  470. widths: ['20%', '20%', '20%', '20%', '20%'],
  471. children: [
  472. {
  473. type: 'button',
  474. id: 'addGraph',
  475. label: lang.AddGraph,
  476. title: lang.AddGraph,
  477. onClick: function() {
  478. addGraph(this.getDialog());
  479. }
  480. },
  481. {
  482. id: 'graphs',
  483. type: 'select',
  484. label: lang.Graphs,
  485. items: [],
  486. onChange: function (api) {
  487. updateFields(this);
  488. }
  489. },
  490. {
  491. type: 'button',
  492. id: 'replaceSelectedGraph',
  493. label: lang.ReplaceSelectedGraph,
  494. title: lang.ReplaceSelectedGraph,
  495. onClick: function() {
  496. removeSelectedGraph(this.getDialog());
  497. updateGraphs(this.getDialog());
  498. addGraph(this.getDialog());
  499. }
  500. },
  501. {
  502. type: 'button',
  503. id: 'remove',
  504. label: lang.Remove,
  505. title: lang.Remove,
  506. onClick: function() {
  507. removeSelectedGraph(this.getDialog());
  508. updateGraphs(this.getDialog());
  509. }
  510. },
  511. {
  512. id: 'position',
  513. type: 'select',
  514. label: lang.Position,
  515. items: [
  516. [lang.Top, 'top'],
  517. [lang.Middle, 'middle'],
  518. [lang.Bottom, 'bottom'],
  519. [lang.FloatLeft, 'floatLeft'],
  520. [lang.FloatRight, 'floatRight']
  521. ],
  522. default: 'middle',
  523. onChange: function (api) {
  524. var currentStyle = picture.attributes.style.value;
  525. var regExpPattern = /vertical-align:\s?(\w|-)+/;
  526. var verticalAlignValue = (regExpPattern.exec(currentStyle))[0];
  527. var regExpPattern = /float:\s?\w+/;
  528. var floatValue = (regExpPattern.exec(currentStyle))[0];
  529. switch(this.getValue()) {
  530. case 'top':
  531. currentStyle = currentStyle.replace(verticalAlignValue, 'vertical-align: text-top');
  532. currentStyle = currentStyle.replace(floatValue, 'float: none');
  533. break;
  534. case 'middle':
  535. currentStyle = currentStyle.replace(verticalAlignValue, 'vertical-align: middle');
  536. currentStyle = currentStyle.replace(floatValue, 'float: none');
  537. break;
  538. case 'bottom':
  539. currentStyle = currentStyle.replace(verticalAlignValue, 'vertical-align: text-bottom');
  540. currentStyle = currentStyle.replace(floatValue, 'float: none');
  541. break;
  542. case 'floatLeft':
  543. currentStyle = currentStyle.replace(verticalAlignValue, 'vertical-align: middle');
  544. currentStyle = currentStyle.replace(floatValue, 'float: left');
  545. break;
  546. case 'floatRight':
  547. currentStyle = currentStyle.replace(verticalAlignValue, 'vertical-align: middle');
  548. currentStyle = currentStyle.replace(floatValue, 'float: right');
  549. break;
  550. }
  551. picture.attributes.style.value = currentStyle;
  552. }
  553. }
  554. ]
  555. },
  556. {
  557. id: 'preview',
  558. type: 'html',
  559. html: '<embed ' +
  560. 'type="image/svg+xml" ' +
  561. 'src="' + CKEDITOR.plugins.getPath('asciisvg') + 'd.svg" ' +
  562. 'style="width:300px; height:200px; ' +
  563. 'vertical-align:middle; float:none;" sscr="-7.5,7.5,-5,5,1,1,1,1,1,'+defaultwidth+','+defaultheight+'" />',
  564. onShow: function( widget ) {
  565. xmin = -7.5;
  566. xmax = 7.5;
  567. ymin = -5;
  568. ymax = 5;
  569. xscl = 1;
  570. yscl = 1;
  571. xgrid = 1;
  572. ygrid = 1;
  573. xtick = 1;
  574. ytick = 1;
  575. width = defaultwidth;
  576. height = defaultheight;
  577. drawPics();
  578. var dialog = this.getDialog();
  579. var pageId = (dialog.definition.contents[0]).id;
  580. var fieldsToDefault = ['equationType','equation','color','width','line','startWith','endWith'];
  581. for (var i = 0; i < fieldsToDefault.length; i++) {
  582. dialog.setValueOf(pageId, fieldsToDefault[i], dialog.getContentElement(pageId, fieldsToDefault[i]).default);
  583. }
  584. var extraField = dialog.getContentElement(pageId,'extraField');
  585. extraField.getElement().hide();
  586. var graphsField = dialog.getContentElement(pageId, 'graphs');
  587. var graphData = null;
  588. graphsField.clear();
  589. graphsField.items = [];
  590. if (graphData !== editor.getSelection().getSelectedElement()) {
  591. graphData = (editor.getSelection().getSelectedElement().$.attributes[0].value).split(',');
  592. for (var i = 11; i < graphData.length; i+=10) {
  593. var graphEquation = '';
  594. switch(graphData[i]) {
  595. case 'func':
  596. graphEquation = 'y='+graphData[i+1];
  597. break;
  598. case 'polar':
  599. graphEquation = 'r='+graphData[i+1];
  600. break;
  601. case 'param':
  602. graphEquation = '[x,y]=['+graphData[i+1]+','+graphData[i+2]+']';
  603. break;
  604. case 'slope':
  605. graphEquation = 'dx/dy='+graphData[i+1];
  606. break;
  607. case 'label':
  608. graphEquation = lang.Label+'='+graphData[i+1];
  609. break;
  610. }
  611. graphsField.items.push(graphEquation);
  612. var sscr = graphData[i]+','+graphData[i+1]+','+graphData[i+2]+','+graphData[i+3]+','+graphData[i+4]+','+graphData[i+5]+','+graphData[i+6]+','+graphData[i+7]+','+graphData[i+8]+','+graphData[i+9];
  613. graphsField.add(graphEquation, sscr);
  614. }
  615. xmin = graphData[0];
  616. dialog.setValueOf(pageId, 'xmin', xmin);
  617. xmax = graphData[1];
  618. dialog.setValueOf(pageId, 'xmax', xmax);
  619. ymin = graphData[2];
  620. dialog.setValueOf(pageId, 'ymin', ymin);
  621. ymax = graphData[3];
  622. dialog.setValueOf(pageId, 'ymax', ymax);
  623. if (graphData[6] === 'null') {
  624. dialog.setValueOf(pageId, 'showAxisLabels', null);
  625. xscl = null;
  626. xtick = null;
  627. yscl = null;
  628. ytick = null;
  629. } else {
  630. xscl = 1;
  631. xtick = 1;
  632. yscl = 1;
  633. ytick = 1;
  634. }
  635. if ((graphData[7]||graphData[8]) === '0') {
  636. dialog.setValueOf(pageId, 'showXYGrid', null);
  637. xgrid = 0;
  638. ygrid = 0;
  639. } else {
  640. xgrid = 1;
  641. ygrid = 1;
  642. }
  643. width = graphData[9];
  644. dialog.setValueOf(pageId, 'resizeTo', width);
  645. height = graphData[10];
  646. dialog.setValueOf(pageId, 'by', height);
  647. updateGraphs(dialog);
  648. }
  649. else {
  650. updateGraphs(dialog);
  651. addGraph(dialog);
  652. }
  653. },
  654. commit : function(data)
  655. {
  656. var dialog = this.getDialog();
  657. var pageId = (dialog.definition.contents[0]).id;
  658. var previewField = dialog.getContentElement(pageId,this.id);
  659. var sscr = xmin+','+xmax+','+ymin+','+ymax+','+xscl+','+yscl+','+(xscl||yscl)+','+xgrid+','+ygrid+','+width+','+height;
  660. var graphsField = dialog.getContentElement(pageId, 'graphs');
  661. for (var i = 0; i < graphsField.items.length; i++) {
  662. sscr += ','+graphsField.getInputElement().$.options[i].getAttribute('value');
  663. }
  664. picture.sscr = sscr;
  665. data.preview = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+width+'" height="'+height+'">'+previewField.getInputElement().$.innerHTML+'</svg>';
  666. }
  667. }
  668. ]
  669. }
  670. ],
  671. onOk: function( widget ) {
  672. var data = {};
  673. this.commitContent(data);
  674. var currentStyle = picture.attributes.style.value;
  675. var regExpPattern = /vertical-align:\s?(\w|-)+/;
  676. var verticalAlignValue = (regExpPattern.exec(currentStyle))[0];
  677. var regExpPattern = /float:\s?\w+/;
  678. var floatValue = (regExpPattern.exec(currentStyle))[0];
  679. var imgElement = '<img src="data:image/svg+xml;base64,'+btoa(data.preview)+'" style="'+verticalAlignValue+';'+floatValue+'" sscr="'+picture.sscr+'" />';
  680. picture.sscr = '-7.5,7.5,-5,5,1,1,1,1,1,'+defaultwidth+','+defaultheight;
  681. var element = CKEDITOR.dom.element.createFromHtml(imgElement);
  682. editor.insertElement(element);
  683. }
  684. };
  685. } );