InlineEditBox.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. require({cache:{
  2. 'url:dijit/templates/InlineEditBox.html':"<span data-dojo-attach-point=\"editNode\" role=\"presentation\" style=\"position: absolute; visibility:hidden\" class=\"dijitReset dijitInline\"\n\tdata-dojo-attach-event=\"onkeypress: _onKeyPress\"\n\t><span data-dojo-attach-point=\"editorPlaceholder\"></span\n\t><span data-dojo-attach-point=\"buttonContainer\"\n\t\t><button data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"label: '${buttonSave}', 'class': 'saveButton'\"\n\t\t\tdata-dojo-attach-point=\"saveButton\" data-dojo-attach-event=\"onClick:save\"></button\n\t\t><button data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"label: '${buttonCancel}', 'class': 'cancelButton'\"\n\t\t\tdata-dojo-attach-point=\"cancelButton\" data-dojo-attach-event=\"onClick:cancel\"></button\n\t></span\n></span>\n"}});
  3. define("dijit/InlineEditBox", [
  4. "dojo/_base/array", // array.forEach
  5. "dojo/_base/declare", // declare
  6. "dojo/_base/Deferred", // Deferred.when
  7. "dojo/dom-attr", // domAttr.set domAttr.get
  8. "dojo/dom-class", // domClass.add domClass.remove domClass.toggle
  9. "dojo/dom-construct", // domConstruct.create domConstruct.destroy
  10. "dojo/dom-style", // domStyle.getComputedStyle domStyle.set domStyle.get
  11. "dojo/_base/event", // event.stop
  12. "dojo/i18n", // i18n.getLocalization
  13. "dojo/_base/kernel", // kernel.deprecated
  14. "dojo/keys", // keys.ENTER keys.ESCAPE
  15. "dojo/_base/lang", // lang.getObject
  16. "dojo/_base/sniff", // has("ie")
  17. "./focus",
  18. "./_Widget",
  19. "./_TemplatedMixin",
  20. "./_WidgetsInTemplateMixin",
  21. "./_Container",
  22. "./form/Button",
  23. "./form/_TextBoxMixin",
  24. "./form/TextBox",
  25. "dojo/text!./templates/InlineEditBox.html",
  26. "dojo/i18n!./nls/common"
  27. ], function(array, declare, Deferred, domAttr, domClass, domConstruct, domStyle, event, i18n, kernel, keys, lang, has,
  28. fm, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _Container, Button, _TextBoxMixin, TextBox, template){
  29. /*=====
  30. var _Widget = dijit._Widget;
  31. var _TemplatedMixin = dijit._TemplatedMixin;
  32. var _WidgetsInTemplateMixin = dijit._WidgetsInTemplateMixin;
  33. var _Container = dijit._Container;
  34. var Button = dijit.form.Button;
  35. var TextBox = dijit.form.TextBox;
  36. =====*/
  37. // module:
  38. // dijit/InlineEditBox
  39. // summary:
  40. // An element with in-line edit capabilities
  41. var InlineEditor = declare("dijit._InlineEditor", [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  42. // summary:
  43. // Internal widget used by InlineEditBox, displayed when in editing mode
  44. // to display the editor and maybe save/cancel buttons. Calling code should
  45. // connect to save/cancel methods to detect when editing is finished
  46. //
  47. // Has mainly the same parameters as InlineEditBox, plus these values:
  48. //
  49. // style: Object
  50. // Set of CSS attributes of display node, to replicate in editor
  51. //
  52. // value: String
  53. // Value as an HTML string or plain text string, depending on renderAsHTML flag
  54. templateString: template,
  55. postMixInProperties: function(){
  56. this.inherited(arguments);
  57. this.messages = i18n.getLocalization("dijit", "common", this.lang);
  58. array.forEach(["buttonSave", "buttonCancel"], function(prop){
  59. if(!this[prop]){ this[prop] = this.messages[prop]; }
  60. }, this);
  61. },
  62. buildRendering: function(){
  63. this.inherited(arguments);
  64. // Create edit widget in place in the template
  65. var cls = typeof this.editor == "string" ? lang.getObject(this.editor) : this.editor;
  66. // Copy the style from the source
  67. // Don't copy ALL properties though, just the necessary/applicable ones.
  68. // wrapperStyle/destStyle code is to workaround IE bug where getComputedStyle().fontSize
  69. // is a relative value like 200%, rather than an absolute value like 24px, and
  70. // the 200% can refer *either* to a setting on the node or it's ancestor (see #11175)
  71. var srcStyle = this.sourceStyle,
  72. editStyle = "line-height:" + srcStyle.lineHeight + ";",
  73. destStyle = domStyle.getComputedStyle(this.domNode);
  74. array.forEach(["Weight","Family","Size","Style"], function(prop){
  75. var textStyle = srcStyle["font"+prop],
  76. wrapperStyle = destStyle["font"+prop];
  77. if(wrapperStyle != textStyle){
  78. editStyle += "font-"+prop+":"+srcStyle["font"+prop]+";";
  79. }
  80. }, this);
  81. array.forEach(["marginTop","marginBottom","marginLeft", "marginRight"], function(prop){
  82. this.domNode.style[prop] = srcStyle[prop];
  83. }, this);
  84. var width = this.inlineEditBox.width;
  85. if(width == "100%"){
  86. // block mode
  87. editStyle += "width:100%;";
  88. this.domNode.style.display = "block";
  89. }else{
  90. // inline-block mode
  91. editStyle += "width:" + (width + (Number(width) == width ? "px" : "")) + ";";
  92. }
  93. var editorParams = lang.delegate(this.inlineEditBox.editorParams, {
  94. style: editStyle,
  95. dir: this.dir,
  96. lang: this.lang,
  97. textDir: this.textDir
  98. });
  99. editorParams[ "displayedValue" in cls.prototype ? "displayedValue" : "value"] = this.value;
  100. this.editWidget = new cls(editorParams, this.editorPlaceholder);
  101. if(this.inlineEditBox.autoSave){
  102. // Remove the save/cancel buttons since saving is done by simply tabbing away or
  103. // selecting a value from the drop down list
  104. domConstruct.destroy(this.buttonContainer);
  105. }
  106. },
  107. postCreate: function(){
  108. this.inherited(arguments);
  109. var ew = this.editWidget;
  110. if(this.inlineEditBox.autoSave){
  111. // Selecting a value from a drop down list causes an onChange event and then we save
  112. this.connect(ew, "onChange", "_onChange");
  113. // ESC and TAB should cancel and save. Note that edit widgets do a stopEvent() on ESC key (to
  114. // prevent Dialog from closing when the user just wants to revert the value in the edit widget),
  115. // so this is the only way we can see the key press event.
  116. this.connect(ew, "onKeyPress", "_onKeyPress");
  117. }else{
  118. // If possible, enable/disable save button based on whether the user has changed the value
  119. if("intermediateChanges" in ew){
  120. ew.set("intermediateChanges", true);
  121. this.connect(ew, "onChange", "_onIntermediateChange");
  122. this.saveButton.set("disabled", true);
  123. }
  124. }
  125. },
  126. _onIntermediateChange: function(/*===== val =====*/){
  127. // summary:
  128. // Called for editor widgets that support the intermediateChanges=true flag as a way
  129. // to detect when to enable/disabled the save button
  130. this.saveButton.set("disabled", (this.getValue() == this._resetValue) || !this.enableSave());
  131. },
  132. destroy: function(){
  133. this.editWidget.destroy(true); // let the parent wrapper widget clean up the DOM
  134. this.inherited(arguments);
  135. },
  136. getValue: function(){
  137. // summary:
  138. // Return the [display] value of the edit widget
  139. var ew = this.editWidget;
  140. return String(ew.get("displayedValue" in ew ? "displayedValue" : "value"));
  141. },
  142. _onKeyPress: function(e){
  143. // summary:
  144. // Handler for keypress in the edit box in autoSave mode.
  145. // description:
  146. // For autoSave widgets, if Esc/Enter, call cancel/save.
  147. // tags:
  148. // private
  149. if(this.inlineEditBox.autoSave && this.inlineEditBox.editing){
  150. if(e.altKey || e.ctrlKey){ return; }
  151. // If Enter/Esc pressed, treat as save/cancel.
  152. if(e.charOrCode == keys.ESCAPE){
  153. event.stop(e);
  154. this.cancel(true); // sets editing=false which short-circuits _onBlur processing
  155. }else if(e.charOrCode == keys.ENTER && e.target.tagName == "INPUT"){
  156. event.stop(e);
  157. this._onChange(); // fire _onBlur and then save
  158. }
  159. // _onBlur will handle TAB automatically by allowing
  160. // the TAB to change focus before we mess with the DOM: #6227
  161. // Expounding by request:
  162. // The current focus is on the edit widget input field.
  163. // save() will hide and destroy this widget.
  164. // We want the focus to jump from the currently hidden
  165. // displayNode, but since it's hidden, it's impossible to
  166. // unhide it, focus it, and then have the browser focus
  167. // away from it to the next focusable element since each
  168. // of these events is asynchronous and the focus-to-next-element
  169. // is already queued.
  170. // So we allow the browser time to unqueue the move-focus event
  171. // before we do all the hide/show stuff.
  172. }
  173. },
  174. _onBlur: function(){
  175. // summary:
  176. // Called when focus moves outside the editor
  177. // tags:
  178. // private
  179. this.inherited(arguments);
  180. if(this.inlineEditBox.autoSave && this.inlineEditBox.editing){
  181. if(this.getValue() == this._resetValue){
  182. this.cancel(false);
  183. }else if(this.enableSave()){
  184. this.save(false);
  185. }
  186. }
  187. },
  188. _onChange: function(){
  189. // summary:
  190. // Called when the underlying widget fires an onChange event,
  191. // such as when the user selects a value from the drop down list of a ComboBox,
  192. // which means that the user has finished entering the value and we should save.
  193. // tags:
  194. // private
  195. if(this.inlineEditBox.autoSave && this.inlineEditBox.editing && this.enableSave()){
  196. fm.focus(this.inlineEditBox.displayNode); // fires _onBlur which will save the formatted value
  197. }
  198. },
  199. enableSave: function(){
  200. // summary:
  201. // User overridable function returning a Boolean to indicate
  202. // if the Save button should be enabled or not - usually due to invalid conditions
  203. // tags:
  204. // extension
  205. return (
  206. this.editWidget.isValid
  207. ? this.editWidget.isValid()
  208. : true
  209. );
  210. },
  211. focus: function(){
  212. // summary:
  213. // Focus the edit widget.
  214. // tags:
  215. // protected
  216. this.editWidget.focus();
  217. setTimeout(lang.hitch(this, function(){
  218. if(this.editWidget.focusNode && this.editWidget.focusNode.tagName == "INPUT"){
  219. _TextBoxMixin.selectInputText(this.editWidget.focusNode);
  220. }
  221. }), 0);
  222. }
  223. });
  224. var InlineEditBox = declare("dijit.InlineEditBox", _Widget, {
  225. // summary:
  226. // An element with in-line edit capabilities
  227. //
  228. // description:
  229. // Behavior for an existing node (`<p>`, `<div>`, `<span>`, etc.) so that
  230. // when you click it, an editor shows up in place of the original
  231. // text. Optionally, Save and Cancel button are displayed below the edit widget.
  232. // When Save is clicked, the text is pulled from the edit
  233. // widget and redisplayed and the edit widget is again hidden.
  234. // By default a plain Textarea widget is used as the editor (or for
  235. // inline values a TextBox), but you can specify an editor such as
  236. // dijit.Editor (for editing HTML) or a Slider (for adjusting a number).
  237. // An edit widget must support the following API to be used:
  238. // - displayedValue or value as initialization parameter,
  239. // and available through set('displayedValue') / set('value')
  240. // - void focus()
  241. // - DOM-node focusNode = node containing editable text
  242. // editing: [readonly] Boolean
  243. // Is the node currently in edit mode?
  244. editing: false,
  245. // autoSave: Boolean
  246. // Changing the value automatically saves it; don't have to push save button
  247. // (and save button isn't even displayed)
  248. autoSave: true,
  249. // buttonSave: String
  250. // Save button label
  251. buttonSave: "",
  252. // buttonCancel: String
  253. // Cancel button label
  254. buttonCancel: "",
  255. // renderAsHtml: Boolean
  256. // Set this to true if the specified Editor's value should be interpreted as HTML
  257. // rather than plain text (ex: `dijit.Editor`)
  258. renderAsHtml: false,
  259. // editor: String|Function
  260. // Class name (or reference to the Class) for Editor widget
  261. editor: TextBox,
  262. // editorWrapper: String|Function
  263. // Class name (or reference to the Class) for widget that wraps the editor widget, displaying save/cancel
  264. // buttons.
  265. editorWrapper: InlineEditor,
  266. // editorParams: Object
  267. // Set of parameters for editor, like {required: true}
  268. editorParams: {},
  269. // disabled: Boolean
  270. // If true, clicking the InlineEditBox to edit it will have no effect.
  271. disabled: false,
  272. onChange: function(/*===== value =====*/){
  273. // summary:
  274. // Set this handler to be notified of changes to value.
  275. // tags:
  276. // callback
  277. },
  278. onCancel: function(){
  279. // summary:
  280. // Set this handler to be notified when editing is cancelled.
  281. // tags:
  282. // callback
  283. },
  284. // width: String
  285. // Width of editor. By default it's width=100% (ie, block mode).
  286. width: "100%",
  287. // value: String
  288. // The display value of the widget in read-only mode
  289. value: "",
  290. // noValueIndicator: [const] String
  291. // The text that gets displayed when there is no value (so that the user has a place to click to edit)
  292. noValueIndicator: has("ie") <= 6 ? // font-family needed on IE6 but it messes up IE8
  293. "<span style='font-family: wingdings; text-decoration: underline;'>&#160;&#160;&#160;&#160;&#x270d;&#160;&#160;&#160;&#160;</span>" :
  294. "<span style='text-decoration: underline;'>&#160;&#160;&#160;&#160;&#x270d;&#160;&#160;&#160;&#160;</span>", // // &#160; == &nbsp;
  295. constructor: function(){
  296. // summary:
  297. // Sets up private arrays etc.
  298. // tags:
  299. // private
  300. this.editorParams = {};
  301. },
  302. postMixInProperties: function(){
  303. this.inherited(arguments);
  304. // save pointer to original source node, since Widget nulls-out srcNodeRef
  305. this.displayNode = this.srcNodeRef;
  306. // connect handlers to the display node
  307. var events = {
  308. ondijitclick: "_onClick",
  309. onmouseover: "_onMouseOver",
  310. onmouseout: "_onMouseOut",
  311. onfocus: "_onMouseOver",
  312. onblur: "_onMouseOut"
  313. };
  314. for(var name in events){
  315. this.connect(this.displayNode, name, events[name]);
  316. }
  317. this.displayNode.setAttribute("role", "button");
  318. if(!this.displayNode.getAttribute("tabIndex")){
  319. this.displayNode.setAttribute("tabIndex", 0);
  320. }
  321. if(!this.value && !("value" in this.params)){ // "" is a good value if specified directly so check params){
  322. this.value = lang.trim(this.renderAsHtml ? this.displayNode.innerHTML :
  323. (this.displayNode.innerText||this.displayNode.textContent||""));
  324. }
  325. if(!this.value){
  326. this.displayNode.innerHTML = this.noValueIndicator;
  327. }
  328. domClass.add(this.displayNode, 'dijitInlineEditBoxDisplayMode');
  329. },
  330. setDisabled: function(/*Boolean*/ disabled){
  331. // summary:
  332. // Deprecated. Use set('disabled', ...) instead.
  333. // tags:
  334. // deprecated
  335. kernel.deprecated("dijit.InlineEditBox.setDisabled() is deprecated. Use set('disabled', bool) instead.", "", "2.0");
  336. this.set('disabled', disabled);
  337. },
  338. _setDisabledAttr: function(/*Boolean*/ disabled){
  339. // summary:
  340. // Hook to make set("disabled", ...) work.
  341. // Set disabled state of widget.
  342. this.domNode.setAttribute("aria-disabled", disabled);
  343. if(disabled){
  344. this.displayNode.removeAttribute("tabIndex");
  345. }else{
  346. this.displayNode.setAttribute("tabIndex", 0);
  347. }
  348. domClass.toggle(this.displayNode, "dijitInlineEditBoxDisplayModeDisabled", disabled);
  349. this._set("disabled", disabled);
  350. },
  351. _onMouseOver: function(){
  352. // summary:
  353. // Handler for onmouseover and onfocus event.
  354. // tags:
  355. // private
  356. if(!this.disabled){
  357. domClass.add(this.displayNode, "dijitInlineEditBoxDisplayModeHover");
  358. }
  359. },
  360. _onMouseOut: function(){
  361. // summary:
  362. // Handler for onmouseout and onblur event.
  363. // tags:
  364. // private
  365. domClass.remove(this.displayNode, "dijitInlineEditBoxDisplayModeHover");
  366. },
  367. _onClick: function(/*Event*/ e){
  368. // summary:
  369. // Handler for onclick event.
  370. // tags:
  371. // private
  372. if(this.disabled){ return; }
  373. if(e){ event.stop(e); }
  374. this._onMouseOut();
  375. // Since FF gets upset if you move a node while in an event handler for that node...
  376. setTimeout(lang.hitch(this, "edit"), 0);
  377. },
  378. edit: function(){
  379. // summary:
  380. // Display the editor widget in place of the original (read only) markup.
  381. // tags:
  382. // private
  383. if(this.disabled || this.editing){ return; }
  384. this._set('editing', true);
  385. // save some display node values that can be restored later
  386. this._savedPosition = domStyle.get(this.displayNode, "position") || "static";
  387. this._savedOpacity = domStyle.get(this.displayNode, "opacity") || "1";
  388. this._savedTabIndex = domAttr.get(this.displayNode, "tabIndex") || "0";
  389. if(this.wrapperWidget){
  390. var ew = this.wrapperWidget.editWidget;
  391. ew.set("displayedValue" in ew ? "displayedValue" : "value", this.value);
  392. }else{
  393. // Placeholder for edit widget
  394. // Put place holder (and eventually editWidget) before the display node so that it's positioned correctly
  395. // when Calendar dropdown appears, which happens automatically on focus.
  396. var placeholder = domConstruct.create("span", null, this.domNode, "before");
  397. // Create the editor wrapper (the thing that holds the editor widget and the save/cancel buttons)
  398. var ewc = typeof this.editorWrapper == "string" ? lang.getObject(this.editorWrapper) : this.editorWrapper;
  399. this.wrapperWidget = new ewc({
  400. value: this.value,
  401. buttonSave: this.buttonSave,
  402. buttonCancel: this.buttonCancel,
  403. dir: this.dir,
  404. lang: this.lang,
  405. tabIndex: this._savedTabIndex,
  406. editor: this.editor,
  407. inlineEditBox: this,
  408. sourceStyle: domStyle.getComputedStyle(this.displayNode),
  409. save: lang.hitch(this, "save"),
  410. cancel: lang.hitch(this, "cancel"),
  411. textDir: this.textDir
  412. }, placeholder);
  413. if(!this._started){
  414. this.startup();
  415. }
  416. }
  417. var ww = this.wrapperWidget;
  418. // to avoid screen jitter, we first create the editor with position:absolute, visibility:hidden,
  419. // and then when it's finished rendering, we switch from display mode to editor
  420. // position:absolute releases screen space allocated to the display node
  421. // opacity:0 is the same as visibility:hidden but is still focusable
  422. // visibility:hidden removes focus outline
  423. domStyle.set(this.displayNode, { position: "absolute", opacity: "0" }); // makes display node invisible, display style used for focus-ability
  424. domStyle.set(ww.domNode, { position: this._savedPosition, visibility: "visible", opacity: "1" });
  425. domAttr.set(this.displayNode, "tabIndex", "-1"); // needed by WebKit for TAB from editor to skip displayNode
  426. // After edit widget has finished initializing (in particular need to wait for dijit.Editor),
  427. // or immediately if there is no onLoadDeferred Deferred,
  428. // replace the display widget with edit widget, leaving them both displayed for a brief time so that
  429. // focus can be shifted without incident.
  430. Deferred.when(ww.editWidget.onLoadDeferred, function(){
  431. // Note: not sure if we still need a setTimeout() now that there's a Deferred.when()
  432. setTimeout(function(){
  433. ww.focus(); // both nodes are showing, so we can switch focus safely
  434. ww._resetValue = ww.getValue();
  435. }, 0);
  436. });
  437. },
  438. _onBlur: function(){
  439. // summary:
  440. // Called when focus moves outside the InlineEditBox.
  441. // Performs garbage collection.
  442. // tags:
  443. // private
  444. this.inherited(arguments);
  445. if(!this.editing){
  446. /* causes IE focus problems, see TooltipDialog_a11y.html...
  447. setTimeout(lang.hitch(this, function(){
  448. if(this.wrapperWidget){
  449. this.wrapperWidget.destroy();
  450. delete this.wrapperWidget;
  451. }
  452. }), 0);
  453. */
  454. }
  455. },
  456. destroy: function(){
  457. if(this.wrapperWidget && !this.wrapperWidget._destroyed){
  458. this.wrapperWidget.destroy();
  459. delete this.wrapperWidget;
  460. }
  461. this.inherited(arguments);
  462. },
  463. _showText: function(/*Boolean*/ focus){
  464. // summary:
  465. // Revert to display mode, and optionally focus on display node
  466. // tags:
  467. // private
  468. var ww = this.wrapperWidget;
  469. domStyle.set(ww.domNode, { position: "absolute", visibility: "hidden", opacity: "0" }); // hide the editor from mouse/keyboard events
  470. domStyle.set(this.displayNode, { position: this._savedPosition, opacity: this._savedOpacity }); // make the original text visible
  471. domAttr.set(this.displayNode, "tabIndex", this._savedTabIndex);
  472. if(focus){
  473. fm.focus(this.displayNode);
  474. }
  475. },
  476. save: function(/*Boolean*/ focus){
  477. // summary:
  478. // Save the contents of the editor and revert to display mode.
  479. // focus: Boolean
  480. // Focus on the display mode text
  481. // tags:
  482. // private
  483. if(this.disabled || !this.editing){ return; }
  484. this._set('editing', false);
  485. var ww = this.wrapperWidget;
  486. var value = ww.getValue();
  487. this.set('value', value); // display changed, formatted value
  488. this._showText(focus); // set focus as needed
  489. },
  490. setValue: function(/*String*/ val){
  491. // summary:
  492. // Deprecated. Use set('value', ...) instead.
  493. // tags:
  494. // deprecated
  495. kernel.deprecated("dijit.InlineEditBox.setValue() is deprecated. Use set('value', ...) instead.", "", "2.0");
  496. return this.set("value", val);
  497. },
  498. _setValueAttr: function(/*String*/ val){
  499. // summary:
  500. // Hook to make set("value", ...) work.
  501. // Inserts specified HTML value into this node, or an "input needed" character if node is blank.
  502. val = lang.trim(val);
  503. var renderVal = this.renderAsHtml ? val : val.replace(/&/gm, "&amp;").replace(/</gm, "&lt;").replace(/>/gm, "&gt;").replace(/"/gm, "&quot;").replace(/\n/g, "<br>");
  504. this.displayNode.innerHTML = renderVal || this.noValueIndicator;
  505. this._set("value", val);
  506. if(this._started){
  507. // tell the world that we have changed
  508. setTimeout(lang.hitch(this, "onChange", val), 0); // setTimeout prevents browser freeze for long-running event handlers
  509. }
  510. // contextual (auto) text direction depends on the text value
  511. if(this.textDir == "auto"){
  512. this.applyTextDir(this.displayNode, this.displayNode.innerText);
  513. }
  514. },
  515. getValue: function(){
  516. // summary:
  517. // Deprecated. Use get('value') instead.
  518. // tags:
  519. // deprecated
  520. kernel.deprecated("dijit.InlineEditBox.getValue() is deprecated. Use get('value') instead.", "", "2.0");
  521. return this.get("value");
  522. },
  523. cancel: function(/*Boolean*/ focus){
  524. // summary:
  525. // Revert to display mode, discarding any changes made in the editor
  526. // tags:
  527. // private
  528. if(this.disabled || !this.editing){ return; }
  529. this._set('editing', false);
  530. // tell the world that we have no changes
  531. setTimeout(lang.hitch(this, "onCancel"), 0); // setTimeout prevents browser freeze for long-running event handlers
  532. this._showText(focus);
  533. },
  534. _setTextDirAttr: function(/*String*/ textDir){
  535. // summary:
  536. // Setter for textDir.
  537. // description:
  538. // Users shouldn't call this function; they should be calling
  539. // set('textDir', value)
  540. // tags:
  541. // private
  542. if(!this._created || this.textDir != textDir){
  543. this._set("textDir", textDir);
  544. this.applyTextDir(this.displayNode, this.displayNode.innerText);
  545. this.displayNode.align = this.dir == "rtl" ? "right" : "left"; //fix the text alignment
  546. }
  547. }
  548. });
  549. InlineEditBox._InlineEditor = InlineEditor; // for monkey patching
  550. return InlineEditBox;
  551. });