Greasy Fork is available in English.

JS Forms Library B

Encapulates and extends many HTML forms elements.

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greatest.deepsurf.us/scripts/418/1300/JS%20Forms%20Library%20B.js

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