Debian Codegraph @

dojox/mobile/bidi/ListItem.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/array",
4 "dojo/dom-construct",
5 "./common",
6 "dojo/_base/window"
7 ], function(declare, array, domConstruct, common, win){
8
9 // module:
10 // dojox/mobile/ListItem
11
12 return declare(null, {
13 // summary:
14 // Support for control over text direction for mobile ListItem widget, using Unicode Control Characters to control text direction.
15 // description:
16 // Implementation for text direction support for Label and RightText.
17 // Text direction is also applied to ListItem's embedded nodes, containing text.
18 // Complicated embedded nodes (like tables) are not supported.
19 // This class should not be used directly.
20 // Mobile ListItem widget loads this module when user sets "has: {'dojo-bidi': true }" in data-dojo-config.
21 _applyAttributes: function(){
22 if(!this.textDir && this.getParent() && this.getParent().get("textDir")){
23 this.textDir = this.getParent().get("textDir");
24 }
25 this.inherited( arguments);
26 if(this.textDir){
27 this._applyTextDirToTextElements();
28 }
29 },
30
31 _setRightTextAttr: function(text){
32 if(!this.templateString && !this.rightTextNode){
33 // When using a template, let the template create the element.
34 this.rightTextNode = domConstruct.create("div", {className:"mblListItemRightText"}, this.labelNode, "before");
35 }
36 if(this.rightTextNode){ // when using a template it may not contain a rightTextNode
37 this.rightText = text;
38 this.rightTextNode.innerHTML = this._cv ? this._cv(text) : text;
39 if(this.textDir){
40 this.rightTextNode.innerHTML = common.enforceTextDirWithUcc(this.rightTextNode.innerHTML, this.textDir);
41 }
42 }
43 },
44
45 _setLabelAttr: function(/*String*/text){
46 this.inherited("_setLabelAttr",arguments);
47 this.labelNode.innerHTML = common.enforceTextDirWithUcc(this.labelNode.innerHTML, this.textDir);
48 },
49
50 _applyTextDirToTextElements: function(){
51 // summary:
52 // Wrap child text nodes in directional UCC marks
53 if(this.labelNode.innerHTML){
54 this.labelNode.innerHTML = common.removeUCCFromText(this.labelNode.innerHTML);
55 this.labelNode.innerHTML = common.enforceTextDirWithUcc(this.labelNode.innerHTML, this.textDir);
56 this.labelNode.style.cssText = "text-align: start";
57 return;
58 }
59 var nEncount = 0;
60 array.forEach(this.domNode.childNodes, function(node){
61 var textNode;
62 if(nEncount === 0){
63 /* Replace content of directional text node, if found */
64 if(node.nodeType === 3 && (node.nodeValue === common.MARK.RLE || node.nodeValue === common.MARK.LRE)){
65 node.nodeValue = (node.nodeValue === common.MARK.RLE) ? common.MARK.LRE : common.MARK.RLE;
66 nEncount = 2;
67 return;
68 }
69 var currentNode = (node.nodeType === 1 && node.childNodes.length === 1) ? node.firstChild : node;
70 if(currentNode.nodeType === 3 && currentNode.nodeValue){
71 /* Insert directional text node */
72 if(currentNode.nodeValue.search(/[.\S]/) != -1){
73 nEncount = 1;
74 textNode = win.doc.createTextNode((this.getTextDir(currentNode.nodeValue).toLowerCase() === 'rtl') ? common.MARK.RLE : common.MARK.LRE);
75 domConstruct.place(textNode, node, "before");
76 }
77 }
78 }
79 /* Insert PDF text node, prevent further processing */
80 else if(nEncount === 1 && node.nodeName.toLowerCase() === "div"){
81 nEncount = 2;
82 textNode = win.doc.createTextNode(common.MARK.PDF);
83 domConstruct.place(textNode, node, "before");
84 }
85 }, this);
86 },
87
88 _setTextDirAttr: function(textDir){
89 if(textDir && this.textDir !== textDir){
90 this.textDir = textDir;
91 this._applyTextDirToTextElements();
92 if(this.rightTextNode){
93 this.rightTextNode.innerHTML = common.removeUCCFromText(this.rightTextNode.innerHTML);
94 this.rightTextNode.innerHTML = common.enforceTextDirWithUcc(this.rightTextNode.innerHTML, this.textDir);
95 }
96 }
97 }
98 });
99 });