/media/system/js/core-uncompressed.js

https://bitbucket.org/kraymitchell/fcd · JavaScript · 550 lines · 315 code · 39 blank · 196 comment · 101 complexity · 97d77e9f522ff8418445b4cb82dd4940 MD5 · raw file

  1. /**
  2. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  3. * @license GNU General Public License version 2 or later; see LICENSE.txt
  4. */
  5. // Only define the Joomla namespace if not defined.
  6. if (typeof(Joomla) === 'undefined') {
  7. var Joomla = {};
  8. }
  9. Joomla.editors = {};
  10. // An object to hold each editor instance on page
  11. Joomla.editors.instances = {};
  12. /**
  13. * Generic submit form
  14. */
  15. Joomla.submitform = function(task, form) {
  16. if (typeof(form) === 'undefined') {
  17. form = document.getElementById('adminForm');
  18. /**
  19. * Added to ensure Joomla 1.5 compatibility
  20. */
  21. if(!form){
  22. form = document.adminForm;
  23. }
  24. }
  25. if (typeof(task) !== 'undefined' && '' !== task) {
  26. form.task.value = task;
  27. }
  28. // Submit the form.
  29. if (typeof form.onsubmit == 'function') {
  30. form.onsubmit();
  31. }
  32. if (typeof form.fireEvent == "function") {
  33. form.fireEvent('submit');
  34. }
  35. form.submit();
  36. };
  37. /**
  38. * Default function. Usually would be overriden by the component
  39. */
  40. Joomla.submitbutton = function(pressbutton) {
  41. Joomla.submitform(pressbutton);
  42. }
  43. /**
  44. * Custom behavior for JavaScript I18N in Joomla! 1.6
  45. *
  46. * Allows you to call Joomla.JText._() to get a translated JavaScript string pushed in with JText::script() in Joomla.
  47. */
  48. Joomla.JText = {
  49. strings: {},
  50. '_': function(key, def) {
  51. return typeof this.strings[key.toUpperCase()] !== 'undefined' ? this.strings[key.toUpperCase()] : def;
  52. },
  53. load: function(object) {
  54. for (var key in object) {
  55. this.strings[key.toUpperCase()] = object[key];
  56. }
  57. return this;
  58. }
  59. };
  60. /**
  61. * Method to replace all request tokens on the page with a new one.
  62. */
  63. Joomla.replaceTokens = function(n) {
  64. var els = document.getElementsByTagName('input');
  65. for (var i = 0; i < els.length; i++) {
  66. if ((els[i].type == 'hidden') && (els[i].name.length == 32) && els[i].value == '1') {
  67. els[i].name = n;
  68. }
  69. }
  70. };
  71. /**
  72. * USED IN: administrator/components/com_banners/views/client/tmpl/default.php
  73. *
  74. * Verifies if the string is in a valid email format
  75. *
  76. * @param string
  77. * @return boolean
  78. */
  79. Joomla.isEmail = function(text) {
  80. var regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
  81. return regex.test(text);
  82. };
  83. /**
  84. * USED IN: all list forms.
  85. *
  86. * Toggles the check state of a group of boxes
  87. *
  88. * Checkboxes must have an id attribute in the form cb0, cb1...
  89. *
  90. * @param mixed The number of box to 'check', for a checkbox element
  91. * @param string An alternative field name
  92. */
  93. Joomla.checkAll = function(checkbox, stub) {
  94. if (!stub) {
  95. stub = 'cb';
  96. }
  97. if (checkbox.form) {
  98. var c = 0;
  99. for (var i = 0, n = checkbox.form.elements.length; i < n; i++) {
  100. var e = checkbox.form.elements[i];
  101. if (e.type == checkbox.type) {
  102. if ((stub && e.id.indexOf(stub) == 0) || !stub) {
  103. e.checked = checkbox.checked;
  104. c += (e.checked == true ? 1 : 0);
  105. }
  106. }
  107. }
  108. if (checkbox.form.boxchecked) {
  109. checkbox.form.boxchecked.value = c;
  110. }
  111. return true;
  112. }
  113. return false;
  114. }
  115. /**
  116. * Render messages send via JSON
  117. *
  118. * @param object messages JavaScript object containing the messages to render
  119. * @return void
  120. */
  121. Joomla.renderMessages = function(messages) {
  122. Joomla.removeMessages();
  123. var container = document.id('system-message-container');
  124. var dl = new Element('dl', {
  125. id: 'system-message',
  126. role: 'alert'
  127. });
  128. Object.each(messages, function (item, type) {
  129. var dt = new Element('dt', {
  130. 'class': type,
  131. html: type
  132. });
  133. dt.inject(dl);
  134. var dd = new Element('dd', {
  135. 'class': type
  136. });
  137. dd.addClass('message');
  138. var list = new Element('ul');
  139. Array.each(item, function (item, index, object) {
  140. var li = new Element('li', {
  141. html: item
  142. });
  143. li.inject(list);
  144. }, this);
  145. list.inject(dd);
  146. dd.inject(dl);
  147. }, this);
  148. dl.inject(container);
  149. };
  150. /**
  151. * Remove messages
  152. *
  153. * @return void
  154. */
  155. Joomla.removeMessages = function() {
  156. var children = $$('#system-message-container > *');
  157. children.destroy();
  158. }
  159. /**
  160. * USED IN: administrator/components/com_cache/views/cache/tmpl/default.php
  161. * administrator/components/com_installer/views/discover/tmpl/default_item.php
  162. * administrator/components/com_installer/views/update/tmpl/default_item.php
  163. * administrator/components/com_languages/helpers/html/languages.php
  164. * libraries/joomla/html/html/grid.php
  165. *
  166. * @param isitchecked
  167. * @param form
  168. * @return
  169. */
  170. Joomla.isChecked = function(isitchecked, form) {
  171. if (typeof(form) === 'undefined') {
  172. form = document.getElementById('adminForm');
  173. /**
  174. * Added to ensure Joomla 1.5 compatibility
  175. */
  176. if(!form){
  177. form = document.adminForm;
  178. }
  179. }
  180. if (isitchecked == true) {
  181. form.boxchecked.value++;
  182. } else {
  183. form.boxchecked.value--;
  184. }
  185. }
  186. /**
  187. * USED IN: libraries/joomla/html/toolbar/button/help.php
  188. *
  189. * Pops up a new window in the middle of the screen
  190. */
  191. Joomla.popupWindow = function(mypage, myname, w, h, scroll) {
  192. var winl = (screen.width - w) / 2;
  193. var wint = (screen.height - h) / 2;
  194. var winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl
  195. + ',scrollbars=' + scroll + ',resizable'
  196. var win = window.open(mypage, myname, winprops)
  197. win.window.focus();
  198. }
  199. /**
  200. * USED IN: libraries/joomla/html/html/grid.php
  201. */
  202. Joomla.tableOrdering = function(order, dir, task, form) {
  203. if (typeof(form) === 'undefined') {
  204. form = document.getElementById('adminForm');
  205. /**
  206. * Added to ensure Joomla 1.5 compatibility
  207. */
  208. if(!form){
  209. form = document.adminForm;
  210. }
  211. }
  212. form.filter_order.value = order;
  213. form.filter_order_Dir.value = dir;
  214. Joomla.submitform(task, form);
  215. }
  216. /**
  217. * USED IN: administrator/components/com_modules/views/module/tmpl/default.php
  218. *
  219. * Writes a dynamically generated list
  220. *
  221. * @param string
  222. * The parameters to insert into the <select> tag
  223. * @param array
  224. * A javascript array of list options in the form [key,value,text]
  225. * @param string
  226. * The key to display for the initial state of the list
  227. * @param string
  228. * The original key that was selected
  229. * @param string
  230. * The original item value that was selected
  231. */
  232. function writeDynaList(selectParams, source, key, orig_key, orig_val) {
  233. var html = '\n <select ' + selectParams + '>';
  234. var i = 0;
  235. for (x in source) {
  236. if (source[x][0] == key) {
  237. var selected = '';
  238. if ((orig_key == key && orig_val == source[x][1])
  239. || (i == 0 && orig_key != key)) {
  240. selected = 'selected="selected"';
  241. }
  242. html += '\n <option value="' + source[x][1] + '" ' + selected
  243. + '>' + source[x][2] + '</option>';
  244. }
  245. i++;
  246. }
  247. html += '\n </select>';
  248. document.writeln(html);
  249. }
  250. /**
  251. * USED IN: administrator/components/com_content/views/article/view.html.php
  252. *
  253. * Changes a dynamically generated list
  254. *
  255. * @param string
  256. * The name of the list to change
  257. * @param array
  258. * A javascript array of list options in the form [key,value,text]
  259. * @param string
  260. * The key to display
  261. * @param string
  262. * The original key that was selected
  263. * @param string
  264. * The original item value that was selected
  265. */
  266. function changeDynaList(listname, source, key, orig_key, orig_val) {
  267. var list = document.adminForm[listname];
  268. // empty the list
  269. for (i in list.options.length) {
  270. list.options[i] = null;
  271. }
  272. i = 0;
  273. for (x in source) {
  274. if (source[x][0] == key) {
  275. opt = new Option();
  276. opt.value = source[x][1];
  277. opt.text = source[x][2];
  278. if ((orig_key == key && orig_val == opt.value) || i == 0) {
  279. opt.selected = true;
  280. }
  281. list.options[i++] = opt;
  282. }
  283. }
  284. list.length = i;
  285. }
  286. /**
  287. * USED IN: administrator/components/com_menus/views/menus/tmpl/default.php
  288. *
  289. * @param radioObj
  290. * @return
  291. */
  292. // return the value of the radio button that is checked
  293. // return an empty string if none are checked, or
  294. // there are no radio buttons
  295. function radioGetCheckedValue(radioObj) {
  296. if (!radioObj) {
  297. return '';
  298. }
  299. var n = radioObj.length;
  300. if (n == undefined) {
  301. if (radioObj.checked) {
  302. return radioObj.value;
  303. } else {
  304. return '';
  305. }
  306. }
  307. for ( var i = 0; i < n; i++) {
  308. if (radioObj[i].checked) {
  309. return radioObj[i].value;
  310. }
  311. }
  312. return '';
  313. }
  314. /**
  315. * USED IN: administrator/components/com_banners/views/banner/tmpl/default/php
  316. * administrator/components/com_categories/views/category/tmpl/default.php
  317. * administrator/components/com_categories/views/copyselect/tmpl/default.php
  318. * administrator/components/com_content/views/copyselect/tmpl/default.php
  319. * administrator/components/com_massmail/views/massmail/tmpl/default.php
  320. * administrator/components/com_menus/views/list/tmpl/copy.php
  321. * administrator/components/com_menus/views/list/tmpl/move.php
  322. * administrator/components/com_messages/views/message/tmpl/default_form.php
  323. * administrator/components/com_newsfeeds/views/newsfeed/tmpl/default.php
  324. * components/com_content/views/article/tmpl/form.php
  325. * templates/beez/html/com_content/article/form.php
  326. *
  327. * @param frmName
  328. * @param srcListName
  329. * @return
  330. */
  331. function getSelectedValue(frmName, srcListName) {
  332. var form = document[frmName];
  333. var srcList = form[srcListName];
  334. i = srcList.selectedIndex;
  335. if (i != null && i > -1) {
  336. return srcList.options[i].value;
  337. } else {
  338. return null;
  339. }
  340. }
  341. /**
  342. * USED IN: all list forms.
  343. *
  344. * Toggles the check state of a group of boxes
  345. *
  346. * Checkboxes must have an id attribute in the form cb0, cb1...
  347. *
  348. * @param mixed The number of box to 'check', for a checkbox element
  349. * @param string An alternative field name
  350. *
  351. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.checkAll() instead.
  352. */
  353. function checkAll(checkbox, stub) {
  354. if (!stub) {
  355. stub = 'cb';
  356. }
  357. if (checkbox.form) {
  358. var c = 0;
  359. for (var i = 0, n = checkbox.form.elements.length; i < n; i++) {
  360. var e = checkbox.form.elements[i];
  361. if (e.type == checkbox.type) {
  362. if ((stub && e.id.indexOf(stub) == 0) || !stub) {
  363. e.checked = checkbox.checked;
  364. c += (e.checked == true ? 1 : 0);
  365. }
  366. }
  367. }
  368. if (checkbox.form.boxchecked) {
  369. checkbox.form.boxchecked.value = c;
  370. }
  371. return true;
  372. } else {
  373. // The old way of doing it
  374. var f = document.adminForm;
  375. var c = f.toggle.checked;
  376. var n = checkbox;
  377. var n2 = 0;
  378. for (var i = 0; i < n; i++) {
  379. var cb = f[stub+''+i];
  380. if (cb) {
  381. cb.checked = c;
  382. n2++;
  383. }
  384. }
  385. if (c) {
  386. document.adminForm.boxchecked.value = n2;
  387. } else {
  388. document.adminForm.boxchecked.value = 0;
  389. }
  390. }
  391. }
  392. /**
  393. * USED IN: all over :)
  394. *
  395. * @param id
  396. * @param task
  397. * @return
  398. */
  399. function listItemTask(id, task) {
  400. var f = document.adminForm;
  401. var cb = f[id];
  402. if (cb) {
  403. for (var i = 0; true; i++) {
  404. var cbx = f['cb'+i];
  405. if (!cbx)
  406. break;
  407. cbx.checked = false;
  408. } // for
  409. cb.checked = true;
  410. f.boxchecked.value = 1;
  411. submitbutton(task);
  412. }
  413. return false;
  414. }
  415. /**
  416. * USED IN: administrator/components/com_cache/views/cache/tmpl/default.php
  417. * administrator/components/com_installer/views/discover/tmpl/default_item.php
  418. * administrator/components/com_installer/views/update/tmpl/default_item.php
  419. * administrator/components/com_languages/helpers/html/languages.php
  420. * libraries/joomla/html/html/grid.php
  421. *
  422. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.isChecked() instead.
  423. *
  424. * @param isitchecked
  425. * @return
  426. *
  427. */
  428. function isChecked(isitchecked) {
  429. if (isitchecked == true) {
  430. document.adminForm.boxchecked.value++;
  431. } else {
  432. document.adminForm.boxchecked.value--;
  433. }
  434. }
  435. /**
  436. * Default function. Usually would be overriden by the component
  437. *
  438. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.submitbutton() instead.
  439. */
  440. function submitbutton(pressbutton) {
  441. submitform(pressbutton);
  442. }
  443. /**
  444. * Submit the admin form
  445. *
  446. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.submitform() instead.
  447. */
  448. function submitform(pressbutton) {
  449. if (pressbutton) {
  450. document.adminForm.task.value = pressbutton;
  451. }
  452. if (typeof document.adminForm.onsubmit == "function") {
  453. document.adminForm.onsubmit();
  454. }
  455. if (typeof document.adminForm.fireEvent == "function") {
  456. document.adminForm.fireEvent('submit');
  457. }
  458. document.adminForm.submit();
  459. }
  460. /**
  461. * USED IN: libraries/joomla/html/toolbar/button/help.php
  462. *
  463. * Pops up a new window in the middle of the screen
  464. *
  465. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.popupWindow() instead.
  466. */
  467. function popupWindow(mypage, myname, w, h, scroll) {
  468. var winl = (screen.width - w) / 2;
  469. var wint = (screen.height - h) / 2;
  470. winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl
  471. + ',scrollbars=' + scroll + ',resizable'
  472. win = window.open(mypage, myname, winprops)
  473. if (parseInt(navigator.appVersion) >= 4) {
  474. win.window.focus();
  475. }
  476. }
  477. // needed for Table Column ordering
  478. /**
  479. * USED IN: libraries/joomla/html/html/grid.php
  480. *
  481. * @deprecated 12.1 This function will be removed in a future version. Use Joomla.tableOrdering() instead.
  482. */
  483. function tableOrdering(order, dir, task) {
  484. var form = document.adminForm;
  485. form.filter_order.value = order;
  486. form.filter_order_Dir.value = dir;
  487. submitform(task);
  488. }
  489. /**
  490. * USED IN: libraries/joomla/html/html/grid.php
  491. */
  492. function saveorder(n, task) {
  493. checkAll_button(n, task);
  494. }
  495. function checkAll_button(n, task) {
  496. if (!task) {
  497. task = 'saveorder';
  498. }
  499. for (var j = 0; j <= n; j++) {
  500. var box = document.adminForm['cb'+j];
  501. if (box) {
  502. if (box.checked == false) {
  503. box.checked = true;
  504. }
  505. } else {
  506. alert("You cannot change the order of items, as an item in the list is `Checked Out`");
  507. return;
  508. }
  509. }
  510. submitform(task);
  511. }