PageRenderTime 63ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/_core/qcodo.js

https://github.com/timfong888/AF-upload
JavaScript | 372 lines | 245 code | 82 blank | 45 comment | 78 complexity | be4024ed67c3012eb3854987220343b0 MD5 | raw file
  1. ///////////////////////////////////////////////////
  2. // The Qcodo Object is used for everything in Qcodo
  3. ///////////////////////////////////////////////////
  4. var qcodo = {
  5. initialize: function() {
  6. ////////////////////////////////
  7. // Browser-related functionality
  8. ////////////////////////////////
  9. this.isBrowser = function(intBrowserType) {
  10. return (intBrowserType & qcodo._intBrowserType);
  11. };
  12. this.IE = 1;
  13. this.IE_6_0 = 2;
  14. this.IE_7_0 = 4;
  15. this.IE_8_0 = 8;
  16. this.FIREFOX = 16;
  17. this.FIREFOX_1_0 = 32;
  18. this.FIREFOX_1_5 = 64;
  19. this.FIREFOX_2_0 = 128;
  20. this.FIREFOX_3_0 = 256;
  21. this.SAFARI = 512;
  22. this.SAFARI_2_0 = 1024;
  23. this.SAFARI_3_0 = 2048;
  24. this.SAFARI_4_0 = 4096;
  25. this.OPERA = 8192;
  26. this.OPERA_7 = 16384;
  27. this.OPERA_8 = 32768;
  28. this.OPERA_9 = 65536;
  29. this.KONQUEROR = 131072;
  30. this.KONQUEROR_3 = 262144;
  31. this.KONQUEROR_4 = 524288;
  32. this.CHROME = 1048576;
  33. this.CHROME_0 = 2097152;
  34. this.CHROME_1 = 4194304;
  35. this.WINDOWS = 8388608;
  36. this.LINUX = 16777216;
  37. this.MACINTOSH = 33554432;
  38. this.UNSUPPORTED = 67108864;
  39. var strUserAgent = navigator.userAgent.toLowerCase();
  40. this._intBrowserType = 0;
  41. // INTERNET EXPLORER (supporting versions 6.0 and 7.0 and eventually 8.0)
  42. if (strUserAgent.indexOf("msie") >= 0) {
  43. this._intBrowserType = this._intBrowserType | this.IE;
  44. if (strUserAgent.indexOf("msie 6.0") >= 0)
  45. this._intBrowserType = this._intBrowserType | this.IE_6_0;
  46. else if (strUserAgent.indexOf("msie 7.0") >= 0)
  47. this._intBrowserType = this._intBrowserType | this.IE_7_0;
  48. else if (strUserAgent.indexOf("msie 8.0") >= 0)
  49. this._intBrowserType = this._intBrowserType | this.IE_8_0;
  50. else
  51. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  52. // FIREFOX (supporting versions 1.0, 1.5, 2.0 and eventually 3.0)
  53. } else if ((strUserAgent.indexOf("firefox") >= 0) || (strUserAgent.indexOf("iceweasel") >= 0)) {
  54. this._intBrowserType = this._intBrowserType | this.FIREFOX;
  55. strUserAgent = strUserAgent.replace('iceweasel/', 'firefox/');
  56. if (strUserAgent.indexOf("firefox/1.0") >= 0)
  57. this._intBrowserType = this._intBrowserType | this.FIREFOX_1_0;
  58. else if (strUserAgent.indexOf("firefox/1.5") >= 0)
  59. this._intBrowserType = this._intBrowserType | this.FIREFOX_1_5;
  60. else if (strUserAgent.indexOf("firefox/2.0") >= 0)
  61. this._intBrowserType = this._intBrowserType | this.FIREFOX_2_0;
  62. else if (strUserAgent.indexOf("firefox/3.0") >= 0)
  63. this._intBrowserType = this._intBrowserType | this.FIREFOX_3_0;
  64. else
  65. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  66. // SAFARI (supporting version 2.0 and eventually 3.0 and 4.0)
  67. } else if (strUserAgent.indexOf("safari") >= 0) {
  68. this._intBrowserType = this._intBrowserType | this.SAFARI;
  69. if (strUserAgent.indexOf("version/4") >= 0)
  70. this._intBrowserType = this._intBrowserType | this.SAFARI_4_0;
  71. else if (strUserAgent.indexOf("version/3") >= 0 || strUserAgent.indexOf("safari/52") >= 0)
  72. this._intBrowserType = this._intBrowserType | this.SAFARI_3_0;
  73. else if (strUserAgent.indexOf("version/2") >= 0 || strUserAgent.indexOf("safari/41") >= 0)
  74. this._intBrowserType = this._intBrowserType | this.SAFARI_2_0;
  75. else
  76. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  77. // KONQUEROR (eventually supporting versions 3 and 4)
  78. } else if (strUserAgent.indexOf("konqueror") >= 0) {
  79. this._intBrowserType = this._intBrowserType | this.KONQUEROR;
  80. if (strUserAgent.indexOf("konqueror/3") >= 0)
  81. this._intBrowserType = this._intBrowserType | this.KONQUEROR_3;
  82. else if (strUserAgent.indexOf("konqueror/4") >= 0)
  83. this._intBrowserType = this._intBrowserType | this.KONQUEROR_4;
  84. else
  85. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  86. }
  87. // OPERA (eventually supporting versions 7, 8 and 9)
  88. if (strUserAgent.indexOf("opera") >= 0) {
  89. this._intBrowserType = this._intBrowserType | this.OPERA;
  90. if (strUserAgent.indexOf("opera/7") >= 0 || strUserAgent.indexOf("opera 7") >= 0)
  91. this._intBrowserType = this._intBrowserType | this.OPERA_7;
  92. else if (strUserAgent.indexOf("opera/8") >= 0 || strUserAgent.indexOf("opera 8") >= 0)
  93. this._intBrowserType = this._intBrowserType | this.OPERA_8;
  94. else if (strUserAgent.indexOf("opera/9") >= 0 || strUserAgent.indexOf("opera 9") >= 0)
  95. this._intBrowserType = this._intBrowserType | this.OPERA_9;
  96. else
  97. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  98. }
  99. // CHROME (eventually supporting versions 0 and 1)
  100. if (strUserAgent.indexOf("chrome") >= 0) {
  101. this._intBrowserType = this._intBrowserType | this.CHROME;
  102. if (strUserAgent.indexOf("chrome/0") >= 0)
  103. this._intBrowserType = this._intBrowserType | this.CHROME_0;
  104. else if (strUserAgent.indexOf("chrome/1") >= 0)
  105. this._intBrowserType = this._intBrowserType | this.CHROME_1;
  106. else
  107. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  108. }
  109. // COMPLETELY UNSUPPORTED
  110. if (this._intBrowserType == 0)
  111. this._intBrowserType = this._intBrowserType | this.UNSUPPORTED;
  112. // OS (supporting Windows, Linux and Mac)
  113. if (strUserAgent.indexOf("windows") >= 0)
  114. this._intBrowserType = this._intBrowserType | this.WINDOWS;
  115. else if (strUserAgent.indexOf("linux") >= 0)
  116. this._intBrowserType = this._intBrowserType | this.LINUX;
  117. else if (strUserAgent.indexOf("macintosh") >= 0 || navigator.userAgent.toLowerCase().indexOf("mac os") >= 0)
  118. this._intBrowserType = this._intBrowserType | this.MACINTOSH;
  119. ////////////////////////////////
  120. // Browser-related functionality
  121. ////////////////////////////////
  122. this.loadJavaScriptFile = function(strScript, objCallback) {
  123. strScript = qc.jsAssets + "/" + strScript;
  124. var objNewScriptInclude = document.createElement("script");
  125. objNewScriptInclude.setAttribute("type", "text/javascript");
  126. objNewScriptInclude.setAttribute("src", strScript);
  127. document.getElementById(document.getElementById("Qform__FormId").value).appendChild(objNewScriptInclude);
  128. // IE does things differently...
  129. if (qc.isBrowser(qcodo.IE)) {
  130. objNewScriptInclude.callOnLoad = objCallback;
  131. objNewScriptInclude.onreadystatechange = function() {
  132. if ((this.readyState == "complete") || (this.readyState == "loaded"))
  133. if (this.callOnLoad)
  134. this.callOnLoad();
  135. };
  136. // ... than everyone else
  137. } else {
  138. objNewScriptInclude.onload = objCallback;
  139. };
  140. };
  141. this.loadStyleSheetFile = function(strStyleSheetFile, strMediaType) {
  142. strStyleSheetFile = qc.cssAssets + "/" + strStyleSheetFile;
  143. // IE does things differently...
  144. if (qc.isBrowser(qcodo.IE)) {
  145. var objNewScriptInclude = document.createStyleSheet(strStyleSheetFile);
  146. // ...than everyone else
  147. } else {
  148. var objNewScriptInclude = document.createElement("style");
  149. objNewScriptInclude.setAttribute("type", "text/css");
  150. objNewScriptInclude.setAttribute("media", strMediaType);
  151. objNewScriptInclude.innerHTML = '@import "' + strStyleSheetFile + '";';
  152. document.body.appendChild(objNewScriptInclude);
  153. };
  154. };
  155. /////////////////////////////
  156. // QForm-related functionality
  157. /////////////////////////////
  158. this.registerForm = function() {
  159. // "Lookup" the QForm's FormId
  160. var strFormId = document.getElementById("Qform__FormId").value;
  161. // Register the Various Hidden Form Elements needed for QForms
  162. this.registerFormHiddenElement("Qform__FormControl", strFormId);
  163. this.registerFormHiddenElement("Qform__FormEvent", strFormId);
  164. this.registerFormHiddenElement("Qform__FormParameter", strFormId);
  165. this.registerFormHiddenElement("Qform__FormCallType", strFormId);
  166. this.registerFormHiddenElement("Qform__FormUpdates", strFormId);
  167. this.registerFormHiddenElement("Qform__FormCheckableControls", strFormId);
  168. };
  169. this.registerFormHiddenElement = function(strId, strFormId) {
  170. var objHiddenElement = document.createElement("input");
  171. objHiddenElement.type = "hidden";
  172. objHiddenElement.id = strId;
  173. objHiddenElement.name = strId;
  174. document.getElementById(strFormId).appendChild(objHiddenElement);
  175. };
  176. this.wrappers = new Array();
  177. ////////////////////////////////////
  178. // Mouse Drag Handling Functionality
  179. ////////////////////////////////////
  180. this.enableMouseDrag = function() {
  181. document.onmousedown = qcodo.handleMouseDown;
  182. document.onmousemove = qcodo.handleMouseMove;
  183. document.onmouseup = qcodo.handleMouseUp;
  184. };
  185. this.handleMouseDown = function(objEvent) {
  186. objEvent = qcodo.handleEvent(objEvent);
  187. var objHandle = qcodo.target;
  188. if (!objHandle) return true;
  189. var objWrapper = objHandle.wrapper;
  190. if (!objWrapper) return true;
  191. // Qcodo-Wide Mouse Handling Functions only operate on the Left Mouse Button
  192. // (Control-specific events can respond to QRightMouse-based Events)
  193. if (qcodo.mouse.left) {
  194. if (objWrapper.handleMouseDown) {
  195. // Specifically for Microsoft IE
  196. if (objHandle.setCapture)
  197. objHandle.setCapture();
  198. // Ensure the Cleanliness of Dragging
  199. objHandle.onmouseout = null;
  200. if (document.selection)
  201. document.selection.empty();
  202. qcodo.currentMouseHandleControl = objWrapper;
  203. return objWrapper.handleMouseDown(objEvent, objHandle);
  204. };
  205. };
  206. qcodo.currentMouseHandleControl = null;
  207. return true;
  208. };
  209. this.handleMouseMove = function(objEvent) {
  210. objEvent = qcodo.handleEvent(objEvent);
  211. if (qcodo.currentMouseHandleControl) {
  212. var objWrapper = qcodo.currentMouseHandleControl;
  213. var objHandle = objWrapper.handle;
  214. // In case IE accidentally marks a selection...
  215. if (document.selection)
  216. document.selection.empty();
  217. if (objWrapper.handleMouseMove)
  218. return objWrapper.handleMouseMove(objEvent, objHandle);
  219. };
  220. return true;
  221. };
  222. this.handleMouseUp = function(objEvent) {
  223. objEvent = qcodo.handleEvent(objEvent);
  224. if (qcodo.currentMouseHandleControl) {
  225. var objWrapper = qcodo.currentMouseHandleControl;
  226. var objHandle = objWrapper.handle;
  227. // In case IE accidentally marks a selection...
  228. if (document.selection)
  229. document.selection.empty();
  230. // For IE to release release/setCapture
  231. if (objHandle.releaseCapture) {
  232. objHandle.releaseCapture();
  233. objHandle.onmouseout = function() {this.releaseCapture()};
  234. };
  235. qcodo.currentMouseHandleControl = null;
  236. if (objWrapper.handleMouseUp)
  237. return objWrapper.handleMouseUp(objEvent, objHandle);
  238. };
  239. return true;
  240. };
  241. ////////////////////////////////////
  242. // Window Unloading
  243. ////////////////////////////////////
  244. this.unloadFlag = false;
  245. this.handleUnload = function() {
  246. qcodo.unloadFlag = true;
  247. };
  248. window.onunload= this.handleUnload;
  249. this.beforeUnloadFlag = false;
  250. this.handleBeforeUnload = function() {
  251. qcodo.beforeUnloadFlag = true;
  252. };
  253. window.onbeforeunload= this.handleBeforeUnload;
  254. ////////////////////////////////////
  255. // Color Handling Functionality
  256. ////////////////////////////////////
  257. this.colorRgbValues = function(strColor) {
  258. strColor = strColor.replace("#", "");
  259. try {
  260. if (strColor.length == 3)
  261. return new Array(
  262. eval("0x" + strColor.substring(0, 1)),
  263. eval("0x" + strColor.substring(1, 2)),
  264. eval("0x" + strColor.substring(2, 3))
  265. );
  266. else if (strColor.length == 6)
  267. return new Array(
  268. eval("0x" + strColor.substring(0, 2)),
  269. eval("0x" + strColor.substring(2, 4)),
  270. eval("0x" + strColor.substring(4, 6))
  271. );
  272. } catch (Exception) {};
  273. return new Array(0, 0, 0);
  274. };
  275. this.hexFromInt = function(intNumber) {
  276. intNumber = (intNumber > 255) ? 255 : ((intNumber < 0) ? 0 : intNumber);
  277. intFirst = Math.floor(intNumber / 16);
  278. intSecond = intNumber % 16;
  279. return intFirst.toString(16) + intSecond.toString(16);
  280. };
  281. this.colorRgbString = function(intRgbArray) {
  282. return "#" + qcodo.hexFromInt(intRgbArray[0]) + qcodo.hexFromInt(intRgbArray[1]) + qcodo.hexFromInt(intRgbArray[2]);
  283. };
  284. }
  285. };
  286. ////////////////////////////////
  287. // Qcodo Shortcut and Initialize
  288. ////////////////////////////////
  289. var qc = qcodo;
  290. qc.initialize();