InlineEditBox.js.uncompressed.js 22 KB

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