PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/app/soc/content/js/melange.dependency.js

https://code.google.com/
JavaScript | 494 lines | 379 code | 78 blank | 37 comment | 39 complexity | 0fc9b310f73970a69089a9cd923cfdaf MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, BSD-2-Clause, LGPL-2.1, GPL-2.0, MIT
  1. /* Copyright 2011 the Melange authors.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /**
  16. * @author <a href="mailto:fadinlight@gmail.com">Mario Ferraro</a>
  17. */
  18. (function () {
  19. /** @lends melange.dependency */
  20. if (window.melange === undefined) {
  21. throw new Error("Melange not loaded");
  22. }
  23. var melange = window.melange;
  24. /** Package that handles melange JS dependencies
  25. * Doesn't list jQuery, JSON, melange and melange.dependency
  26. * in any chain as they're dependencies of this own script,
  27. * and they will be then loaded anyway.
  28. * @name melange.dependency
  29. * @namespace melange.depencency
  30. * @borrows melange.logging.debugDecorator.log as log
  31. */
  32. melange.dependency = window.melange.dependency = function () {
  33. return new melange.dependency();
  34. };
  35. /** Shortcut to current package.
  36. * @private
  37. */
  38. var $m = melange.logging.debugDecorator(melange.dependency);
  39. melange.error.createErrors([
  40. ]);
  41. $m.templateWithContext = function (script_template, context) {
  42. this.script_template = script_template;
  43. this.context = context;
  44. };
  45. $m.cssFile = function (css) {
  46. this.css = css;
  47. };
  48. var script_dependencies_chains = {};
  49. var s = script_dependencies_chains;
  50. // Third party JS URL prefix
  51. var tpjs = "/js/" + melange.config.app_version + "/";
  52. // Melange packages URL prefix
  53. var mpjs = "/soc/content/" + melange.config.app_version + "/js/";
  54. // Melange CSS URL prefix
  55. var mcss = "/" + melange.config.css_path + "/";
  56. if (melange.config.google_api_key !== undefined) {
  57. s.google = [
  58. "https://www.google.com/jsapi?key=" + melange.config.google_api_key
  59. ];
  60. }
  61. else {
  62. s.google = [
  63. "https://www.google.com/jsapi"
  64. ];
  65. }
  66. if (melange.config.is_local !== undefined && melange.config.is_local === true) {
  67. s.jquery = [
  68. tpjs + "jquery/jquery-1.6.4.js"
  69. ];
  70. }
  71. else {
  72. s.jquery = [
  73. "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
  74. ];
  75. }
  76. s.json = [
  77. tpjs + "json/json2.js"
  78. ];
  79. s.tinymce = [
  80. "/tiny_mce/tiny_mce.js"
  81. ];
  82. s.purr = [
  83. tpjs + "jquery/jquery-purr.js"
  84. ];
  85. s.counter = [
  86. tpjs + "jquery/jquery-counter.js"
  87. ];
  88. s.spin = [
  89. tpjs + "jquery/jquery-spin-1.1.1.js"
  90. ];
  91. s.bgiframe = [
  92. tpjs + "jquery/jquery-bgiframe.js"
  93. ];
  94. s.ajaxQueue = [
  95. tpjs + "jquery/jquery-ajaxQueue.js"
  96. ];
  97. s.progressbar = [
  98. tpjs + "jquery/jquery-progressbar.js"
  99. ];
  100. s.uniform = [
  101. tpjs + "jquery/jquery-uniform.js"
  102. ];
  103. s.raty = [
  104. tpjs + "jquery/jquery.raty.js"
  105. ];
  106. s.cluetip = [
  107. tpjs + "jquery/jquery.cluetip.js"
  108. ];
  109. s.dimensions = [
  110. tpjs + "jquery/jquery.dimensions.js"
  111. ];
  112. s.scrollTo = [
  113. tpjs + "jquery/jquery.scrollTo.js"
  114. ];
  115. s.formbuilder = [
  116. s.scrollTo,
  117. null,
  118. tpjs + "jquery/jquery.formbuilder.js"
  119. ];
  120. s.colorbox = [
  121. tpjs + "jquery/jquery.colorbox.js"
  122. ];
  123. s.hashchange = [
  124. tpjs + "jquery/jquery.ba-hashchange.js"
  125. ];
  126. s.dd = [
  127. tpjs + "jquery/jquery.dd.js"
  128. ];
  129. s.modernizr = [
  130. tpjs + "modernizr/modernizr-svg.js"
  131. ];
  132. s.jqueryui = {}
  133. if (melange.config.is_local !== undefined && melange.config.is_local === true) {
  134. s.jqueryui.core = [
  135. new $m.cssFile(mcss + "jquery-ui/jquery.ui.all.css"),
  136. tpjs + "jquery/jquery-ui.core.js"
  137. ];
  138. }
  139. else {
  140. s.jqueryui.core = [
  141. new $m.cssFile(mcss + "jquery-ui/jquery.ui.merged.css"),
  142. tpjs + "jquery/jquery-ui.core.js"
  143. ];
  144. }
  145. s.jqueryui.datepicker = [
  146. s.jqueryui.core,
  147. null,
  148. tpjs + "jquery/jquery-ui.datepicker.js"
  149. ];
  150. s.jqueryui.position = [
  151. s.jqueryui.core,
  152. null,
  153. tpjs + "jquery/jquery-ui.position.js"
  154. ];
  155. s.jqueryui.widget = [
  156. s.jqueryui.core,
  157. null,
  158. tpjs + "jquery/jquery-ui.widget.js"
  159. ];
  160. s.jqueryui.mouse = [
  161. s.jqueryui.core,
  162. null,
  163. tpjs + "jquery/jquery-ui.mouse.js"
  164. ];
  165. s.jqueryui.button = [
  166. s.jqueryui.widget,
  167. null,
  168. tpjs + "jquery/jquery-ui.button.js"
  169. ];
  170. s.jqueryui.autocomplete = [
  171. s.jqueryui.position,
  172. s.jqueryui.widget,
  173. null,
  174. new $m.cssFile(mcss + "jquery-ui/jquery.ui.autocomplete.css"),
  175. tpjs + "jquery/jquery-ui.autocomplete.js"
  176. ];
  177. s.jqueryui.dialog = [
  178. s.jqueryui.position,
  179. s.jqueryui.widget,
  180. null,
  181. tpjs + "jquery/jquery-ui.dialog.js"
  182. ];
  183. s.jqueryui.checkboxes = [
  184. s.jqueryui.core,
  185. tpjs + "jquery/jquery.ui-checkboxes.js"
  186. ];
  187. s.jqueryui.draggable = [
  188. s.jqueryui.widget,
  189. s.jqueryui.mouse,
  190. null,
  191. tpjs + "jquery/jquery-ui.draggable.js"
  192. ];
  193. s.jqueryui.sortable = [
  194. s.jqueryui.widget,
  195. s.jqueryui.mouse,
  196. null,
  197. tpjs + "jquery/jquery-ui.sortable.js"
  198. ];
  199. s.jqueryui.effects = [
  200. tpjs + "jquery/jquery-ui.effects.core.js"
  201. ];
  202. s.jqueryui.effects.blind = [
  203. s.jqueryui.effects,
  204. null,
  205. tpjs + "jquery/jquery-ui.effects.blind.js"
  206. ];
  207. s.jqgrid = [
  208. s.jqueryui.core,
  209. s.jqueryui.dialog,
  210. s.jqueryui.draggable,
  211. s.jqueryui.sortable,
  212. null,
  213. new $m.cssFile(mcss + "ui.multiselect.css"),
  214. tpjs + "jquery/jquery-jqgrid.ui.multiselect.js",
  215. null,
  216. new $m.cssFile(mcss + "ui.jqgrid.css"),
  217. tpjs + "jquery/jquery-jqgrid.locale-en.js",
  218. null,
  219. tpjs + "jquery/jquery-jqgrid.base.js",
  220. null,
  221. tpjs + "jquery/jquery-jqgrid.custom.js",
  222. tpjs + "jquery/jquery-jqgrid.filter.js",
  223. tpjs + "jquery/jquery-jqgrid.jqueryui.js"
  224. ];
  225. s.jqgridediting = [
  226. s.jqgrid,
  227. null,
  228. tpjs + "jquery/jquery-jqgrid.common.js",
  229. tpjs + "jquery/jquery-jqgrid.fmatter.js",
  230. tpjs + "jquery/jquery-jqgrid.formedit.js",
  231. null,
  232. tpjs + "jquery/jquery-jqgrid.searchFilter.js",
  233. tpjs + "jquery/jquery-jqgrid.inlinedit.js",
  234. null,
  235. tpjs + "jquery/jquery-jqgrid.jqDnR.js",
  236. null,
  237. tpjs + "jquery/jquery-jqgrid.jqModal.js"
  238. ];
  239. s.cookie = [
  240. tpjs + "jquery/jquery-cookie.js"
  241. ];
  242. s.jquery.svg = [
  243. tpjs + "jquery/jquery.svg.pack.js"
  244. ];
  245. s.jlinq = [
  246. tpjs + "jlinq/jLinq-2.2.1.js"
  247. ];
  248. s.fileupload = [
  249. s.jqueryui.widget,
  250. tpjs + "jquery/jquery.fileupload.js"
  251. ];
  252. /** Melange packages **/
  253. s.melange = {};
  254. s.melange.main = [
  255. s.google,
  256. s.cookie,
  257. null,
  258. mpjs + "melange.js"
  259. ];
  260. s.melange.gdata = {};
  261. s.melange.gdata.core = [
  262. mpjs + "melange.gdata.core.js"
  263. ];
  264. s.melange.datetimepicker = [
  265. s.jqueryui.datepicker,
  266. null,
  267. mpjs + "melange.datetimepicker.js"
  268. ];
  269. s.melange.duplicates = [
  270. s.progressbar,
  271. null,
  272. mpjs + "duplicate-slots.js"
  273. ];
  274. s.melange.form = [
  275. ];
  276. s.melange.list = [
  277. s.jqgrid,
  278. s.jlinq,
  279. new $m.cssFile(mcss + "others.css"),
  280. null,
  281. s.jqueryui.dialog,
  282. s.jqueryui.button,
  283. s.jqgridediting,
  284. null,
  285. mpjs + "melange.list.js",
  286. null,
  287. mpjs + "melange.list.cookie_service.js",
  288. mpjs + "melange.list.process_data.js",
  289. null,
  290. function () {
  291. if (window.melange_list_queue !== undefined && window.melange_list_queue instanceof Array) {
  292. jQuery.each(window.melange_list_queue, function (index, function_to_call) {
  293. function_to_call();
  294. });
  295. }
  296. }
  297. ];
  298. s.melange.tooltip = [
  299. s.purr,
  300. null
  301. ];
  302. s.melange.autocomplete = [
  303. s.jqueryui.autocomplete,
  304. null,
  305. mpjs + "melange.autocomplete.js"
  306. ];
  307. s.melange.graph = [
  308. s.google,
  309. null,
  310. mpjs + "melange.graph.js"
  311. ];
  312. s.melange.uploadform = [
  313. s.fileupload,
  314. null,
  315. mpjs + "upload-form.js"
  316. ];
  317. s.melange.blog = [
  318. s.google,
  319. null,
  320. mpjs + "melange.blog.js"
  321. ];
  322. s.melange.action = [
  323. s.dimensions,
  324. s.cluetip,
  325. s.jqueryui.checkboxes,
  326. null,
  327. mpjs + "melange.action.js"
  328. ];
  329. s.melange.map = [
  330. mpjs + "melange.map.js"
  331. ];
  332. s.melange.program_select = [
  333. mpjs + "melange.program_select.js"
  334. ];
  335. s.melange.dynamicoptions = [
  336. s.json,
  337. null,
  338. mpjs + "melange.dynamicoptions.js"
  339. ];
  340. s.melange.clock = [
  341. s.modernizr,
  342. s.jquery.svg,
  343. null,
  344. mpjs + "melange.clock.js"
  345. ];
  346. $m.s = s;
  347. var unpack = function (orig_array) {
  348. var array_to_return = [];
  349. for (var i = 0, len = orig_array.length; i < len; i++) {
  350. var current_element = orig_array[i];
  351. if (typeof current_element === 'object' && current_element instanceof
  352. Array) {
  353. var unpacks = unpack(current_element);
  354. array_to_return = array_to_return.concat(unpacks);
  355. }
  356. else {
  357. array_to_return.push(current_element);
  358. }
  359. }
  360. return array_to_return;
  361. };
  362. $m.loadScripts = function(requested_packages) {
  363. var _tempqueue = unpack(requested_packages);
  364. /* Remove duplicates from the queue, as allowDuplicates with LAB
  365. * fails randomly at least in Safari and Chrome
  366. */
  367. var _queue = [];
  368. // Temporary queue with CSS paths strings.
  369. var _cssqueue = [];
  370. for (var i = 0, len = _tempqueue.length; i < len; i++) {
  371. var temp_val = _tempqueue[i];
  372. if (typeof temp_val == "string") {
  373. if (jQuery.inArray(temp_val, _queue) === -1) {
  374. _queue.push(temp_val);
  375. }
  376. }
  377. else if (temp_val instanceof $m.cssFile) {
  378. if (jQuery.inArray(temp_val.css, _cssqueue) === -1) {
  379. _queue.push(temp_val);
  380. _cssqueue.push(temp_val.css);
  381. }
  382. }
  383. else {
  384. _queue.push(temp_val);
  385. }
  386. }
  387. for (var i=0, len=_queue.length; i<len; i++) {
  388. if (typeof _queue[i] == "string") { // script string source found
  389. $LAB = $LAB.script(_queue[i]);
  390. }
  391. else if (!_queue[i]) { // null/false found
  392. $LAB = $LAB.wait();
  393. }
  394. else if (typeof _queue[i] == "object" && _queue[i] instanceof $m.templateWithContext) {
  395. $LAB = $LAB.wait(
  396. function (context_to_send) {
  397. return function () {
  398. melange.templates.setContextToLast(context_to_send);
  399. }
  400. }(_queue[i].context)
  401. ).script(_queue[i].script_template).wait();
  402. }
  403. else if (typeof _queue[i] == "object" && _queue[i] instanceof $m.cssFile) {
  404. jQuery("<link>", {
  405. href: _queue[i].css,
  406. media: "screen",
  407. rel: "stylesheet",
  408. type: "text/css"
  409. }).appendTo("head");
  410. }
  411. else if (typeof _queue[i] == "function") { // inline function found
  412. $LAB = $LAB.wait(_queue[i]);
  413. }
  414. }
  415. };
  416. }());