Greasy Fork is available in English.

JS Forms Library B

Encapulates and extends many HTML forms elements.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/409/1286/JS%20Forms%20Library%20B.js

  1. // ==UserScript==
  2. // @name JS Forms Library B
  3. // @namespace formstemp
  4. // @description Encapulates and extends many HTML forms elements.
  5. // @require https://greatest.deepsurf.us/scripts/407-wm-common-library/code/WM%20Common%20Library.user.js?version=1284
  6. // @require https://greatest.deepsurf.us/scripts/408-wm-debug-console/code/WM%20Debug%20Console.user.js?version=1285
  7. // @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/
  8. // @include file:///C:/Users/Charlie/Desktop/*
  9. // @version 0.0.0.12
  10. // @copyright Charlie Ewing except where noted
  11. // ==/UserScript==
  12.  
  13. //this script requires some functions in the WM Common Library
  14. //this script needs access to a pre-defined JSON object
  15.  
  16. (function() {
  17. var sandbox=this;
  18. //element helper functions
  19. sandbox.elementOuterWidth=function(e){
  20. return parseInt(e.offsetWidth||0);
  21. };
  22. sandbox.elementOuterHeight=function(e){
  23. return parseInt(e.offsetHeight||0);
  24. };
  25. sandbox.elementInnerWidth=function(e){
  26. var curWidth = e.style.width;
  27. e.style.width="0";
  28. var difference = elementOuterWidth(e);
  29. e.style.width=curWidth;
  30. return elementOuterWidth(e)-difference;
  31. };
  32. sandbox.elementInnerHeight=function(e){
  33. var curHeight = e.style.height;
  34. e.style.height="0";
  35. var difference = elementOuterHeight(e);
  36. e.style.height=curHeight;
  37. return elementOuterHeight(e)-difference;
  38. };
  39.  
  40. //forms library B
  41. sandbox.jsForms = {
  42. colorData:{
  43. webSafe:[],
  44. system:["ActiveBorder","ActiveCaption","ActiveCaptionText","AppWorkspace","ButtonFace","ButtonHighlight","ButtonShadow","Control","ControlDark","ControlDarkDark","ControlLight","ControlLightLight","ControlText","Desktop","GradientActiveCaption","GradientInactiveCaption","GrayText","Highlight","HighlightText","HotTrack","InactiveBorder","InactiveCaption","InactiveCaptionText","Info","InfoText","Menu","MenuBar","MenuHighlight","MenuText","ScrollBar","Transparent","Window","WindowFrame","WindowText"],
  45. colorWords:["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenrod","DarkGray","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DodgerBlue","Firebrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","Goldenrod","Gray","Green","GreenYellow","Honeydew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenrodYellow","LightGray","LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen","Magenta","Maroon","MediumAquamarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen","MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue","MintCream","MistyRose","Moccasin","NavajoWhite","Navy","OldLace","Olive","OliveDrab","Orange","OrangeRed","Orchid","PaleGoldenrod","PaleGreen","PaleTurquoise","PaleVioletRed","PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Purple","Red","RosyBrown","RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell","Sienna","Silver","SkyBlue","SlateBlue","SlateGray","Snow","SpringGreen","SteelBlue","Tan","Teal","Thistle","Tomato","Turquoise","Violet","Wheat","White","WhiteSmoke","Yellow","YellowGreen"],
  46. custom:[
  47. {name:"Attribute",value:"rgba(255, 0, 0, 0.75)"},
  48. {name:"BlueWindow",value:"rgba(156, 246, 255, 0.75)"},
  49. {name:"Bookmark",value:"rgba(191, 210, 249, 0.75)"},
  50. {name:"BookmarkText",value:"rgba(128, 128, 128, 0.75)"},
  51. {name:"Breakpoint",value:"rgba(150, 58, 70, 0.75)"},
  52. {name:"BreakpointText",value:"rgba(255, 219, 163, 0.75)"},
  53. {name:"BrownText",value:"rgba(88, 60, 31, 0.75)"},
  54. {name:"Buy",value:"rgba(83, 196, 251, 0.75)"},
  55. {name:"Caret",value:"rgba(128, 0, 255, 0.75)"},
  56. {name:"CDATA",value:"rgba(255, 128, 0, 0.75)"},
  57. {name:"Close",value:"rgba(195, 70, 58, 0.75)"},
  58. {name:"Comment",value:"rgba(0, 100, 0, 0.75)"},
  59. {name:"CurrentLine",value:"rgba(232, 232, 232, 0.75)"},
  60. {name:"Experimental",value:"rgba(156, 244, 156, 0.75)"},
  61. {name:"GoTo",value:"rgba(102, 204, 51, 0.75)"},
  62. {name:"GreenWindow",value:"rgba(207, 255, 180, 0.75)"},
  63. {name:"Hint",value:"rgba(174, 129, 235, 0.75)"},
  64. {name:"ID",value:"rgba(0, 128, 255, 0.75)"},
  65. {name:"InactiveSelected",value:"rgba(191, 205, 219, 0.75)"},
  66. {name:"InactiveSelectedText",value:"rgba(67, 78, 84, 0.75)"},
  67. {name:"ItemDone",value:"#91FF91"},
  68. {name:"ItemFailed",value:"#FF7171"},
  69. {name:"ItemProcessing",value:"#FFFF7D"},
  70. {name:"Keyword",value:"rgba(0, 0, 255, 0.75)"},
  71. {name:"LineNumber",value:"rgba(43, 145, 175, 0.75)"},
  72. {name:"Number",value:"rgba(255, 0, 0, 0.75)"},
  73. {name:"PRE",value:"rgba(246, 246, 242, 0.75)"},
  74. {name:"QuoteText",value:"rgba(85, 85, 85, 0.75)"},
  75. {name:"Regex",value:"rgba(128, 0, 255, 0.75)"},
  76. {name:"SelectedText",value:"rgba(192, 192, 192, 0.75)"},
  77. {name:"SmartHightlighting",value:"rgba(0, 255, 0, 0.75)"},
  78. {name:"String",value:"rgba(163, 21, 21, 0.75)"},
  79. {name:"Tag",value:"rgba(0, 0, 255, 0.75)"},
  80. {name:"TanWindow",value:"rgba(255, 233, 180, 0.75)"},
  81. {name:"TrackChange",value:"rgba(108, 226, 108, 0.75)"},
  82. {name:"Unsaved",value:"rgba(255, 238, 98, 0.75)"},
  83. {name:"Value",value:"rgba(0, 0, 0, 0.75)"}
  84. ]
  85. },
  86. globalStyle:function(){
  87. //control element styles
  88. return ".jsfButton {"+
  89. //"display: block;"+
  90. "width: 17px;"+
  91. "border: 1px solid buttonshadow;"+
  92. "border-radius: 15%;"+
  93. "padding: 0px;"+
  94. "line-height: 0;"+
  95. "font-size: 16px;"+
  96. "box-shadow: 0 5px 10px buttonhighlight inset, 0 3px 10px buttonhighlight inset,0 -5px 10px buttonshadow inset, 1px 1px 0 buttonhighlight inset, -1px -1px 0 buttonhighlight inset;"+
  97. "vertical-align: middle;"+
  98. "background-color: buttonface;"+
  99. "position:relative;"+
  100. "}\n"+
  101. ".jsfButton:hover {"+
  102. "border: 1px solid highlight;"+
  103. "box-shadow: 0 5px 10px buttonhighlight inset, 0 3px 10px buttonhighlight inset,0 -3px 10px highlight inset, 1px 1px 0 buttonhighlight inset, -1px -1px 0 buttonhighlight inset;"+
  104. "}\n"+
  105. ".jsfButton>span {position:absolute;}\n"+
  106. //tab styles
  107. ".jsfTabControl>.tabs {display:block;}\n"+
  108. ".jsfTabControl>.pages {overflow:auto; display:block; padding:3px; border-radius: 0 5px 5px 5px; border: 1px solid; z-index:1; position:relative; top:-1px; background-color:buttonface; padding:5px;}\n"+
  109. ".jsfTabControl>.pages>div {display:block; height:100%;}\n"+
  110. ".jsfTab {z-index:0; top:2px; background-color:buttonshadow; display:inline-block;border:1px solid; border-bottom:none; border-radius:5px 5px 0 0; padding: 4px 8px; position:relative;}\n"+
  111. ".jsfTab.selected {z-index:999; top:0; background-color:buttonface;}\n"+
  112. ".jsfTab>img {vertical-align:middle; width:16px; height:16px; padding-right:4px; display:inline-block;}\n"+
  113. ".jsfTab>div {vertical-align:middle; display:inline-block;}\n"+
  114. //left side tabs variant
  115. ".jsfTabControl.alignLeft>.tabs {display:inline-block; vertical-align:top;}\n"+
  116. ".jsfTabControl.alignLeft>.pages {display:inline-block; vertical-align:top; left:-1px; top:0;}\n"+
  117. ".jsfTabControl.alignLeft>.tabs>.jsfTab {border-radius:5px 0 0 5px; border:1px solid; border-right:none; display:block; left:2px; top:0;}\n"+
  118. ".jsfTabControl.alignLeft>.tabs>.jsfTab.selected {left:0;}\n"+
  119. ".jsfTabControl.alignLeft>.tabs>.jsfTab>img {}\n"+
  120. ".jsfTabControl.alignLeft>.tabs>.jsfTab>div {}\n"+
  121. //right side tabs variant
  122. ".jsfTabControl.alignRight>.tabs {display:inline-block; vertical-align:top;}\n"+
  123. ".jsfTabControl.alignRight>.pages {display:inline-block; vertical-align:top; right:-1px; top:0; border-radius:5px 0 5px 5px;}\n"+
  124. ".jsfTabControl.alignRight>.tabs>.jsfTab {border-radius:0 5px 5px 0; border:1px solid; border-left:none; display:block; right:2px; top:0;}\n"+
  125. ".jsfTabControl.alignRight>.tabs>.jsfTab.selected {right:0;}\n"+
  126. ".jsfTabControl.alignRight>.tabs>.jsfTab>img {}\n"+
  127. ".jsfTabControl.alignRight>.tabs>.jsfTab>div {}\n"+
  128.  
  129. //bottom tabs variant
  130. ".jsfTabControl.alignBottom>.tabs {}\n"+
  131. ".jsfTabControl.alignBottom>.pages {border-radius:5px 5px 5px 0; top:1px;}\n"+
  132. ".jsfTabControl.alignBottom>.tabs>.jsfTab {border:1px solid; border-top:none; border-radius:0 0 5px 5px; top:-2px;}\n"+
  133. ".jsfTabControl.alignBottom>.tabs>.jsfTab.selected {top:0;}\n"+
  134. ".jsfTabControl.alignBottom>.tabs>.jsfTab>img {}\n"+
  135. ".jsfTabControl.alignBottom>.tabs>.jsfTab>div {}\n"+
  136.  
  137. //coolbar top variant
  138. ".jsfTabControl.coolBar>.tabs {background-color:window;}\n"+
  139. ".jsfTabControl.coolBar>.pages {top:0; border-radius:0; border:none; border-top:solid 1px windowframe; box-shadow:inset 0 1px buttonhighlight; padding: 15px 11px;}\n"+
  140. ".jsfTabControl.coolBar>.tabs>.jsfTab {margin-left:2px; top:0px; background-color:transparent; border-radius:0; border:none; text-align:center;}\n"+
  141. ".jsfTabControl.coolBar>.tabs>.jsfTab:first-child {margin-left:11px;}\n"+
  142. ".jsfTabControl.coolBar>.tabs>.jsfTab.selected {background-color:activecaption;}\n"+
  143. ".jsfTabControl.coolBar.hotTrack>.tabs>.jsfTab.selected:hover {background-color:activecaption;}\n"+
  144. ".jsfTabControl.coolBar>.tabs>.jsfTab>img {width:32px; height:32px; padding-right:0px;}\n"+
  145. ".jsfTabControl.coolBar>.tabs>.jsfTab>div {display:block; padding-top:5px;}\n"+
  146.  
  147. //coolbar left variant
  148. ".jsfTabControl.coolBar.alignLeft>.tabs {}\n"+
  149. ".jsfTabControl.coolBar.alignLeft>.pages {left:0; border:none; border-left:solid 1px windowframe; box-shadow:inset 1px 0 buttonhighlight;}\n"+
  150. ".jsfTabControl.coolBar.alignLeft>.tabs>.jsfTab {left:0px; margin-left:0px; margin-top:2px;}\n"+
  151. ".jsfTabControl.coolBar.alignLeft>.tabs>.jsfTab:first-child {margin-left:0px; margin-top:11px;}\n"+
  152. ".jsfTabControl.coolBar.alignLeft>.tabs>.jsfTab.selected {}\n"+
  153. ".jsfTabControl.coolBar.alignLeft>.tabs>.jsfTab>img {}\n"+
  154. ".jsfTabControl.coolBar.alignLeft>.tabs>.jsfTab>div {}\n"+
  155.  
  156. //coolbar right variant
  157. ".jsfTabControl.coolBar.alignRight>.tabs {}\n"+
  158. ".jsfTabControl.coolBar.alignRight>.pages {left:0; border:none; border-right:solid 1px windowframe; box-shadow:inset -1px 0 buttonhighlight;}\n"+
  159. ".jsfTabControl.coolBar.alignRight>.tabs>.jsfTab {left:0px; margin-left:0px; margin-top:2px;}\n"+
  160. ".jsfTabControl.coolBar.alignRight>.tabs>.jsfTab:first-child {margin-left:0px; margin-top:11px;}\n"+
  161. ".jsfTabControl.coolBar.alignRight>.tabs>.jsfTab.selected {}\n"+
  162. ".jsfTabControl.coolBar.alignRight>.tabs>.jsfTab>img {}\n"+
  163. ".jsfTabControl.coolBar.alignRight>.tabs>.jsfTab>div {}\n"+
  164.  
  165. //coolbar bottom variant
  166. ".jsfTabControl.coolBar.alignBottom>.tabs {}\n"+
  167. ".jsfTabControl.coolBar.alignBottom>.pages {border:none; border-bottom:solid 1px windowframe; box-shadow:inset 0 -1px buttonhighlight;}\n"+
  168. ".jsfTabControl.coolBar.alignBottom>.tabs>.jsfTab {}\n"+
  169. ".jsfTabControl.coolBar.alignBottom>.tabs>.jsfTab:first-child {}\n"+
  170. ".jsfTabControl.coolBar.alignBottom>.tabs>.jsfTab.selected {}\n"+
  171. ".jsfTabControl.coolBar.alignBottom>.tabs>.jsfTab>img {}\n"+
  172. ".jsfTabControl.coolBar.alignBottom>.tabs>.jsfTab>div {}\n"+
  173. //hottracking variant
  174. ".hotTrack>.tabs>.jsfTab:hover {background-color:inactivecaption;}\n"+
  175. ".hotTrack>.tabs>.jsfTab.selected:hover {background-color:buttonface;}\n"+
  176. //draw styles
  177. ".jsfblock {display:block !important;}\n"+
  178. ".jsftableRow {display:table-row !important;}\n"+
  179. ".jsftableCell {display:table-cell !important;}\n"+
  180. ".jsfinlineBlock {display:inline-block !important;}\n"+
  181. ".jsfinline {display:inline !important;}\n"+
  182. ".jsftable {display:table !important;}\n"+
  183. ".jsfhidden {display:none !important;}\n"+
  184. ".jsfBlock {display:block !important;}\n"+
  185. ".jsfTableRow {display:table-row !important;}\n"+
  186. ".jsfTableCell {display:table-cell !important;}\n"+
  187. ".jsfInlineBlock {display:inline-block !important;}\n"+
  188. ".jsfInline {display:inline !important;}\n"+
  189. ".jsfTable {display:table !important;}\n"+
  190. ".jsfHidden {display:none !important;}\n"+
  191. //form docking
  192. ".jsfDockTop {position:absolute !important; top:0px !important;}\n"+
  193. ".jsfDockBottom {position:absolute !important; bottom:0px !important;}\n"+
  194. ".jsfDockRight {position:absolute !important; right:0px !important;}\n"+
  195. ".jsfDockLeft {position:absolute !important; left:0px !important;}\n"+
  196.  
  197. ""//leave here
  198. },
  199. //basic constructor
  200. createElement:function(type,params){try{
  201. if (type=="createElement") {
  202. log("jsForms.createElement: Whoa! That would create an infinite loop.");
  203. return null;
  204. } else if (exists(jsForms[type])) {
  205. return new jsForms[type](params);
  206. }
  207. }catch(e){log("jsForms.createElement: "+e);}},
  208. //basic parts for every element
  209. basicElement:function(params){try{
  210. var self=this;
  211. params=params||{};
  212. //defaults
  213. this._enabled=true;
  214. this.parent=null; //container element
  215. this.tag=null;
  216. this.causesValidation=true;
  217. //events
  218. this.onCreated=null;
  219. //set the accessibility of the element
  220. this.__defineGetter__("enabled", function(){
  221. return this._enabled;
  222. });
  223. this.__defineSetter__("enabled", function(v){
  224. this._enabled = cBool(v);
  225. if (this.node) this.node.enabled=this.enabled;
  226. });
  227. //enable/disable commands
  228. this.enable=function(){this.enabled=true;};
  229. this.disable=function(){this.enabled=false;};
  230.  
  231. //init
  232. for (var p in params) this[p]=params[p];
  233. //return it
  234. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  235. return self;
  236. }catch(e){log("jsForms.basicElement.init: "+e);}},
  237. //basic parts for visual elements
  238. visualElement:function(params){try{
  239. var self=this;
  240. params=params||{};
  241. //attach basics
  242. self=extend(self,new jsForms.basicElement() );
  243. //defaults
  244. this._backColor="";
  245. this._foreColor="";
  246. this._font="";//"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif
  247. this._cursor="";
  248. this._visible=true;
  249. this._position={top:"",left:"",right:"",bottom:""};
  250. this._size={height:"",width:""};
  251. this._maximumSize={height:"",width:""};
  252. this._minimumSize={height:"",width:""};
  253. this._margin={top:"",left:"",right:"",bottom:""};
  254. this._padding={top:"",left:"",right:"",bottom:""};
  255. this._node=null;
  256. this.backgroundNode=null;
  257. this.borderNode=null;
  258. //_backgroundImage: url
  259. //_backgroundImageLayout: "", time, stretch, center, zoom
  260. this._borderStyle="None"; //[None, FixedSingle, Fixed3D]
  261. this._drawStyle="inline-block";
  262. this._borderCSS="1px solid #646464";
  263. this._borderRadius={topLeft:"",topRight:"",bottomRight:"",bottomLeft:""};
  264. this._toolTipText="";
  265. this._dock="none";
  266. //events
  267. this.onClick=null;
  268. this.onFocus=null;
  269. this.onBlur=null;
  270. //add css className
  271. this.addClassName=function(s){try{
  272. if (!isArray(s)) s=[s];
  273. var css=this.node.className;
  274. for (var w=0,len=s.length;(w<len);w++) {
  275. var word=s[w];
  276. this.node.className=css.addWord("jsf"+word);
  277. }
  278. }catch(e){log("jsForms.visualElement.addClassName: "+e);}};
  279.  
  280. //remove css className
  281. this.removeClassName=function(s){try{
  282. if (!isArray(s)) s=[s];
  283. var css=this.node.className;
  284. for (var w=0,len=s.length;(w<len);w++) {
  285. var word=s[w];
  286. this.node.className=css.removeWord("jsf"+word);
  287. }
  288. }catch(e){log("jsForms.visualElement.addClassName: "+e);}};
  289. //autoFit parent element
  290. this.__defineGetter__("dock", function(){
  291. return this._dock;
  292. });
  293. this.__defineSetter__("dock", function(v){try{
  294. this._dock = (v=v.toString());
  295. //clear classes
  296. this.removeClassName(["dockTop","dockBottom","dockFill","dockRight","dockLeft"]);
  297. //calculate display, height, width and position
  298. var d, w, h, p=this.node.parentNode||null;
  299. switch(v) {
  300. case "none":
  301. //use given heights and widths
  302. d=this._drawStyle;
  303. w=this.size.width||"";
  304. h=this.size.height||"";
  305. break;
  306. case "fill":
  307. //fully dock with parent object
  308. if (!p) return;
  309. d="block";
  310. w="";
  311. h=elementInnerHeight(p)-(this.outerHeight-this.innerHeight)+"px";
  312. break;
  313. case "fillAndShare":
  314. //dock with parent object
  315. //using any space left by other children
  316. //this assumes all siblings are blocks
  317. if (!p) return;
  318. d="block";
  319. w="";
  320. //detect maximum possible height
  321. h=
  322. //parent inner height
  323. elementInnerHeight(p)
  324. //minus the outer requirements for this element
  325. -(this.outerHeight-this.innerHeight);
  326. //detect sibling elements' heights
  327. var sibH=0;
  328. for (var s in p.childNodes){
  329. sib=p.childNodes[s];
  330. if (sib!=this.node) {
  331. sibH+=elementOuterHeight(sib);
  332. }
  333. }
  334. h=(h-sibH)+"px";
  335. break;
  336. case "top":
  337. //dock to the top of the parent
  338. d="block";
  339. w="";
  340. h=this.size.height||"";
  341. this.addClassName("dockTop");
  342. break;
  343. case "bottom":
  344. //dock to the bottom of the parent
  345. d="block";
  346. w="";
  347. h=this.size.height||"";
  348. this.addClassName("dockBottom");
  349. break;
  350. case "right":
  351. //dock to the right of the parent
  352. d=this._drawStyle;
  353. w=this.size.width||"";
  354. h=elementInnerHeight(p)-(this.outerHeight-this.innerHeight)+"px";
  355. this.addClassName("dockRight");
  356. break;
  357. case "left":
  358. //dock to the right of the parent
  359. d=this._drawStyle;
  360. w=this.size.width||"";
  361. h=elementInnerHeight(p)-(this.outerHeight-this.innerHeight)+"px";
  362. this.addClassName("dockLeft");
  363. break;
  364. }
  365. //apply non-class changes
  366. this.node.style.display=d;
  367. this.node.style.width=w;
  368. this.node.style.height=h;
  369. }catch(e){log("jsForms.visualElement.autoFit: "+e);}});
  370.  
  371. //set css background color
  372. this.__defineGetter__("backColor", function(){
  373. return this._backColor;
  374. });
  375. this.__defineSetter__("backColor", function(v){try{
  376. this._backColor = (v.toString());
  377. if (this.backgroundNode) this.backgroundNode.style.backgroundColor=this.backColor;
  378. }catch(e){log("jsForms.visualElement.backColor: "+e);}});
  379. //set draw style (display)
  380. this.__defineGetter__("drawStyle", function(){
  381. return this._drawStyle;
  382. });
  383. this.__defineSetter__("drawStyle", function(v){try{
  384. this._drawStyle = (v.toString());
  385. this.dock=this._dock;
  386. }catch(e){log("jsForms.visualElement.drawStyle: "+e);}});
  387.  
  388. //set tooltiptext/title
  389. this.__defineGetter__("toolTipText", function(){
  390. return this._toolTipText;
  391. });
  392. this.__defineSetter__("toolTipText", function(v){try{
  393. this._toolTipText = (v.toString());
  394. if (this.node) this.node.title=this._toolTipText;
  395. }catch(e){log("jsForms.visualElement.toolTipText: "+e);}});
  396.  
  397. //set css foreground color
  398. this.__defineGetter__("foreColor", function(){
  399. return this._foreColor;
  400. });
  401. this.__defineSetter__("foreColor", function(v){try{
  402. this._foreColor = (v.toString());
  403. if (this.node) this.node.style.color=this.foreColor;
  404. }catch(e){log("jsForms.visualElement.foreColor: "+e);}});
  405. //set the font used in both the box and the list
  406. this.__defineGetter__("font", function(){
  407. return this._font;
  408. });
  409. this.__defineSetter__("font", function(v){try{
  410. this._font = (v.toString());
  411. if (this.node) this.node.style.fontFamily=this.font;
  412. }catch(e){log("jsForms.visualElement.font: "+e);}});
  413.  
  414. //set the node element css class
  415. this.__defineGetter__("className", function(){
  416. return this.node.className;
  417. });
  418. this.__defineSetter__("className", function(v){try{
  419. if (this.node) this.node.className=v;
  420. }catch(e){log("jsForms.visualElement.className: "+e);}});
  421.  
  422. //set the cursor used in the element
  423. this.__defineGetter__("cursor", function(){
  424. return this._cursor;
  425. });
  426. this.__defineSetter__("cursor", function(v){try{
  427. this._cursor = (v.toString());
  428. if (this.node) this.node.style.cursor=this.cursor;
  429. }catch(e){log("jsForms.visualElement.cursor: "+e);}});
  430.  
  431. //set if the dropdown is visible
  432. this.__defineGetter__("visible", function(){
  433. return this._visible;
  434. });
  435. this.__defineSetter__("visible", function(v){try{
  436. this._visible = cBool(v);
  437. //log(this._visible);
  438. if (this._visible) this.removeClassName("hidden");
  439. else this.addClassName("hidden");
  440. }catch(e){log("jsForms.visualElement.visible: "+e);}});
  441.  
  442. //set the location based on the upper left of the container box
  443. //values are copied from the passed object so that a reference to the
  444. //passed object does not remain
  445. this.__defineGetter__("position", function(){
  446. return this._position;
  447. });
  448. this.__defineSetter__("position", function(v){try{
  449. if (isObject(v)) {
  450. this._position.top=v.top||"";
  451. this._position.left=v.left||"";
  452. this._position.right=v.right||"";
  453. this._position.bottom=v.bottom||"";
  454. } else {
  455. //value was not an object
  456. log("jsForms.visualElement.position.set: input was not an object");
  457. this._position={top:"",left:"",right:"",bottom:""}
  458. }
  459. if (this.node) {
  460. this.node.style.top=this.position.top;
  461. this.node.style.left=this.position.left;
  462. this.node.style.right=this.position.right;
  463. this.node.style.bottom=this.position.bottom;
  464. }
  465. }catch(e){log("jsForms.visualElement.position: "+e);}});
  466.  
  467. //set the height and width of the box
  468. this.__defineGetter__("size", function(){
  469. return this._size;
  470. });
  471. this.__defineSetter__("size", function(v){try{
  472. if (isObject(v)) {
  473. this._size.height=v.height||"";
  474. this._size.width=v.width||"";
  475. } else {
  476. //value was not an object
  477. log("jsForms.visualElement.size.set: input was not an object");
  478. this._size={height:"",width:""}
  479. }
  480. //now use the dock function to finish sizing
  481. this.dock = this._dock;
  482. }catch(e){log("jsForms.visualElement.size: "+e);}});
  483.  
  484. //set the max height and width of the box
  485. this.__defineGetter__("maximumSize", function(){
  486. return this._maximumSize;
  487. });
  488. this.__defineSetter__("maximumSize", function(v){try{
  489. if (isObject(v)) {
  490. this._maximumSize.height=v.height||"";
  491. this._maximumSize.width=v.width||"";
  492. } else {
  493. //value was not an object
  494. log("jsForms.visualElement.maximumSize.set: input was not an object");
  495. this._maximumSize={height:"",width:""}
  496. }
  497. if (this.node) {
  498. this.node.style.maxHeight=this.maximumSize.height;
  499. this.node.style.maxWidth=this.maximumSize.width;
  500. }
  501. }catch(e){log("jsForms.visualElement.maximumSize: "+e);}});
  502.  
  503. //set the min height and width of the box
  504. this.__defineGetter__("minimumSize", function(){
  505. return this._minimumSize;
  506. });
  507. this.__defineSetter__("minimumSize", function(v){try{
  508. if (isObject(v)) {
  509. this._minimumSize.height=v.height||"";
  510. this._minimumSize.width=v.width||"";
  511. } else {
  512. //value was not an object
  513. log("jsForms.visualElement.minimumSize.set: input was not an object");
  514. this._minimumSize={height:"",width:""}
  515. }
  516. if (this.node) {
  517. this.node.style.minHeight=this.minimumSize.height;
  518. this.node.style.minWidth=this.minimumSize.width;
  519. }
  520. }catch(e){log("jsForms.visualElement.minimumSize: "+e);}});
  521.  
  522. //set the margins of the object {top, left, right, bottom}
  523. this.__defineGetter__("margin", function(){
  524. return this._margin;
  525. });
  526. this.__defineSetter__("margin", function(v){try{
  527. if (isObject(v)) {
  528. this._margin.top=v.top||"";
  529. this._margin.left=v.left||"";
  530. this._margin.right=v.right||"";
  531. this._margin.bottom=v.bottom||"";
  532. } else {
  533. //value was not an object
  534. log("jsForms.visualElement.margin.set: input was not an object");
  535. this._margin={top:"",left:"",right:"",bottom:""}
  536. }
  537. if (this.node) {
  538. this.node.style.margin=
  539. this.margin.top+" "+
  540. this.margin.right+" "+
  541. this.margin.bottom+" "+
  542. this.margin.left;
  543. }
  544. }catch(e){log("jsForms.visualElement.margin: "+e);}});
  545.  
  546. //set the padding of the object {top, left, right, bottom}
  547. this.__defineGetter__("padding", function(){
  548. return this._padding;
  549. });
  550. this.__defineSetter__("padding", function(v){try{
  551. if (isObject(v)) {
  552. this._padding.top=v.top||"";
  553. this._padding.left=v.left||"";
  554. this._padding.right=v.right||"";
  555. this._padding.bottom=v.bottom||"";
  556. } else {
  557. //value was not an object
  558. log("jsForms.visualElement.padding.set: input was not an object");
  559. this._padding={top:"",left:"",right:"",bottom:""}
  560. }
  561. if (this.node) {
  562. this.node.style.paddingTop=this.padding.top;
  563. this.node.style.paddingLeft=this.padding.left;
  564. this.node.style.paddingRight=this.padding.right;
  565. this.node.style.paddingBottom=this.padding.bottom;
  566. }
  567. }catch(e){log("jsForms.visualElement.padding: "+e);}});
  568.  
  569. //set the border radius of the object
  570. this.__defineGetter__("borderRadius", function(){
  571. return this._borderRadius;
  572. });
  573. this.__defineSetter__("borderRadius", function(v){try{
  574. if (isObject(v)) {
  575. this._borderRadius.topLeft=v.topLeft||"";
  576. this._borderRadius.bottomLeft=v.bottomLeft||"";
  577. this._borderRadius.topRight=v.topRight||"";
  578. this._borderRadius.bottomRight=v.bottomRight||"";
  579. } else {
  580. //value was not an object
  581. log("jsForms.visualElement.borderRadius.set: input was not an object");
  582. this._borderRadius={topLeft:"",bottomLeft:"",topRight:"",bottomRight:""}
  583. }
  584. if (this.borderNode) {
  585. this.borderNode.style.borderTopLeftRadius=this.borderRadius.topLeft;
  586. this.borderNode.style.borderTopRightRadius=this.borderRadius.topRight;
  587. this.borderNode.style.borderBottomLeftRadius=this.borderRadius.bottomLeft;
  588. this.borderNode.style.borderBottomRightRadius=this.borderRadius.bottomRight;
  589. }
  590. }catch(e){log("jsForms.visualElement.borderRadius: "+e);}});
  591.  
  592. //set the border style of the element
  593. this.__defineGetter__("borderStyle", function(){
  594. return this._borderStyle;
  595. });
  596. this.__defineSetter__("borderStyle", function(v){try{
  597. this._borderStyle = (v.toString());
  598. if (this.borderNode){
  599. this.borderNode.style.border=(
  600. (this._borderStyle=="Fixed3D")?"2px inset buttonface":
  601. (this._borderStyle=="FixedSingle")?this._borderCSS:
  602. "none"
  603. );
  604. }
  605. }catch(e){log("jsForms.visualElement.borderStyle: "+e);}});
  606.  
  607. //set default border css for borderStyle FixedSingle
  608. this.__defineGetter__("borderCSS", function(){
  609. return this._borderCSS;
  610. });
  611. this.__defineSetter__("borderCSS", function(v){try{
  612. this._borderCSS = (v.toString());
  613. this.borderStyle = this._borderStyle;
  614. }catch(e){log("jsForms.visualElement.borderCSS: "+e);}});
  615.  
  616. //return the dom node
  617. this.__defineGetter__("node", function(){
  618. return this._node;
  619. });
  620.  
  621. //calculate inner and outer actual sizes
  622. this.__defineGetter__("outerWidth", function(){
  623. return elementOuterWidth(this._node);
  624. });
  625.  
  626. this.__defineGetter__("innerWidth", function(){
  627. return elementInnerWidth(this._node);
  628. });
  629.  
  630. this.__defineGetter__("outerHeight", function(){
  631. return elementOuterHeight(this._node);
  632. });
  633.  
  634. this.__defineGetter__("innerHeight", function(){
  635. return elementInnerHeight(this._node);
  636. });
  637.  
  638. //show/hide the visual element
  639. this.show=function(){
  640. this.visible=true;
  641. };
  642. this.hide=function(){
  643. this.visible=false;
  644. };
  645.  
  646. //draw the housing
  647. this._node=createElement("div",{
  648. style:(
  649. "display:"+this._drawStyle+";"+
  650. "vertical-align:middle;"+
  651. ""//leave here
  652. )
  653. });
  654. //set nodes for bordering and background
  655. this.borderNode=this._node;
  656. this.backgroundNode=this._node;
  657. //init
  658. for (var p in params) this[p]=params[p];
  659. //confirm(JSON.stringify(this));
  660.  
  661. //return it
  662. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  663. return self;
  664. }catch(e){log("jsForms.visualElement.init: "+e);}},
  665. //icon specific parts
  666. icon:function(params){try{
  667. var self=this;
  668. params=params||{};
  669. //attach basic elements
  670. self=extend(self,new jsForms.visualElement() );
  671.  
  672. //defaults
  673. this._src=null;
  674. this._defaultImage=null;
  675. this._altImage=null;
  676. this.imageNode=null;
  677. this.node.style.overflow="hidden";
  678. this._selectedImage="_src";
  679. //set the image
  680. this.__defineGetter__("src", function(){
  681. return this._src;
  682. });
  683. this.__defineSetter__("_src", function(v){try{
  684. this._src = (v.toString());
  685. if (this._selectedImage=="_src") this.redraw();
  686. }catch(e){log("jsForms.icon.src: "+e);}});
  687. //set the default image
  688. this.__defineGetter__("defaultImage", function(){
  689. return this._defaultImage;
  690. });
  691. this.__defineSetter__("defaultImage", function(v){try{
  692. this._defaultImage = (v.toString());
  693. if (this._selectedImage=="_defaultImage") this.redraw();
  694. }catch(e){log("jsForms.icon.defaultImage: "+e);}});
  695.  
  696. //set the alt image
  697. this.__defineGetter__("altImage", function(){
  698. return this._altImage;
  699. });
  700. this.__defineSetter__("altImage", function(v){try{
  701. this._altImage = (v.toString());
  702. if (this._selectedImage=="_altImage") this.redraw();
  703. }catch(e){log("jsForms.icon.altImage: "+e);}});
  704. //show different images
  705. this.showPrimary=function(){
  706. this._selectedImage="_src";
  707. this.redraw();
  708. };
  709. this.showDefault=function(){
  710. this._selectedImage="_defaultImage";
  711. this.redraw();
  712. };
  713. this.showAlt=function(){
  714. this._selectedImage="_altImage";
  715. this.redraw();
  716. };
  717. //redraw
  718. this.redraw=function(){try{
  719. if (this.imageNode) {
  720. this.imageNode.src=(this[this._selectedImage]||this._defaultImage);
  721. }
  722. }catch(e){log("jsForms.icon.src: "+e);}};
  723. //draw it
  724. if (this.node){
  725. this.node.appendChild(
  726. this.imageNode=createElement("img",{
  727. style:(
  728. "width:inherit;"+
  729. "height:inherit;"+
  730. ""//leave here
  731. ),
  732. })
  733. );
  734. }
  735.  
  736. //init
  737. for (var p in params) {try{
  738. //separate event functions
  739. if (p.startsWith("on")) {
  740. //apply event functions to intended objects
  741. if (["onCreated"].inArray(p)) {
  742. this[p]=params[p];
  743. } else this.imageNode[p.toLowerCase()]=params[p];
  744. } else this[p]=params[p];
  745. }catch(e){log("jsForms.icon.init (params): "+e);}};
  746. //confirm(JSON.stringify(this));
  747.  
  748. /*/preload images
  749. new Image().src = this._altImage;
  750. new Image().src = this._defaultImage;
  751. new Image().src = this._src;
  752. */
  753.  
  754. //return it
  755. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  756. return self;
  757. }catch(e){log("jsForms.icon.init: "+e);}},
  758. //textbox specific parts
  759. textBox:function(params){try{
  760. var self=this;
  761. params=params||{};
  762. //attach basic elements
  763. self=extend(self,new jsForms.visualElement() );
  764.  
  765. //defaults
  766. this._text="";
  767. this._emptyText="";
  768. this._maxLength=32767;
  769. this.textNode=null;
  770. this.borderNode=null;
  771. this.backgroundNode=null;
  772. this._borderStyle="FixedSingle";
  773. //this._drawStyle="block";
  774. //events
  775. this.onChange=null;
  776.  
  777. //set the text shown in the box
  778. this.__defineGetter__("text", function(){
  779. return this._text;
  780. });
  781. this.__defineSetter__("text", function(v){try{
  782. this._text = (v.toString());
  783. if (this.textNode) this.textNode.value=v;
  784. if (this.causesValidation && this.onChange) {var caller=this; doAction(function(){caller.onChange(caller);})};
  785. }catch(e){log("jsForms.textBox.text: "+e);}});
  786.  
  787. //text to display when text=""
  788. this.__defineGetter__("emptyText", function(){
  789. return this._emptyText;
  790. });
  791. this.__defineSetter__("emptyText", function(v){try{
  792. this._emptyText = (v.toString());
  793. if (this.node) this.node.title=this.emptyText;
  794. }catch(e){log("jsForms.textBox.emptyText: "+e);}});
  795.  
  796. //set the max number of characters that can be entered in the box
  797. this.__defineGetter__("maxLength", function(){
  798. return this._maxLength;
  799. });
  800. this.__defineSetter__("maxLength", function(v){try{
  801. this._maxLength = parseInt(v);
  802. if (this.node) this.node.maxLength=this.maxLength;
  803. }catch(e){log("jsForms.textBox.maxLength: "+e);}});
  804.  
  805. //get the default value as text
  806. this.__defineGetter__("value", function(){
  807. return this._text;
  808. });
  809. //draw it
  810. this._node.appendChild(
  811. this.textNode=createElement("input",{
  812. maxLength:this._maxLength,
  813. value:this._text,
  814. title:this._emptyText,
  815. enabled:this._enabled,
  816. style:(
  817. "display:"+this._drawStyle+";"+
  818. "width:inherit;"+
  819. "height:inherit;"+
  820. "minWidth:inherit;"+
  821. "minHeight:inherit;"+
  822. "maxWidth:inherit;"+
  823. "maxHeight:inherit;"+
  824. "margin-top:inherit;"+
  825. "margin-left:inherit;"+
  826. "margin-right:inherit;"+
  827. "margin-bottom:inherit;"+
  828. "top:inherit;"+
  829. "left:inherit;"+
  830. "right:inherit;"+
  831. "bottom:inherit;"+
  832. "cursor:inherit;"+
  833. //"font-family:inherit;"+
  834. //"background-color:"+this._backColor+";"+
  835. "color:inherit;"+
  836. /*"border:"+(
  837. (this.borderStyle=="Fixed3D")?"":
  838. (this.borderStyle=="FixedSingle")?this.borderCSS:
  839. "none"
  840. )+";"+
  841. "border-top-left-radius:"+this.borderRadius.topLeft+";"+
  842. "border-top-right-radius:"+this.borderRadius.bottomLeft+";"+
  843. "border-bottom-left-radius:"+this.borderRadius.topRight+";"+
  844. "border-bottom-right-radius:"+this.borderRadius.bottomRight+";"+
  845. */
  846.  
  847.  
  848. ""//leave here
  849. ),
  850. onclick:self.onClick,
  851. ondblclick:self.onDoubleClick,
  852. onmousedown:self.onMouseDown,
  853. onmouseup:self.onMouseUp,
  854. onmousemove:self.onMouseMove,
  855. onmouseover:self.onMouseOver,
  856. onmouseout:self.onMouseOut,
  857. onkeydown:self.onKeyDown,
  858. onkeypress:self.onKeyPress,
  859. onkeyup:self.onKeyPress,
  860. onblur:self.onBlur,
  861. onfocus:self.onFocus,
  862. onselect:self.onSelect,
  863. onchange:function(){
  864. self.text=this.value;
  865. },
  866. })
  867. );
  868. //set nodes for bordering and background
  869. this.borderNode=this.textNode;
  870. this.backgroundNode=this.textNode;
  871. //init
  872. for (var p in params) this[p]=params[p];
  873. //confirm(JSON.stringify(this));
  874.  
  875. //return it
  876. if (this.causesValidation && this.onCreated) doAction(function(){this.onCreated(this);});
  877. return this;
  878. }catch(e){log("jsForms.textBox.init: "+e);}},
  879.  
  880. //numeric up/down specific parts
  881. spinBox:function(params){try{
  882. var self=this;
  883. params=params||{};
  884. //attach basic elements
  885. self=extend(self,new jsForms.textBox() );
  886.  
  887. //defaults
  888. //this._hexadecimal=false;
  889. //this._thousandsSeparator=false;
  890. this._upDownAlign="right";
  891. //this._decimalPlaces=0;
  892. this._increment=1;
  893. this._maximum=100;
  894. this._minimum=0;
  895. this._rollOver=false; //start at the other end if past boundary
  896. //set the max value
  897. this.__defineGetter__("maximum", function(){
  898. return this._maximum;
  899. });
  900. this.__defineSetter__("maximum", function(v){try{
  901. this._maximum = parseInt(v);
  902. }catch(e){log("jsForms.spinBox.maximum: "+e);}});
  903.  
  904. //set the min value
  905. this.__defineGetter__("minimum", function(){
  906. return this._minimum;
  907. });
  908. this.__defineSetter__("minimum", function(v){try{
  909. this._minimum = parseInt(v);
  910. }catch(e){log("jsForms.spinBox.minimum: "+e);}});
  911.  
  912. //set the increment value
  913. this.__defineGetter__("increment", function(){
  914. return this._increment;
  915. });
  916. this.__defineSetter__("increment", function(v){try{
  917. this._increment = parseInt(v);
  918. }catch(e){log("jsForms.spinBox.increment: "+e);}});
  919.  
  920. //set the rollOver flag
  921. this.__defineGetter__("rollOver", function(){
  922. return this._rollOver;
  923. });
  924. this.__defineSetter__("rollOver", function(v){try{
  925. this._rollOver = cBool(v);
  926. }catch(e){log("jsForms.spinBox.rollOver: "+e);}});
  927.  
  928. //up and down functions
  929. this.up=function(){
  930. this.change(this._increment);
  931. };
  932. this.down=function(){
  933. this.change(-(this._increment));
  934. };
  935. this.change=function(n){
  936. var v=parseInt(this.text),hasChanged=false;
  937. v=v+n;
  938. //validate boundaries
  939. if ((v<=this._maximum)&&(v>=this._minimum)){
  940. hasChanged=true;
  941. } else {
  942. if (this._rollOver) {
  943. //perform rollover
  944. if (v>this._maximum) v=this._minimum;
  945. else v=this._maximum;
  946. hasChanged=true;
  947. }
  948. }
  949. if (hasChanged){
  950. //format output
  951. //v=v.toString();
  952. //v=v.format("#,##0");
  953. //print it
  954. this.text=v;
  955. }
  956. };
  957. //append buttons to the textbox portion
  958. this.node.style.position="relative";
  959. this.textNode.style.textAlign=(this._upDownAlign=="left")?"right":"left";
  960. this.textNode.style.verticalAlign="middle";
  961. this.node.appendChild(
  962. this.buttonNode=createElement("div",{
  963. style:(
  964. "vertical-align: middle;"+
  965. "position: relative;"+
  966. "display: inline-block;"+
  967. ""//leave here
  968. ),
  969. },[
  970. this.incrementNode=createElement("button",{
  971. className:"jsfButton jsfblock",
  972. title:"Up",
  973. onclick:function(){
  974. self.up();
  975. },
  976. },[
  977. createElement("span",{
  978. textContent:"\u25B4",
  979. })
  980. ]),
  981. this.decrementNode=createElement("button",{
  982. className:"jsfButton jsfblock",
  983. title:"Down",
  984. onclick:function(){
  985. self.down();
  986. },
  987. },[
  988. createElement("span",{
  989. textContent:"\u25BE",
  990. })
  991. ])
  992. ])
  993. );
  994. //init
  995. for (var p in params) this[p]=params[p];
  996.  
  997. //resize its buttons
  998. this.fixSizes=function(){
  999. var self=this;
  1000. var btn=this.incrementNode;
  1001. var h=elementOuterHeight(this.textNode);
  1002. var i=elementOuterHeight(btn)-elementInnerHeight(btn);
  1003. if (!isNaN(h) && !isNaN(i) && h>0){
  1004. //resize buttons
  1005. btn.style.height=(h/2)-i+"px";
  1006. self.decrementNode.style.height=
  1007. btn.style.height;
  1008. //move child text to center
  1009. var span=btn.childNodes[0];
  1010. span.style.left=
  1011. Math.floor((
  1012. elementInnerWidth(btn)-elementOuterWidth(span))/2
  1013. )+"px";
  1014. span.style.bottom=
  1015. Math.floor((
  1016. elementInnerHeight(btn)-elementOuterHeight(span))/2
  1017. )+"px";
  1018. var span=self.decrementNode.childNodes[0];
  1019. span.style.left=
  1020. Math.floor(
  1021. (elementInnerWidth(self.decrementNode)-elementOuterWidth(span))/2
  1022. )+"px";
  1023. span.style.bottom=
  1024. Math.floor(
  1025. (elementInnerHeight(self.decrementNode)-elementOuterHeight(span))/2
  1026. )+"px";
  1027. } else {
  1028. setTimeout(function(){self.fixSizes();},100);
  1029. }
  1030. };
  1031. this.fixSizes();
  1032.  
  1033. //return it
  1034. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1035. return self;
  1036. }catch(e){log("jsForms.spinBox.init: "+e);}},
  1037.  
  1038. //checkbox specific parts
  1039. checkBox:function(params){try{
  1040. var self=this;
  1041. params=params||{};
  1042. //attach basic elements
  1043. self=extend(self,new jsForms.visualElement() );
  1044.  
  1045. //defaults
  1046. this._checked=false;
  1047. this._text="";
  1048. this._value="";
  1049. //_threeState: see checkedState
  1050. //_checkedState: [unchecked, checked, indeterminate]
  1051. this._autoCheck=true; //check on label click
  1052. this.checkNode=null;
  1053. this.labelNode=null;
  1054. this._highlightSelected=false;
  1055.  
  1056. //this._image="";
  1057. //this._textCheckRelation="After"; //[Above, Below, Before, After]
  1058. //this._textImageRelation="After"; //[Above, Below, Before, After]
  1059. //events
  1060. this.onChecked=null;
  1061. this.onUnchecked=null;
  1062. //set visible text of the checkbox
  1063. this.__defineGetter__("text", function(){
  1064. return this._text;
  1065. });
  1066. this.__defineSetter__("text", function(v){try{
  1067. this._text = (v.toString());
  1068. if (this.labelNode) this.labelNode.textContent=this._text;
  1069. }catch(e){log("jsForms.checkBox.text: "+e);}});
  1070.  
  1071. //set underlying value of the checkbox
  1072. this.__defineGetter__("value", function(){
  1073. return this._value;
  1074. });
  1075. this.__defineSetter__("value", function(v){try{
  1076. this._value = v;
  1077. if (this.checkNode) this.checkNode.value=this._value;
  1078. }catch(e){log("jsForms.checkBox.value: "+e);}});
  1079.  
  1080. this.doAutoCheck=function(){try{
  1081. click(self.checkNode);
  1082. if (self.onLabelClick) self.onLabelClick();
  1083. }catch(e){log("jsForms.checkBox.doAutoCheck: "+e);}};
  1084. //set autocheck on label click
  1085. this.__defineGetter__("autoCheck", function(){
  1086. return this._autoCheck;
  1087. });
  1088. this.__defineSetter__("autoCheck", function(v){try{
  1089. this._autoCheck = cBool(v);
  1090. this.labelNode.onclick=(!this._autoCheck)?this.onLabelClick:this.doAutoCheck;
  1091. }catch(e){log("jsForms.checkBox.autoCheck: "+e);}});
  1092.  
  1093. //set highlight on checked
  1094. this.__defineGetter__("highlightSelected", function(){
  1095. return this._highlightSelected;
  1096. });
  1097. this.__defineSetter__("highlightSelected", function(v){try{
  1098. this._highlightSelected = cBool(v);
  1099. if (this.node) {
  1100. this.node.style.backgroundColor=(this._highlightSelected)?((this._checked)?"highlight":this.backColor):this.backColor;
  1101. this.node.style.color=(this._highlightSelected)?((this._checked)?"highlighttext":this.foreColor):this.foreColor;
  1102. }
  1103. }catch(e){log("jsForms.checkBox.highlightSelected: "+e);}});
  1104.  
  1105. //set checked state
  1106. this.__defineGetter__("checked", function(){
  1107. return this._checked;
  1108. });
  1109. this.__defineSetter__("checked", function(v){try{
  1110. this._checked = cBool(v);
  1111. if (this.checkNode) this.checkNode.checked=this._checked;
  1112. if (this.node) {
  1113. this.node.style.backgroundColor=(this._highlightSelected)?((this._checked)?"highlight":this.backColor):this.backColor;
  1114. this.node.style.color=(this._highlightSelected)?((this._checked)?"highlighttext":this.foreColor):this.foreColor;
  1115. }
  1116. if (this.causesValidation){
  1117. var caller=this;
  1118. if (this.onChecked && this._checked) doAction(function(){caller.onChecked(caller);});
  1119. if (this.onUnchecked && !this._checked) doAction(function(){caller.onChecked(caller);});
  1120. if (this.onChange) doAction(function(){caller.onChange(caller);});
  1121. /*confirm("-onchange");
  1122. window.setTimeout(function(){
  1123. confirm("-onchange delay");
  1124. caller.onChange(caller);
  1125. },1000);*/
  1126. //}
  1127. }
  1128. }catch(e){log("jsForms.checkBox.checked: "+e);}});
  1129. //register the initial params
  1130. for (var p in params) this[p]=params[p];
  1131. //draw it
  1132. this.node.appendChild(
  1133. this.checkNode=createElement("input",{
  1134. type: "checkbox",
  1135. value: this._value,
  1136. checked: this._checked,
  1137. style:(
  1138. "margin-right: 4px;"+
  1139. "vertical-align: middle;"+
  1140. "" //leave here
  1141. ),
  1142. onclick:self.onClick,
  1143. ondblclick:self.onDoubleClick,
  1144. onmousedown:self.onMouseDown,
  1145. onmouseup:self.onMouseUp,
  1146. onmousemove:self.onMouseMove,
  1147. onmouseover:self.onMouseOver,
  1148. onmouseout:self.onMouseOut,
  1149. onkeydown:self.onKeyDown,
  1150. onkeypress:self.onKeyPress,
  1151. onkeyup:self.onKeyPress,
  1152. onblur:self.onBlur,
  1153. onfocus:self.onFocus,
  1154. onchange:function(){
  1155. self.checked=this.checked;
  1156. },
  1157. })
  1158. );
  1159. this.node.appendChild(
  1160. this.labelNode=createElement("label",{
  1161. textContent:this._text,
  1162. style:(
  1163. "margin-right: 4px;"+
  1164. "vertical-align: middle;"+
  1165. "font-weight: normal;"+
  1166. "color: inherit;"+
  1167. "" //leave here
  1168. ),
  1169. onclick:(this._autoCheck)?self.doAutoCheck:self.onLabelClick,
  1170. ondblclick:self.onLabelDoubleClick,
  1171. onmousedown:self.onMouseDown,
  1172. onmouseup:self.onMouseUp,
  1173. onmousemove:self.onMouseMove,
  1174. onmouseover:self.onMouseOver,
  1175. onmouseout:self.onMouseOut,
  1176. onkeydown:self.onKeyDown,
  1177. onkeypress:self.onKeyPress,
  1178. onkeyup:self.onKeyPress,
  1179. onblur:self.onBlur,
  1180. onfocus:self.onFocus,
  1181. })
  1182. );
  1183. //return it
  1184. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1185. return self;
  1186. }catch(e){log("jsForms.checkBox.init: "+e);}},
  1187. //toolBox for containing tool icons
  1188. toolBox:function(params){try{
  1189. var self=this;
  1190. params=params||{};
  1191. //attach basic elements
  1192. self=extend(self,new jsForms.listBox({items:params.items}) );
  1193. delete params.items;
  1194.  
  1195. //defaults
  1196. this.node.style.position="absolute";
  1197. this.drawStyle="block";
  1198. //this.node.style.overflow=""; //make it expand as needed
  1199. this.position={top:"0px",right:"0px"};
  1200. //init
  1201. for (var p in params) this[p]=params[p];
  1202. //confirm(JSON.stringify(this));
  1203.  
  1204. //return it
  1205. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1206. return self;
  1207. }catch(e){log("jsForms.toolBox.init: "+e);}},
  1208. //listbox specific parts
  1209. listBox:function(params){try{
  1210. var self=this;
  1211. params=params||{};
  1212. //attach basic elements
  1213. self=extend(self, new jsForms.visualElement() );
  1214.  
  1215. //defaults
  1216. this._maxItems=32767;
  1217. this._maxSelectedItems=32767;
  1218. this._sorted=false;
  1219. this._sortBy=["text"];
  1220. this._sortOrder="asc";
  1221. this.listNode=this.node;
  1222. this._items=[];
  1223. this._firstItemSelectsAll=false;
  1224. this._explicitClose=false;
  1225. this._valueMember="value";
  1226. this._highlightSelected=false;
  1227. this.node.style.overflow="scroll";
  1228. this._allowMoveChildren=false;
  1229. //events
  1230. this.onItemSelected=null;
  1231. this.onItemChecked=null;
  1232. this.onItemUnselected=null;
  1233. this.onItemUnchecked=null;
  1234. this.onMaxItemsSelected=null;
  1235. //set the max number of items to show in the list
  1236. this.__defineGetter__("maxItems", function(){
  1237. return this._maxItems;
  1238. });
  1239. this.__defineSetter__("maxItems", function(v){try{
  1240. this._maxItems = parseInt(v);
  1241. }catch(e){log("jsForms.listBox.maxItems: "+e);}});
  1242.  
  1243. //set the max number of items that can be selected
  1244. this.__defineGetter__("maxSelectedItems", function(){
  1245. return this._maxSelectedItems;
  1246. });
  1247. this.__defineSetter__("maxSelectedItems", function(v){try{
  1248. this._maxSelectedItems = parseInt(v);
  1249. }catch(e){log("jsForms.listBox.maxSelectedItems: "+e);}});
  1250.  
  1251. //set if the list is to be sorted
  1252. this.__defineGetter__("sorted", function(){
  1253. return this._sorted;
  1254. });
  1255. this.__defineSetter__("sorted", function(v){try{
  1256. this._sorted = cBool(v);
  1257. if (this._sorted) this.sort();
  1258. }catch(e){log("jsForms.listBox.sorted: "+e);}});
  1259. //set if the list children can be moved around
  1260. this.__defineGetter__("allowMoveChildren", function(){
  1261. return this._allowMoveChildren;
  1262. });
  1263. this.__defineSetter__("allowMoveChilden", function(v){try{
  1264. this._allowMoveChildren = cBool(v);
  1265. //add||remove tools for each child
  1266. for (var i=0,child;(child=this.items[i]);i++){
  1267. if (this._allowMoveChildren) {
  1268. //add item to toolbox
  1269. } else {
  1270. //remove item from toolbox
  1271. }
  1272. }
  1273. }catch(e){log("jsForms.listBox.allowMoveChildren: "+e);}});
  1274.  
  1275. //set highlight if selected
  1276. this.__defineGetter__("highlightSelected", function(){
  1277. return this._highlightSelected;
  1278. });
  1279. this.__defineSetter__("highlightSelected", function(v){try{
  1280. this._highlightSelected = cBool(v);
  1281. for (var i=0,child;(child=this.items[i]);i++){
  1282. child.highlightSelected=this._highlightSelected;
  1283. }
  1284. }catch(e){log("jsForms.listBox.highlightSelected: "+e);}});
  1285.  
  1286. //set the parameters by which the list is to be sorted
  1287. this.__defineGetter__("sortBy", function(){
  1288. return this._sortBy;
  1289. });
  1290. this.__defineSetter__("sortBy", function(v){try{
  1291. if (isArray(v) || isString(v)) {
  1292. this._sortBy = v;
  1293. if (this._sorted) this.sort();
  1294. } else {
  1295. log("jsForms.listBox.sortBy: Expected array or string, found "+typeof v);
  1296. }
  1297. }catch(e){log("jsForms.listBox.sortBy: "+e);}});
  1298. //set the direction by which the sorting is done
  1299. this.__defineGetter__("sortOrder", function(){
  1300. return this._sortOrder;
  1301. });
  1302. this.__defineSetter__("sortOrder", function(v){try{
  1303. this._sortOrder = v.toString();
  1304. if (this._sorted) this.sort();
  1305. }catch(e){log("jsForms.listBox.sortOrder: "+e);}});
  1306.  
  1307. //get the items list of the list
  1308. this.__defineGetter__("items", function(){
  1309. return this._items;
  1310. });
  1311. this.__defineSetter__("items", function(v){try{
  1312. this._items = v;
  1313. }catch(e){log("jsForms.listBox.items: "+e);}});
  1314. //alias for items list
  1315. this.__defineGetter__("options", function(){
  1316. return this._items;
  1317. });
  1318.  
  1319. //set the parameter of the sub item that is to be used as a value
  1320. this.__defineGetter__("valueMember", function(){
  1321. return this._valueMember;
  1322. });
  1323. this.__defineSetter__("valueMember", function(v){try{
  1324. this._valueMember = (v.toString());
  1325. }catch(e){log("jsForms.listBox.valueMember: "+e);}});
  1326.  
  1327. //an object to display at the end of the
  1328. //...list that can be clicked to close a dropdown
  1329. this.__defineGetter__("explicitClose", function(){
  1330. return this._explicitClose;
  1331. });
  1332. this.__defineSetter__("explicitClose", function(v){try{
  1333. this._explicitClose = cBool(v);
  1334. }catch(e){log("jsForms.listBox.explicitClose: "+e);}});
  1335. //set if the special selectAll option appears
  1336. this.__defineGetter__("firstItemSelectsAll", function(){
  1337. return this._firstItemSelectsAll;
  1338. });
  1339. this.__defineSetter__("firstItemSelectsAll", function(v){try{
  1340. this._firstItemSelectsAll = cBool(v);
  1341. }catch(e){log("jsForms.listBox.firstItemSelectsAll: "+e);}});
  1342.  
  1343. //get the default value as text
  1344. this.__defineGetter__("value", function(){try{
  1345. var ret=[];
  1346. var sel=this.selectedItems;
  1347. for (var i=0,child;(child=sel[i]);i++){
  1348. ret.push(child[this._valueMember]);
  1349. }
  1350. return ret;
  1351. }catch(e){log("jsForms.listBox.value: "+e);}});
  1352. //get an array of selected options/checkboxes
  1353. this.__defineGetter__("selectedItems", function(){try{
  1354. var ret=[];
  1355. for (var i=0,child;(child=this.items[i]);i++){
  1356. if (exists(child.selected)) {
  1357. //check for option types that are selected
  1358. if (child.selected) ret.push(child);
  1359. } else if (exists(child.checked)) {
  1360. //check for checkbox types that are checked
  1361. if (child.checked) ret.push(child);
  1362. }
  1363. }
  1364. return ret;
  1365. }catch(e){log("jsForms.listBox.selectedItems: "+e);}});
  1366.  
  1367. //sort the list and redraw
  1368. //p accepts {direction:string, by:array:string}
  1369. //sorting is done using by[len-1] to by[0] so that
  1370. //...sorting by ["lastName","firstName"] results in
  1371. //...items being sorted by lastName first in the output
  1372. this.sort=function(p){try{
  1373. var params=p||{};
  1374. params.by=params.by||this._sortBy||["text"];
  1375. if (!isArray(params.by)) params.by=[].push(params.by);
  1376. params.direction=params.direction||this._sortOrder||"asc";
  1377. //var arrList=methodsToArray(this._items);
  1378. var arrList=this._items;
  1379. var dir=params.direction.toLowerCase();
  1380. //for each passed sort by entry, sort the list
  1381. for (var i=this.params.by.length,by;(by=this.params.by[i]);i--){
  1382. arrList.sort(function(a,b){
  1383. if (["ascending","asc"].inArray(dir)) return a[by]>=b[by];
  1384. if (["descending","desc"].inArray(dir)) return a[by]<=b[by];
  1385. return true;
  1386. });
  1387. };
  1388. //this._items=arrayToMethods(arrList);
  1389. this._items=arrList;
  1390. this.redraw();
  1391. }catch(e){log("jsForms.listBox.sort: "+e);}};
  1392. //redraw the list of items
  1393. this.redraw=function(){try{
  1394. //clear all items
  1395. for (var n in this.node){
  1396. remove(n);
  1397. }
  1398. //append selectall button if needed
  1399. if (this._firstItemSelectsAll) {
  1400. this.node.appendChild(this._selectAllNode);
  1401. }
  1402. //redraw in current order
  1403. for (var i=0,child;(child=this.items[i]);i++){
  1404. this.node.appendChild(child.node||child);
  1405. }
  1406. //append explicitclose button if needed
  1407. if (this._explicitClose){
  1408. this.node.appendChild(this._explicitCloseNode);
  1409. }
  1410. }catch(e){log("jsForms.listBox.redraw: "+e);}};
  1411. //generic close function, to be replaced by parent objects
  1412. this.close=function(){
  1413. this.visible=false;
  1414. };
  1415. //collapse the list down to a single element
  1416. this.collapse=function(){try{
  1417. this.node.style.height=this.items[0].node.offsetHeight;
  1418. this.node.style.overflowX="hidden";
  1419. this.node.style.overflowY="hidden";
  1420. }catch(e){log("jsForms.listBox.collapse: "+e);}};
  1421. //expand the list to the specified size
  1422. this.expand=function(){try{
  1423. this.node.style.height=this.size.height;
  1424. this.node.style.overflowX="hidden";
  1425. this.node.style.overflowY="scroll";
  1426. }catch(e){log("jsForms.listBox.expand: "+e);}};
  1427.  
  1428. //update visual details, such as border
  1429. this.borderStyle="FixedSingle";
  1430.  
  1431. //register the initial params
  1432. for (var p in params) {try{
  1433. this[p]=params[p];
  1434. }catch(e){log("jsForms.listBox.init(params "+p+"): "+e);}};
  1435. //modify children
  1436. for (var i=0,child;(child=this.items[i]);i++){try{
  1437. //append onchange value to every list item
  1438. child.onChange=function(){
  1439. if (self.causesValidation && self.onChange) {
  1440. doAction(function(){self.onChange(self);});
  1441. }
  1442. };
  1443. //change the drawstyle of each listitem
  1444. (child.node||child).style.display="block";
  1445. //set the highlightSelected attribute
  1446. child.highlightSelected=this._highlightSelected;
  1447. }catch(e){log("jsForms.listBox.init(modify children): "+e);}};
  1448. //create the maybe-needed explicit close button
  1449. this._explicitCloseNode=createElement("button",{
  1450. textContent:"Close",
  1451. style:(
  1452. "float:right;"+
  1453. ""//leave here
  1454. ),
  1455. onclick:function(){
  1456. if (self.close) doAction(function(){self.close();});
  1457. },
  1458. });
  1459. //create the maybe-needed select all node
  1460. var o=new jsForms.checkBox({
  1461. text:"Select All",
  1462. onChange:function(){
  1463. for (var i=0,child;(child=self._items[i]);i++){
  1464. if (exists(child.selected)) child.selected=this.checked;
  1465. if (exists(child.checked)) child.checked=this.checked;
  1466. }
  1467. },
  1468. });
  1469. this._selectAllNode=o.node;
  1470. o.labelNode.style.fontWeight="bold";
  1471. //draw it
  1472. this.node.style.overflowX="hidden";
  1473. this.node.style.overflowY="scroll";
  1474. this.redraw();
  1475. //return it
  1476. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1477. return self;
  1478. }catch(e){log("jsForms.listBox.init: "+e);}},
  1479.  
  1480. //combobox, dropdown, select-multi
  1481. comboBox:function(params){try{
  1482. var self=this;
  1483. params=params||{};
  1484. //attach basic elements
  1485. self=extend(self,new jsForms.textBox() );
  1486. //defaults
  1487. this._dropDownStyle="dropDown";
  1488. this._dropDownZIndex="999";
  1489. this.node.style.position="relative";
  1490. this.textNode.style.verticalAlign="middle";
  1491. this.textNode.disabled=true; //prevent typing in the box
  1492. //sub items
  1493. try{
  1494. this._dropDown=new jsForms.listBox({
  1495. parent:this,
  1496. items:params.items,
  1497. onChange:function(){
  1498. self.text=this.value;
  1499. //confirm(this.value);
  1500. },
  1501. firstItemSelectsAll:params.firstItemSelectsAll,
  1502. explicitClose:params.explicitClose,
  1503. backColor:params.backColor||"window",
  1504. //size:{width:"100%"},
  1505. highlightSelected:params.highlightSelected,
  1506. size:params.dropDownSize,
  1507. drawStyle:"block",
  1508. });
  1509. //close the dropdown by default
  1510. if (this._dropDownStyle!="simple") this._dropDown.hide();
  1511. this._dropDown.node.style.zIndex=this._dropDownZIndex;
  1512. this._dropDown.node.style.position="absolute";
  1513. //set the text based on what was passed as selected
  1514. this.text=this._dropDown.value;
  1515. }catch(e){log("jsForms.comboBox.init(create list): "+e);};
  1516. //scrap items we don't want appended to this object
  1517. delete params.items;
  1518. delete params.explicitClose;
  1519. delete params.firstItemSelectsAll;
  1520. delete params.highlightSelected;
  1521. delete params.dropDownSize;
  1522.  
  1523. //get the dropdown sub object
  1524. this.__defineGetter__("dropDown", function(){
  1525. return this._dropDown;
  1526. });
  1527.  
  1528. //set the dropdown visual style
  1529. //simple: no dropdown, elements shown directly below all the time
  1530. //dropdown: dropdown, elements in hidden list, allow typing in top box
  1531. //dropdownList: same as dropdown minus typing in top box
  1532. this.__defineGetter__("dropDownStyle", function(){
  1533. return this._dropDownStyle;
  1534. });
  1535. this.__defineSetter__("dropDownStyle", function(v){try{
  1536. this._dropDownStyle = (v.toString());
  1537. this._dropDown.visible=((this._dropDownStyle=="simple")?true:false);
  1538. }catch(e){log("jsForms.comboBox.dropDownStyle: "+e);}});
  1539.  
  1540. //set the z-index of the dropdown portion when open
  1541. this.__defineGetter__("dropDownZIndex", function(){
  1542. return this._dropDownZIndex;
  1543. });
  1544. this.__defineSetter__("dropDownZIndex", function(v){try{
  1545. this._dropDownZIndex = parseInt(v);
  1546. this._dropDown.node.style.zIndex=this._dropDownZIndex;
  1547. }catch(e){log("jsForms.comboBox.dropDownZIndex: "+e);}});
  1548. //redefine value: get the dropdown value array
  1549. this.__defineGetter__("value", function(){
  1550. return this._dropDown.value;
  1551. });
  1552. //show/hide dropdown
  1553. this.showDropDown=function(){
  1554. this._dropDown.show();
  1555. this.buttonTextNode.textContent="\u25B4";
  1556. };
  1557. this.hideDropDown=function(){
  1558. this._dropDown.hide();
  1559. this.buttonTextNode.textContent="\u25BE";
  1560. };
  1561. this.toggleDropDown=function(){
  1562. var dd=this._dropDown;
  1563. if (dd.visible) this.hideDropDown(); else this.showDropDown();
  1564. };
  1565. //register the initial params
  1566. for (var p in params) this[p]=params[p];
  1567. //append a button to the textbox portion
  1568. this.node.appendChild(
  1569. this.buttonNode=createElement("button",{
  1570. className:"jsfButton jsfinlineBlock",
  1571. onclick:function(){
  1572. self.toggleDropDown();
  1573. },
  1574. },[
  1575. this.buttonTextNode=createElement("span",{
  1576. textContent:"\u25BE",
  1577. })
  1578. ])
  1579. );
  1580. //append the dropdown list
  1581. this.node.appendChild(this._dropDown.node);
  1582. //resize its parts
  1583. this.fixSizes=function(){
  1584. var self=this;
  1585. //resize dropdown button
  1586. var btn=this.buttonNode;
  1587. var h=elementOuterHeight(this.textNode);
  1588. var i=elementOuterHeight(btn)-elementInnerHeight(btn);
  1589. if (!isNaN(h) && !isNaN(i) && h>0){
  1590. btn.style.height=(h-i)+"px";
  1591. var span=btn.childNodes[0];
  1592. span.style.left=
  1593. Math.floor((
  1594. elementInnerWidth(btn)-elementOuterWidth(span))/2
  1595. )+"px";
  1596. span.style.bottom=
  1597. Math.floor((
  1598. elementInnerHeight(btn)-elementOuterHeight(span))/2
  1599. )+"px";
  1600. } else {
  1601. setTimeout(function(){self.fixSizes();},100);
  1602. }
  1603.  
  1604. //resize dropdown
  1605. this._dropDown.node.style.width=
  1606. this.innerWidth-
  1607. (this._dropDown.outerWidth-this._dropDown.innerWidth)+
  1608. "px";
  1609. };
  1610. this.fixSizes();
  1611.  
  1612. //return it
  1613. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1614. return self;
  1615. }catch(e){log("jsForms.comboBox.init: "+e);}},
  1616.  
  1617. //css color picker
  1618. colorPicker:function(params){try{
  1619. var self=this;
  1620. params=params||{};
  1621. //attach basic elements
  1622. self=extend(self,new jsForms.textBox() );
  1623. //defaults
  1624. this._dropDownStyle="dropDown";
  1625. this._dropDownZIndex="999";
  1626. //functions
  1627. var spanClick=function(){
  1628. self.text=this.getAttribute("data-ft");
  1629. self.hideDropDowns();
  1630. self.colorBox.style.backgroundColor=self.text;
  1631. };
  1632. var makeSpans=function(data,e){
  1633. var ret=[];
  1634. if (isArrayAndNotEmpty(data)) for (var i=0,d;(d=data[i]);i++){
  1635. var value=(typeof d == "object")?d.value:d;
  1636. var name=(typeof d == "object")?d.name:d;
  1637. ret.push(createElement("span",{
  1638. onclick:spanClick,
  1639. style:(
  1640. //"color: white !important;"+
  1641. //"text-shadow: 0px 0px 1px black,0px 0px 1px black,0px 0px 1px black,0px 0px 1px black,0px 0px 1px black;"+
  1642. //"font-weight:bold;"+
  1643. "display:block;"+
  1644. ""//leave here
  1645. ),
  1646. "data-ft":value,
  1647. },[
  1648. createElement("div",{
  1649. style:(
  1650. "background-color:"+value+" !important;"+
  1651. "margin:0px 6px 0px 3px;"+
  1652. "border:1px solid black;"+
  1653. "width:20px; height:10px;"+
  1654. "vertical-align:baseline;"+
  1655. "display:inline-block;"+
  1656. ""//leave here
  1657. ),
  1658. }),
  1659. createElement("text",name)
  1660. ]));
  1661. }
  1662. return ret;
  1663. };
  1664. //sub items
  1665. var shareStyle=(
  1666. "background-color:"+(params.backColor||"window")+";"+
  1667. "height:"+params.dropDownSize.height+";"+
  1668. "z-index:"+this._dropDownZIndex+";"+
  1669. "position:absolute;"+
  1670. "display:none;"+
  1671. "overflow-x:hidden;"+
  1672. "overflow-y:auto;"+
  1673. ""//leave here
  1674. );
  1675. try{
  1676. this._webSafe=createElement("div",{
  1677. style:shareStyle,
  1678. },
  1679. makeSpans(jsForms.colorData.webSafe)
  1680. );
  1681. }catch(e){log("jsForms.colorPicker.init(webSafe): "+e);};
  1682. try{
  1683. this._colorWords=createElement("div",{
  1684. style:shareStyle,
  1685. },
  1686. makeSpans(jsForms.colorData.colorWords)
  1687. );
  1688. }catch(e){log("jsForms.colorPicker.init(colorWords): "+e);};
  1689. try{
  1690. this._system=createElement("div",{
  1691. style:shareStyle,
  1692. },
  1693. makeSpans(jsForms.colorData.system)
  1694. );
  1695. }catch(e){log("jsForms.colorPicker.init(system): "+e);};
  1696. try{
  1697. this._custom=createElement("div",{
  1698. style:shareStyle,
  1699. },
  1700. makeSpans(jsForms.colorData.custom)
  1701. );
  1702. }catch(e){log("jsForms.colorPicker.init(custom): "+e);};
  1703. delete params.dropDownSize;
  1704. //set the z-index of the dropdown portion when open
  1705. this.__defineGetter__("dropDownZIndex", function(){
  1706. return this._dropDownZIndex;
  1707. });
  1708. this.__defineSetter__("dropDownZIndex", function(v){try{
  1709. this._dropDownZIndex = parseInt(v);
  1710. this._webSafe.style.zIndex=this._dropDownZIndex;
  1711. this._system.style.zIndex=this._dropDownZIndex;
  1712. this._colorNames.style.zIndex=this._dropDownZIndex;
  1713. this._custom.style.zIndex=this._dropDownZIndex;
  1714. }catch(e){log("jsForms.colorPicker.dropDownZIndex: "+e);}});
  1715. //redefine value: get the dropdown value array
  1716. this.__defineGetter__("value", function(){
  1717. return this.textNode.value;
  1718. });
  1719.  
  1720. //resize the dropdown to fit our control
  1721. this.resizeDropDown=function(e){
  1722. var w=this.innerWidth-
  1723. ( elementOuterWidth(this[e])-elementInnerWidth(this[e]) )+
  1724. "px";
  1725. //confirm(w);
  1726. this[e].style.width=w;
  1727. };
  1728. //show/hide dropdown
  1729. this.showDropDown=function(e){
  1730. this.hideDropDowns();
  1731. this.resizeDropDown(e);
  1732. this[e].style.display="block"
  1733. };
  1734. this.hideDropDowns=function(){
  1735. this._webSafe.style.display="none";
  1736. this._system.style.display="none";
  1737. this._colorWords.style.display="none";
  1738. this._custom.style.display="none";
  1739. };
  1740. this.toggleDropDown=function(e){
  1741. var hidden=(this[e].style.display=="none");
  1742. if (hidden) this.showDropDown(e); else this.hideDropDowns();
  1743. };
  1744. //init
  1745. for (var p in params) this[p]=params[p];
  1746.  
  1747. //append a button to the textbox portion
  1748. this.node.style.position="relative";
  1749. this.node.appendChild(
  1750. createElement("button",{
  1751. style:(
  1752. "position: relative;"+
  1753. "font-size: 18px;"+
  1754. "padding: 0px;"+
  1755. "line-height: 0px;"+
  1756. "border: 1px solid buttonshadow;"+
  1757. "height:16px; width:17px;"+
  1758. "background-color: buttonface;"+
  1759. "box-shadow:1px 1px buttonhighlight inset, -1px -1px buttonhighlight inset;"+
  1760. "vertical-align:middle;"+
  1761. ""//leave here
  1762. ),
  1763. onclick:function(){
  1764. self.toggleDropDown("_webSafe");
  1765. },
  1766. },[
  1767. createElement("span",{
  1768. textContent:"\u25BE",
  1769. style:(
  1770. "position: relative;"+
  1771. "left:-3px;"+
  1772. ""//leave here
  1773. )
  1774. })
  1775. ])
  1776. );
  1777. this.node.appendChild(
  1778. createElement("button",{
  1779. style:(
  1780. "position: relative;"+
  1781. "font-size: 18px;"+
  1782. "padding: 0px;"+
  1783. "line-height: 0px;"+
  1784. "border: 1px solid buttonshadow;"+
  1785. "height:16px; width:17px;"+
  1786. "background-color: buttonface;"+
  1787. "box-shadow:1px 1px buttonhighlight inset, -1px -1px buttonhighlight inset;"+
  1788. "vertical-align:middle;"+
  1789. ""//leave here
  1790. ),
  1791. onclick:function(){
  1792. self.toggleDropDown("_colorWords");
  1793. },
  1794. },[
  1795. createElement("span",{
  1796. textContent:"\u25BE",
  1797. style:(
  1798. "position: relative;"+
  1799. "left:-3px;"+
  1800. ""//leave here
  1801. )
  1802. })
  1803. ])
  1804. );
  1805. this.node.appendChild(
  1806. createElement("button",{
  1807. style:(
  1808. "position: relative;"+
  1809. "font-size: 18px;"+
  1810. "padding: 0px;"+
  1811. "line-height: 0px;"+
  1812. "border: 1px solid buttonshadow;"+
  1813. "height:16px; width:17px;"+
  1814. "background-color: buttonface;"+
  1815. "box-shadow:1px 1px buttonhighlight inset, -1px -1px buttonhighlight inset;"+
  1816. "vertical-align:middle;"+
  1817. ""//leave here
  1818. ),
  1819. onclick:function(){
  1820. self.toggleDropDown("_system");
  1821. },
  1822. },[
  1823. createElement("span",{
  1824. textContent:"\u25BE",
  1825. style:(
  1826. "position: relative;"+
  1827. "left:-3px;"+
  1828. ""//leave here
  1829. )
  1830. })
  1831. ])
  1832. );
  1833. this.node.appendChild(
  1834. createElement("button",{
  1835. style:(
  1836. "position: relative;"+
  1837. "font-size: 18px;"+
  1838. "padding: 0px;"+
  1839. "line-height: 0px;"+
  1840. "border: 1px solid buttonshadow;"+
  1841. "height:16px; width:17px;"+
  1842. "background-color: buttonface;"+
  1843. "box-shadow:1px 1px buttonhighlight inset, -1px -1px buttonhighlight inset;"+
  1844. "vertical-align:middle;"+
  1845. ""//leave here
  1846. ),
  1847. onclick:function(){
  1848. self.toggleDropDown("_custom");
  1849. },
  1850. },[
  1851. createElement("span",{
  1852. textContent:"\u25BE",
  1853. style:(
  1854. "position: relative;"+
  1855. "left:-3px;"+
  1856. ""//leave here
  1857. )
  1858. })
  1859. ])
  1860. );
  1861. //append the dropdown list
  1862. this.node.appendChild(this._webSafe);
  1863. this.node.appendChild(this._colorWords);
  1864. this.node.appendChild(this._system);
  1865. this.node.appendChild(this._custom);
  1866. //append the colorbox before the textbox
  1867. this.colorBox=createElement("div",{
  1868. style:(
  1869. "background-color:"+this.text+";"+
  1870. "margin:0px 6px 0px 3px;"+
  1871. "border:1px solid black;"+
  1872. "width:20px; height:10px;"+
  1873. "vertical-align:middle;"+
  1874. "display:inline-block;"+
  1875. ""//leave here
  1876. ),
  1877. });
  1878. this.node.insertBefore(this.colorBox,this.textNode);
  1879. this.textNode.style.verticalAlign="middle";
  1880. var oldOnChange=this.textNode.onchange||null;
  1881. this.textNode.onchange=function(){
  1882. self.text=this.value;
  1883. self.colorBox.style.backgroundColor=this.value;
  1884. };
  1885. //return it
  1886. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  1887. return self;
  1888. }catch(e){log("jsForms.colorPicker.init: "+e);}},
  1889. //tabcontrol inner control
  1890. tabPage:function(params){try{
  1891. var self=this;
  1892. params=params||{};
  1893. //attach basic elements
  1894. self=extend(self,new jsForms.visualElement() );
  1895.  
  1896. //make sure we know our parent
  1897. this.parent=params.parent||null;
  1898. delete params.parent;
  1899.  
  1900. //defaults
  1901. this._text="";
  1902. this._image="";
  1903. //this._autoScroll=true;
  1904. this._showImage=true;
  1905. this.buttonNode=null;
  1906. this.imageNode=null;
  1907. this.textNode=null;
  1908. this.pageNode=null;
  1909. this._drawStyle="block";
  1910. //set the text shown in the tab button
  1911. this.__defineGetter__("text", function(){
  1912. return this._text;
  1913. });
  1914. this.__defineSetter__("text", function(v){try{
  1915. this._text = (v.toString());
  1916. if (this.textNode) this.textNode.textContent=this._text;
  1917. }catch(e){log("jsForms.tabPage.text: "+e);}});
  1918.  
  1919. //return if the parent knows we are selected
  1920. this.__defineGetter__("selected", function(){
  1921. return (this.parent._selectedTab===this);
  1922. });
  1923.  
  1924. //set the image shown in the tab button
  1925. this.__defineGetter__("image", function(){
  1926. return this._image;
  1927. });
  1928. this.__defineSetter__("image", function(v){try{
  1929. this._image = ((v||"").toString());
  1930. if (this.imageNode) {
  1931. this.imageNode.src=this._image;
  1932. this.imageNode.className=
  1933. this.imageNode.className[((this._showImage && (this._image||this._imageClass))?"remove":"add")+"Word"]("jsfHidden");
  1934. }
  1935. }catch(e){log("jsForms.tabPage.image: "+e);}});
  1936.  
  1937. //image className
  1938. this.__defineGetter__("imageClass", function(){
  1939. return this._imageClass;
  1940. });
  1941. this.__defineSetter__("imageClass", function(v){try{
  1942. var oldClass=this._imageClass;
  1943. this._imageClass = ((v||"").toString());
  1944. if (this.imageNode) {
  1945. this.imageNode.className=
  1946. this.imageNode.className.removeWord(oldClass).addWord(this._imageClass);
  1947. }
  1948. }catch(e){log("jsForms.tabPage.imageClass: "+e);}});
  1949.  
  1950. //show/hide the tab button image
  1951. this.__defineGetter__("showImage", function(){
  1952. return this._showImage;
  1953. });
  1954. this.__defineSetter__("showImage", function(v){try{
  1955. this._showImage = cBool(v);
  1956. if (this.imageNode) {
  1957. this.imageNode.className=
  1958. this.imageNode.className[((this._showImage && (this._image||this._imageClass))?"remove":"add")+"Word"]("jsfHidden");
  1959. }
  1960. }catch(e){log("jsForms.tabPage.showImage: "+e);}});
  1961.  
  1962. //select tab
  1963. this.select=function(){
  1964. this.parent.selectTab(this);
  1965. }
  1966. //init
  1967. var selected=params.selected||false;
  1968. delete params.selected;
  1969. var content=params.content||null;
  1970. delete params.content;
  1971. for (var p in params) this[p]=params[p];
  1972.  
  1973. //draw it
  1974. if (this.parent) {
  1975. //add button to parent node
  1976. this.parent.tabsNode.appendChild(
  1977. this.buttonNode=createElement("div",{
  1978. className:"jsfTab",
  1979. style:(
  1980. ""//leave here
  1981. ),
  1982. onclick:function(){self.select();},
  1983. },[
  1984. this.imageNode=createElement("img",{
  1985. className:this._imageClass+((this._showImage && (this._image||this._imageClass))?"":" jsfHidden"),
  1986. style:(
  1987. ""//leave here
  1988. ),
  1989. src:this._image||"",
  1990. }),
  1991. this.textNode=createElement("div",{
  1992. textContent:this._text.upperWords(),
  1993. style:(
  1994. ""//leave here
  1995. ),
  1996. }),
  1997. ])
  1998. );
  1999. //add page to parent node
  2000. if (content) {
  2001. if (!isArray(content)) content=[content];
  2002. for (var i=0,contentNode;(contentNode=content[i]);i++){
  2003. this.node.appendChild(contentNode);
  2004. }
  2005. }
  2006. this.parent.pagesNode.appendChild(this.node);
  2007. this.pageNode=this.node;
  2008. //make selected if needed
  2009. this.hide();
  2010. this.dock=this._dock;
  2011. if (selected) this.select();
  2012. }
  2013. //return it
  2014. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  2015. return self;
  2016. }catch(e){log("jsForms.tabPage.init: "+e);}},
  2017.  
  2018. //tabcontrol uppermost control
  2019. tabControl:function(params){try{
  2020. var self=this;
  2021. params=params||{};
  2022. //attach basic elements
  2023. self=extend(self,new jsForms.visualElement() );
  2024. //defaults
  2025. this._alignment="top"; //[top, left, right, bottom]
  2026. //this._appearance="normal"; //[normal,buttons,flat buttons]
  2027. this._hotTrack=true; //mouseover glow on buttons
  2028. this._multiLine=false; //allow multiple lines of tabs
  2029. //this._sizeMode="normal"; //[normal,fixed,filltoright]
  2030. this._shareSinglePage=false; //all tabs use the same pageNode
  2031. this.tabs=[];
  2032. this.tabsNode=null;
  2033. this.pagesNode=null;
  2034. this._selectedTab=null;
  2035. this.node.className=this.node.className.addWord("jsfTabControl hotTrack");
  2036. this.sharedPageNode=null; //container for shared tabPage
  2037. this.preventAutoSelectTab=false;
  2038.  
  2039. //subStyle
  2040. this.__defineGetter__("subStyle", function(){
  2041. return this._subStyle;
  2042. });
  2043. this.__defineSetter__("subStyle", function(v){try{
  2044. this.node.className=this.node.className.removeWord(this._subStyle);
  2045. this._subStyle = (v.toString());
  2046. this.node.className=this.node.className.addWord(this._subStyle);
  2047. }catch(e){log("jsForms.tabControl.subStyle: "+e);}});
  2048.  
  2049. //tabs alignment
  2050. this.__defineGetter__("alignment", function(){
  2051. return this._alignment;
  2052. });
  2053. this.__defineSetter__("alignment", function(v){try{
  2054. this._alignment = (v.toString().toLowerCase().upperWords());
  2055. //remove all alignment css words
  2056. this.node.className=this.node.className.removeWord(["alignTop","alignLeft","alignBottom","alignRight"]);
  2057. this.node.className=this.node.className.addWord("align"+this._alignment);
  2058. this.redraw();
  2059. }catch(e){log("jsForms.tabControl.alignment: "+e);}});
  2060.  
  2061. //tab bar hot tracking
  2062. this.__defineGetter__("hotTrack", function(){
  2063. return this._hotTrack;
  2064. });
  2065. this.__defineSetter__("hotTrack", function(v){try{
  2066. this._hotTrack = cBool(v);
  2067. this.node.className=this.node.className[((this._hotTrack)?"add":"remove")+"Word"]("hotTrack");
  2068. }catch(e){log("jsForms.tabControl.hotTrack: "+e);}});
  2069.  
  2070. //use a single tabPage for all tabs
  2071. this.__defineGetter__("shareSinglePage", function(){
  2072. return this._shareSinglePage;
  2073. });
  2074. this.__defineSetter__("shareSinglePage", function(v){try{
  2075. this._shareSinglePage = cBool(v);
  2076. }catch(e){log("jsForms.tabControl.shareSinglePage: "+e);}});
  2077.  
  2078. //select tab by index or by passed object
  2079. this.selectTab=function(v){try{
  2080. var lastSelected=this._selectedTab;
  2081. switch(typeof v){
  2082. case "object":
  2083. this._selectedTab=v;
  2084. break;
  2085. case "number":
  2086. this._selectedTab=this.tabs[v];
  2087. break;
  2088. }
  2089. //move the selected tab forward, unselected backward
  2090. if (lastSelected) {
  2091. if (!this._shareSinglePage) lastSelected.hide();
  2092. with (lastSelected.buttonNode) {
  2093. className=className.removeWord("selected");
  2094. }
  2095. }
  2096. if (!this._shareSinglePage) this._selectedTab.show();
  2097. with (this._selectedTab.buttonNode) {
  2098. className=className.addWord("selected");
  2099. }
  2100. //do onSelect event
  2101. if (this._selectedTab.onSelect) {
  2102. this._selectedTab.onSelect(this._selectedTab);
  2103. }
  2104. }catch(e){log("jsForms.tabControl.selectTab: "+e);}};
  2105. //capture the sizes we need for this tabcontrol
  2106. //and redraw its borders
  2107. this.redraw=function(){try{
  2108. //reset self first
  2109. this.dock=this._dock;
  2110. //pages fit this minus the tabs bar
  2111. this.pagesNode.style.height=
  2112. (this._alignment=="Top" || this._alignment=="Bottom")?(
  2113. this.innerHeight
  2114. - elementOuterHeight(this.tabsNode)
  2115. - (
  2116. elementOuterHeight(this.pagesNode)
  2117. - elementInnerHeight(this.pagesNode)
  2118. ) + "px"
  2119. ):(
  2120. this.innerHeight
  2121. -(
  2122. elementOuterHeight(this.pagesNode)
  2123. - elementInnerHeight(this.pagesNode)
  2124. ) + "px"
  2125. );
  2126. this.pagesNode.style.width=
  2127. (this._alignment=="Left" || this._alignment=="Right")?(
  2128. this.innerWidth
  2129. - elementOuterWidth(this.tabsNode)
  2130. - (
  2131. elementOuterWidth(this.pagesNode)
  2132. - elementInnerWidth(this.pagesNode)
  2133. ) + "px"
  2134. ):("");//automatic
  2135. //order the tabs in relation to the pages based on alignment
  2136. if (this._alignment=="Bottom" || this._alignment=="Right"){
  2137. this.node.insertBefore(this.pagesNode,this.tabsNode);
  2138. } else {
  2139. this.node.insertBefore(this.tabsNode,this.pagesNode);
  2140. }
  2141. }catch(e){log("jsForms.tabControl.redraw: "+e);}};
  2142. //addTab using tab construction params
  2143. this.addTab=function(params){try{
  2144. params.parent=this;
  2145. var tab;
  2146. this.tabs.push(tab=new jsForms.tabPage(params));
  2147. return tab;
  2148. }catch(e){log("jsForms.tabControl.addTab: "+e);}};
  2149.  
  2150. //removeTab using tab object reference
  2151. this.removeTab=function(tab){try{
  2152. this.tabs.removeByValue(tab);
  2153. remove(tab.node);
  2154. }catch(e){log("jsForms.tabControl.removeTab: "+e);}};
  2155. //create tab button container
  2156. this.node.appendChild(
  2157. this.tabsNode=createElement("div",{
  2158. className:"tabs",
  2159. style:(
  2160. ((!this._multiLine)?"overflow: hidden;":"")+
  2161. //(!this._multiLine)?"height:24px;":""+
  2162. //"width:"+(parseInt(this.size.width)-5)+"px;"+
  2163. ""//leave here
  2164. ),
  2165. })
  2166. );
  2167. //append tab page container
  2168. this.node.appendChild(
  2169. this.pagesNode=createElement("div",{
  2170. className:"pages",
  2171. style:(
  2172. ((this._autoFit)?"display:block;":"")+
  2173. //(!this._multiLine && this.size.height)?"height:"+(parseInt(this.size.height)-32)+"px;":""+
  2174. ""//leave here
  2175. ),
  2176. })
  2177. );
  2178. //append a shared tabPage if required
  2179. this._shareSinglePage=params.shareSinglePage||false;
  2180. if (this._shareSinglePage){
  2181. var content=params.sharedContent;
  2182. delete params.sharedContent;
  2183. if (content) {
  2184. if (!isArray(content)) content=[content];
  2185. }
  2186. this.pagesNode.appendChild(
  2187. this.sharedPageNode=createElement("div",{},content)
  2188. );
  2189. }
  2190. //init the tabs
  2191. if (isArrayAndNotEmpty(params.tabs)) {
  2192. for (var i=0,tab;(tab=params.tabs[i]);i++) {
  2193. this.addTab(tab);
  2194. }
  2195. //select an initial tab if none already selected
  2196. var autoTab=!(params.preventAutoSelectTab||false);
  2197. if (autoTab && !this._selectedTab) this.selectTab(0);
  2198. }
  2199. delete params.tabs;
  2200. //init the rest
  2201. for (var p in params) this[p]=params[p];
  2202. //draw
  2203. this.alignment=this._alignment; //and it redraws here
  2204. //return it
  2205. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  2206. return self;
  2207. }catch(e){log("jsForms.tabControl.init: "+e);}},
  2208. //coolBar version of tabcontrol
  2209. coolBar:function(params){try{
  2210. var self=this;
  2211. params=params||{};
  2212. params.hotTrack=true;
  2213. params.subStyle="coolBar";
  2214. //attach basic elements
  2215. //this is basically the exact same thing as a tabcontrol
  2216. self=extend(self,new jsForms.tabControl(params) );
  2217. //return it
  2218. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  2219. return self;
  2220. }catch(e){log("jsForms.coolBar.init: "+e);}},
  2221.  
  2222. //treeview inner controls
  2223. treeNode:function(params){try{
  2224. var self=this;
  2225. params=params||{};
  2226. //attach basic elements
  2227. self=extend(self,new jsForms.visualElement() );
  2228.  
  2229. //defaults
  2230. this._text="";
  2231. this._checked=false;
  2232. this._image="";
  2233. this._selected=false;
  2234. this.TreeView=null;
  2235. //fullPath
  2236. //getNodeCount //full count of child tree nodes
  2237. //level //depth in the tree
  2238. //remove
  2239. //isEditing
  2240. //toggle (expanded/collapsed)
  2241.  
  2242. //edit label
  2243. this.beginEdit=function(){
  2244. };
  2245. this.endEdit=function(){
  2246. };
  2247. //expand/collapse (with children)
  2248. this.expand=function(ignoreChildren){
  2249. };
  2250. this.collapse=function(ignoreChildren){
  2251. };
  2252. //copy
  2253. this.clone=function(){
  2254. };
  2255. //open parent nodes and scroll into view
  2256. this.ensureVisible=function(){
  2257. };
  2258. //init
  2259. for (var p in params) this[p]=params[p];
  2260. //return it
  2261. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  2262. return self;
  2263. }catch(e){log("jsForms.treeNode.init: "+e);}},
  2264.  
  2265. //treeview uppermost control
  2266. treeView:function(params){try{
  2267. var self=this;
  2268. params=params||{};
  2269. //attach basic elements
  2270. self=extend(self, new jsForms.visualElement() );
  2271.  
  2272. //defaults
  2273. this._checkBoxes=false; //show checkboxes at nodes
  2274. this._fullRowSelect=false; //highlight the entire child
  2275. this._hotTracking=true;
  2276. this._indent="28px";
  2277. this._labelEdit=false; //allow edit of labels on node
  2278. this._nodes=[];
  2279. this._pathSeparator="\\";
  2280. this._scrollable=true;
  2281. this._showLines=false; //show node lines
  2282. this._showPlusMinus=true;
  2283. this._showRootLines=true;
  2284. this._sortBy="value";
  2285. this._sortOrder="asc";
  2286. //get the dropdown sub object
  2287. this.__defineGetter__("hasChildren", function(){
  2288. return (this._nodes.length>0);
  2289. });
  2290. //add remove nodes
  2291. this.addRoot=function(node){
  2292. //draw it
  2293. //add it
  2294. this._nodes.push(node);
  2295. };
  2296. //expand/collapse nodes
  2297. this.collapseAll=function(){
  2298. for (var i=0,child;(child=this._nodes[i]);i++) child.collapseAll();
  2299. };
  2300. this.expandAll=function(){
  2301. for (var i=0,child;(child=this._nodes[i]);i++) child.expandAll();
  2302. };
  2303. //sort nodes
  2304. this.sort=function(){
  2305. };
  2306. //init
  2307. for (var p in params) this[p]=params[p];
  2308. //return it
  2309. if (self.causesValidation && self.onCreated) doAction(function(){self.onCreated(self);});
  2310. return self;
  2311. }catch(e){log("jsForms.treeView.init: "+e);}},
  2312.  
  2313. };
  2314. /*to do list
  2315. dropDown: simplified comboBox with only one item selectable
  2316. checkedListBox: uses listBox and assumes checks based on bound data or simple input
  2317. checkedDropDown: uses comboBox and assumes checks
  2318. bindToData function
  2319. checkbox: check-image-text ordering/layout
  2320. checkbox: check hidden
  2321. */
  2322. //JSON-ready testing page
  2323. if (window.location.href.match(/^(http:\/\/www\.facebook\.com\/test)/) ||
  2324. window.location.href.match(/^(file:\/\/\/C:\/Users\/Charlie\/Desktop)/) ) {
  2325. var textBox = new jsForms.textBox({
  2326. text:"hello world",
  2327. backColor:"window",
  2328. foreColor:"windowtext",
  2329. font:'"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif',
  2330. //borderStyle:"Fixed3D",
  2331. borderRadius:{topLeft:"5px", bottomRight:"5px"},
  2332. onChange:function(o){
  2333. confirm(o.text);
  2334. },
  2335. });
  2336. document.documentElement.appendChild(textBox.node,document.documentElement.childNodes[0]);
  2337. var spinBox = new jsForms.spinBox({
  2338. text:"3",
  2339. backColor:"window",
  2340. foreColor:"windowtext",
  2341. minimum:0,
  2342. maximum:10,
  2343. rollOver:true,
  2344. increment:1,
  2345. });
  2346. document.documentElement.appendChild(spinBox.node,document.documentElement.childNodes[0]);
  2347.  
  2348. var checkBox = new jsForms.checkBox({
  2349. text:"hello world",
  2350. value:"1",
  2351. checked:true,
  2352. font:'"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif',
  2353. onChange:function(o){
  2354. confirm(o.checked);
  2355. },
  2356. });
  2357. document.documentElement.appendChild(checkBox.node,document.documentElement.childNodes[0]);
  2358. var listBox = new jsForms.listBox({
  2359. font:'"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif',
  2360. onChange:function(o){
  2361. //confirm(o.value);
  2362. },
  2363. items:[
  2364. new jsForms.checkBox({text:"hello world"}),
  2365. new jsForms.checkBox({text:"hello moon"}),
  2366. new jsForms.checkBox({text:"goodnight moon"}),
  2367. ],
  2368. borderStyle:"Fixed3D",
  2369. firstItemSelectsAll:true,
  2370. explicitClose:true,
  2371. });
  2372. document.documentElement.appendChild(listBox.node,document.documentElement.childNodes[0]);
  2373. var postParts = {
  2374. //derived from post.testData
  2375. //this stuff is created in the main.which call
  2376. //so if that is not called yet, each will be undefined
  2377. "title":"The title of a post contains the bold text, usually including the poster's name, at the top of the post.",
  2378. "msg":"The msg of a post is the part the poster added as a comment.",
  2379. "caption":"The caption of a post is one of two lines just below the title.",
  2380. "desc":"The desc of a post is one of two lines just below the title.",
  2381. "link":"The link of a post is just the ORIGINAL link text, not the url.",
  2382. "url":"The url of a post is the address to which the post redirects the user when clicked.",
  2383. "img":"The img of a post is the url of the icon that displays with the post.",
  2384. "fromName":"The fromName is the name of the poster.",
  2385. "fromID":"The fromID is the ID of the poster.",
  2386. "targetName":"The targetName is a list of targets the poster intended the post to display to.",
  2387. "targetID":"The targetID is a list of targets' IDs that the poster intended the post to display to.",
  2388. "canvas":"The canvas of a post is location of the game code.",
  2389. "likeName":"The likeName is a list of names of users who liked this post.",
  2390. "likeID":"The likeID is a list of IDs of users who liked the post.",
  2391. "comments":"The comments is a list of all comments made to the post, excluding the initial msg.",
  2392. "commentorName":"The commentorName is a list of names of all commentors.",
  2393. "commentorID":"The commentorID is a list of IDs of all commentors.",
  2394. "body":"The body of a post is a compilation of the title, caption, and desc.",
  2395. "either":"The either of a post is the compilation of the link and body.",
  2396. "html":"The html of a post is the compilation of ALL visible FB attributes.",
  2397. //right from the post object
  2398. "which":"The which of a post is its identified codename. The codename starts with an appID and ends with something the sidekick developer uses to key the bonus type.",
  2399. "idText":"The identified link text of a post.",
  2400. "date":"The date of a post is its creation time on FB. This time is read as a unix date.", //read as unix time
  2401. "status":"The status of a post is the return code created by the sidekick.",
  2402. "priority":"The priority of a post is set by the prioritizer.",
  2403. "appID":"The appID of the game for which this post belongs.",
  2404. "appName":"The appName of the game for which this post belongs, as reported by the FB database.",
  2405. "isStale":"Reports if a post is older than the user-set older limit.",
  2406. "isScam":"Reports if a post is suspected of being a scam. Usually if the canvas and appName do not match.",
  2407. "isCollect":"Reports if the post is set to be collected.",
  2408. "isExcluded":"Reports if the post has been set as excluded.",
  2409. "isFailed":"Reports if the post is set as having already failed.",
  2410. "isAccepted":"Reports if the post is set as having already been successfully collected.",
  2411. "isPaused":"Reports if the post's bonus type or app has been paused by the prioritizer. Paused objects to not process for collection.",
  2412. "isPinned":"Reports if the post is marked as being pinned.",
  2413. "isLiked":"Reports if the post has been identified as already being liked by the current user.",
  2414. "isMyPost":"Reports if the post belongs to the current user.",
  2415. "isUndefined":"Reports if the post does not match any id given by the sidekick.",
  2416. "isWishlist":"Reports if the post is deemed a whichlist request.",
  2417. "isTimeout":"Reports if the post has been marked as a timed out collection try.",
  2418. "isW2W":"Reports if the post is a Wall-To-Wall post, meaning that it was posted to a specific user's wall.",
  2419. "isForMe":"Reports if the W2W post targets the current user."
  2420. };
  2421. var search=["body"];
  2422.  
  2423. var comboBox = new jsForms.comboBox({
  2424. font:'"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif',
  2425. onChange:function(o){
  2426. GM_log("combo changed");
  2427. },
  2428. items:(function(){
  2429. var ret=[];
  2430. for (var i in postParts){
  2431. ret.push(new jsForms.checkBox({
  2432. text:i,
  2433. value:i,
  2434. toolTipText:postParts[i],
  2435. checked:(search.inArray(i)),
  2436. size:{width:"200%"},
  2437. }));
  2438. }
  2439. return ret;
  2440. })(),
  2441. borderStyle:"Fixed3D",
  2442. borderRadius:{topLeft:"1px", bottomRight:"1px",topRight:"1px",bottomLeft:"1px"},
  2443. explicitClose:true,
  2444. highlightSelected:true,
  2445. dropDownSize:{height:"200px"},
  2446. sorted:true,
  2447. });
  2448. document.documentElement.appendChild(comboBox.node,document.documentElement.childNodes[0]);
  2449.  
  2450. //just a divider
  2451. document.documentElement.appendChild(createElement("div"));
  2452. var myConsole={};
  2453. var tabControl = new jsForms.tabControl({
  2454. //font:'"Bebas Neue","League Gothic",Haettenschweiler,"Arial Narrow",sans-serif',
  2455. tabs:[
  2456. {
  2457. text:"Tabs",
  2458. image:"file:///C:/Users/Charlie/Documents/From%20Disk%202/Wikia%20Frontwall/selLast.png",
  2459. //selected:true,
  2460. content:createElement("div",{},[
  2461. createElement("label",{textContent:"Alignment: "}),
  2462. createElement("select",{
  2463. onchange:function(){
  2464. tabControl.alignment=this.value;
  2465. },
  2466. },optionsFromArray([
  2467. "Top","Right","Bottom","Left"
  2468. ])),
  2469. createElement("br"),
  2470. createElement("label",{textContent:"hotTrack: "}),
  2471. createElement("select",{
  2472. onchange:function(){
  2473. tabControl.hotTrack=this.value;
  2474. },
  2475. },optionsFromArray([
  2476. "false","true"
  2477. ])),
  2478. createElement("br"),
  2479. createElement("label",{textContent:"subStyle: "}),
  2480. createElement("select",{
  2481. onchange:function(){
  2482. tabControl.subStyle=this.value;
  2483. },
  2484. },optionsFromArray([
  2485. "normal","coolBar"
  2486. ])),
  2487. ])
  2488. },
  2489. {
  2490. text:"red phone",
  2491. image:"file:///C:/Users/Charlie/Documents/From%20Disk%202/Wikia%20Frontwall/red%20phone%20128.png",
  2492. },
  2493. {
  2494. text:"firefox",
  2495. image:"file:///C:/Users/Charlie/Documents/From%20Disk%202/Wikia%20Frontwall/firefox_icon.png",
  2496. },
  2497. ],
  2498. dock:"fill",
  2499. });
  2500. (myConsole.phoneTab=tabControl.tabs[1]).node.appendChild(
  2501. new jsForms.textBox().node
  2502. );
  2503. (myConsole.ffTab=tabControl.tabs[2]).node.textContent="FireFox is the best!";
  2504. document.documentElement.appendChild(
  2505. createElement("div",{
  2506. style:(
  2507. "height:500px;"+
  2508. ""//leave here
  2509. ),
  2510. },[
  2511. tabControl.node
  2512. ])
  2513. );
  2514. tabControl.redraw();
  2515.  
  2516. var colorPicker = new jsForms.colorPicker({
  2517. borderStyle:"none",
  2518. dropDownSize:{height:"200px"},
  2519. sorted:true,
  2520. text:"",
  2521. });
  2522. document.documentElement.appendChild(colorPicker.node,document.documentElement.childNodes[0]);
  2523.  
  2524. };
  2525. //add own css
  2526. try{addGlobalStyle(jsForms.globalStyle(),"jsForms");}catch(e){log("jsForms.addGlobalStyle: "+e);};
  2527. })();