/source/libraries/projectfork/html/script.php

https://github.com/projectfork/Projectfork · PHP · 634 lines · 320 code · 119 blank · 195 comment · 80 complexity · b4c79a10c2589dfdcd204646f8376bdc MD5 · raw file

  1. <?php
  2. /**
  3. * @package pkg_projectfork
  4. * @subpackage lib_projectfork
  5. *
  6. * @author Tobias Kuhn (eaxs)
  7. * @copyright Copyright (C) 2006-2013 Tobias Kuhn. All rights reserved.
  8. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
  9. **/
  10. defined('_JEXEC') or die();
  11. jimport('joomla.application.component.helper');
  12. /**
  13. * Utility class for Projectfork javascript behaviors
  14. *
  15. */
  16. abstract class PFhtmlScript
  17. {
  18. /**
  19. * Array containing information for loaded files
  20. *
  21. * @var array $loaded
  22. */
  23. protected static $loaded = array();
  24. /**
  25. * Method to load jQuery JS
  26. *
  27. * @return void
  28. */
  29. public static function jQuery()
  30. {
  31. // Only load once
  32. if (!empty(self::$loaded[__METHOD__])) {
  33. return;
  34. }
  35. $params = JComponentHelper::getParams('com_projectfork');
  36. if (JFactory::getApplication()->isSite()) {
  37. $load = $params->get('jquery_site');
  38. }
  39. else {
  40. $load = $params->get('jquery_admin');
  41. }
  42. // Load only of doc type is HTML
  43. if (JFactory::getDocument()->getType() == 'html' && $load != '0') {
  44. $dispatcher = JDispatcher::getInstance();
  45. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptjQuery');
  46. }
  47. self::$loaded[__METHOD__] = true;
  48. }
  49. /**
  50. * Method to load jQuery UI JS
  51. *
  52. * @return void
  53. */
  54. public static function jQueryUI()
  55. {
  56. // Only load once
  57. if (!empty(self::$loaded[__METHOD__])) {
  58. return;
  59. }
  60. // Load dependencies
  61. if (empty(self::$loaded['jQuery'])) {
  62. self::jQuery();
  63. }
  64. // Load only of doc type is HTML
  65. if (JFactory::getDocument()->getType() == 'html') {
  66. $dispatcher = JDispatcher::getInstance();
  67. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptjQueryUI');
  68. }
  69. self::$loaded[__METHOD__] = true;
  70. }
  71. /**
  72. * Method to load jQuery Sortable JS
  73. *
  74. * @return void
  75. */
  76. public static function jQuerySortable()
  77. {
  78. // Only load once
  79. if (!empty(self::$loaded[__METHOD__])) {
  80. return;
  81. }
  82. // Load dependencies
  83. if (empty(self::$loaded['jQueryUI'])) {
  84. self::jQueryUI();
  85. }
  86. // Load only of doc type is HTML
  87. if (JFactory::getDocument()->getType() == 'html') {
  88. $dispatcher = JDispatcher::getInstance();
  89. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptjQuerySortable');
  90. }
  91. self::$loaded[__METHOD__] = true;
  92. }
  93. /**
  94. * Method to load jQuery Chosen JS
  95. *
  96. * @return void
  97. */
  98. public static function jQueryChosen()
  99. {
  100. // Only load once
  101. if (!empty(self::$loaded[__METHOD__])) {
  102. return;
  103. }
  104. // Load dependencies
  105. if (empty(self::$loaded['jQuery'])) {
  106. self::jQuery();
  107. }
  108. // Load only of doc type is HTML
  109. if (JFactory::getDocument()->getType() == 'html') {
  110. $dispatcher = JDispatcher::getInstance();
  111. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptjQueryChosen');
  112. }
  113. self::$loaded[__METHOD__] = true;
  114. }
  115. /**
  116. * Method to load jQuery Select2 JS
  117. *
  118. * @return void
  119. */
  120. public static function jQuerySelect2()
  121. {
  122. // Only load once
  123. if (!empty(self::$loaded[__METHOD__])) {
  124. return;
  125. }
  126. // Load dependencies
  127. if (empty(self::$loaded['jQuery'])) {
  128. self::jQuery();
  129. }
  130. // Load only of doc type is HTML
  131. if (JFactory::getDocument()->getType() == 'html') {
  132. $dispatcher = JDispatcher::getInstance();
  133. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptjQuerySelect2');
  134. }
  135. self::$loaded[__METHOD__] = true;
  136. }
  137. /**
  138. * Method to load bootstrap JS
  139. *
  140. * @return void
  141. */
  142. public static function bootstrap()
  143. {
  144. // Only load once
  145. if (!empty(self::$loaded[__METHOD__])) {
  146. return;
  147. }
  148. // Load dependencies
  149. if (empty(self::$loaded['jQuery'])) {
  150. self::jQuery();
  151. }
  152. $params = JComponentHelper::getParams('com_projectfork');
  153. // Load only of doc type is HTML
  154. if (JFactory::getDocument()->getType() == 'html' && $params->get('bootstrap_js') != '0') {
  155. $dispatcher = JDispatcher::getInstance();
  156. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptBootstrap');
  157. }
  158. self::$loaded[__METHOD__] = true;
  159. }
  160. /**
  161. * Method to load jQuery flot JS
  162. *
  163. * @return void
  164. */
  165. public static function flot()
  166. {
  167. // Only load once
  168. if (!empty(self::$loaded[__METHOD__])) {
  169. return;
  170. }
  171. // Load dependencies
  172. if (empty(self::$loaded['jQuery'])) {
  173. self::jQuery();
  174. }
  175. // Load only of doc type is HTML
  176. if (JFactory::getDocument()->getType() == 'html') {
  177. $dispatcher = JDispatcher::getInstance();
  178. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptFlot');
  179. }
  180. self::$loaded[__METHOD__] = true;
  181. }
  182. /**
  183. * Method to load Projectfork comments JS
  184. *
  185. * @return void
  186. */
  187. public static function comments()
  188. {
  189. // Only load once
  190. if (!empty(self::$loaded[__METHOD__])) {
  191. return;
  192. }
  193. // Load dependencies
  194. if (empty(self::$loaded['jQuery'])) {
  195. self::jQuery();
  196. }
  197. if (empty(self::$loaded['projectfork'])) {
  198. self::projectfork();
  199. }
  200. // Load only of doc type is HTML
  201. if (JFactory::getDocument()->getType() == 'html') {
  202. $dispatcher = JDispatcher::getInstance();
  203. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptComments');
  204. }
  205. self::$loaded[__METHOD__] = true;
  206. }
  207. /**
  208. * Method to load Projectfork form JS
  209. *
  210. * @return void
  211. */
  212. public static function form()
  213. {
  214. // Only load once
  215. if (!empty(self::$loaded[__METHOD__])) {
  216. return;
  217. }
  218. // Load dependencies
  219. if (empty(self::$loaded['jQuery'])) {
  220. self::jQuery();
  221. }
  222. if (empty(self::$loaded['projectfork'])) {
  223. self::projectfork();
  224. }
  225. // Load only of doc type is HTML
  226. if (JFactory::getDocument()->getType() == 'html') {
  227. $dispatcher = JDispatcher::getInstance();
  228. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptForm');
  229. }
  230. self::$loaded[__METHOD__] = true;
  231. }
  232. /**
  233. * Method to load Projectfork list form JS
  234. *
  235. * @return void
  236. */
  237. public static function listForm()
  238. {
  239. // Only load once
  240. if (!empty(self::$loaded[__METHOD__])) {
  241. return;
  242. }
  243. // Load dependencies
  244. if (empty(self::$loaded['jQuery'])) {
  245. self::jQuery();
  246. }
  247. if (empty(self::$loaded['projectfork'])) {
  248. self::projectfork();
  249. }
  250. // Load only of doc type is HTML
  251. if (JFactory::getDocument()->getType() == 'html') {
  252. $dispatcher = JDispatcher::getInstance();
  253. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptListForm');
  254. }
  255. self::$loaded[__METHOD__] = true;
  256. }
  257. /**
  258. * Method to load Projectfork task JS
  259. *
  260. * @return void
  261. */
  262. public static function task()
  263. {
  264. // Only load once
  265. if (!empty(self::$loaded[__METHOD__])) {
  266. return;
  267. }
  268. // Load dependencies
  269. if (empty(self::$loaded['jQuery'])) {
  270. self::jQuery();
  271. }
  272. if (empty(self::$loaded['projectfork'])) {
  273. self::projectfork();
  274. }
  275. // Load only of doc type is HTML
  276. if (JFactory::getDocument()->getType() == 'html') {
  277. $dispatcher = JDispatcher::getInstance();
  278. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptTask');
  279. }
  280. self::$loaded[__METHOD__] = true;
  281. }
  282. /**
  283. * Method to load Projectfork time recording JS
  284. *
  285. * @return void
  286. */
  287. public static function timerec()
  288. {
  289. // Only load once
  290. if (!empty(self::$loaded[__METHOD__])) {
  291. return;
  292. }
  293. // Load dependencies
  294. if (empty(self::$loaded['jQuery'])) {
  295. self::jQuery();
  296. }
  297. if (empty(self::$loaded['projectfork'])) {
  298. self::projectfork();
  299. }
  300. // Load only of doc type is HTML
  301. if (JFactory::getDocument()->getType() == 'html') {
  302. $dispatcher = JDispatcher::getInstance();
  303. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptTimerec');
  304. }
  305. self::$loaded[__METHOD__] = true;
  306. }
  307. /**
  308. * Method to load upload JS
  309. *
  310. * @return void
  311. */
  312. public static function upload()
  313. {
  314. // Only load once
  315. if (!empty(self::$loaded[__METHOD__])) {
  316. return;
  317. }
  318. // Load only of doc type is HTML
  319. if (JFactory::getDocument()->getType() == 'html') {
  320. $dispatcher = JDispatcher::getInstance();
  321. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptUpload');
  322. }
  323. self::$loaded[__METHOD__] = true;
  324. }
  325. /**
  326. * Method to load Projectfork base JS
  327. *
  328. * @return void
  329. */
  330. public static function projectfork()
  331. {
  332. // Only load once
  333. if (!empty(self::$loaded[__METHOD__])) {
  334. return;
  335. }
  336. // Load only of doc type is HTML
  337. if (JFactory::getDocument()->getType() == 'html') {
  338. $dispatcher = JDispatcher::getInstance();
  339. $dispatcher->register('onBeforeCompileHead', 'triggerProjectforkScriptCore');
  340. }
  341. self::$loaded[__METHOD__] = true;
  342. }
  343. }
  344. /**
  345. * Stupid but necessary way of adding jQuery to the document head.
  346. * This function is called by the "onCompileHead" system event and makes sure that jQuery is not already loaded
  347. *
  348. */
  349. function triggerProjectforkScriptjQuery()
  350. {
  351. $params = JComponentHelper::getParams('com_projectfork');
  352. if (JFactory::getApplication()->isSite()) {
  353. $load = $params->get('jquery_site');
  354. }
  355. else {
  356. $load = $params->get('jquery_admin');
  357. }
  358. // Auto-load
  359. if ($load == '') {
  360. $scripts = (array) array_keys(JFactory::getDocument()->_scripts);
  361. $string = implode('', $scripts);
  362. if (stripos($string, 'jquery') === false) {
  363. JHtml::_('script', 'com_projectfork/jquery/jquery.min.js', false, true, false, false, false);
  364. JHtml::_('script', 'com_projectfork/jquery/jquery.noconflict.js', false, true, false, false, false);
  365. }
  366. }
  367. // Force load
  368. if ($load == '1') {
  369. JHtml::_('script', 'com_projectfork/jquery/jquery.min.js', false, true, false, false, false);
  370. JHtml::_('script', 'com_projectfork/jquery/jquery.noconflict.js', false, true, false, false, false);
  371. }
  372. }
  373. /**
  374. * Stupid but necessary way of adding jQuery UI to the document head.
  375. * This function is called by the "onCompileHead" system event and makes sure that flot is loaded after jQuery
  376. *
  377. */
  378. function triggerProjectforkScriptjQueryUI()
  379. {
  380. $scripts = (array) array_keys(JFactory::getDocument()->_scripts);
  381. $string = implode('', $scripts);
  382. if (stripos($string, 'jquery.ui') === false) {
  383. JHtml::_('script', 'com_projectfork/jquery/jquery.ui.core.min.js', false, true, false, false, false);
  384. }
  385. }
  386. /**
  387. * Stupid but necessary way of adding jQuery Chosen to the document head.
  388. * This function is called by the "onCompileHead" system event and makes sure that the script is loaded after jQuery
  389. *
  390. */
  391. function triggerProjectforkScriptjQueryChosen()
  392. {
  393. if (version_compare(JVERSION, '3', 'ge')) {
  394. JHtml::_('script', 'jui/chosen.jquery.min.js', false, true, false, false, false);
  395. JHtml::_('stylesheet', 'jui/chosen.css', false, true);
  396. }
  397. else {
  398. JHtml::_('script', 'com_projectfork/chosen/chosen.jquery.min.js', false, true, false, false, false);
  399. JHtml::_('stylesheet', 'com_projectfork/chosen/chosen.css', false, true);
  400. }
  401. }
  402. /**
  403. * Stupid but necessary way of adding jQuery Select2 to the document head.
  404. * This function is called by the "onCompileHead" system event and makes sure that the script is loaded after jQuery
  405. *
  406. */
  407. function triggerProjectforkScriptjQuerySelect2()
  408. {
  409. JHtml::_('script', 'com_projectfork/select2/select2.min.js', false, true, false, false, false);
  410. JHtml::_('stylesheet', 'com_projectfork/select2/select2.css', false, true);
  411. }
  412. /**
  413. * Stupid but necessary way of adding jQuery Sortable to the document head.
  414. * This function is called by the "onCompileHead" system event and makes sure that flot is loaded after jQuery
  415. *
  416. */
  417. function triggerProjectforkScriptjQuerySortable()
  418. {
  419. $scripts = (array) array_keys(JFactory::getDocument()->_scripts);
  420. $string = implode('', $scripts);
  421. if (stripos($string, 'jquery.ui.sortable') === false) {
  422. JHtml::_('script', 'com_projectfork/jquery/jquery.ui.sortable.min.js', false, true, false, false, false);
  423. }
  424. }
  425. /**
  426. * Stupid but necessary way of adding Bootstrap JS to the document head.
  427. * This function is called by the "onCompileHead" system event and makes sure that Bootstrap JS is not already loaded
  428. *
  429. */
  430. function triggerProjectforkScriptBootstrap()
  431. {
  432. $params = JComponentHelper::getParams('com_projectfork');
  433. $load = $params->get('bootstrap_js');
  434. // Auto-load
  435. if ($load == '') {
  436. $scripts = (array) array_keys(JFactory::getDocument()->_scripts);
  437. $string = implode('', $scripts);
  438. if (stripos($string, 'bootstrap') === false) {
  439. JHtml::_('script', 'com_projectfork/bootstrap/bootstrap.min.js', false, true, false, false, false);
  440. }
  441. }
  442. // Force load
  443. if ($load == '1') {
  444. JHtml::_('script', 'com_projectfork/bootstrap/bootstrap.min.js', false, true, false, false, false);
  445. }
  446. }
  447. /**
  448. * Stupid but necessary way of adding jQuery Flot to the document head.
  449. * This function is called by the "onCompileHead" system event and makes sure that flot is loaded after jQuery
  450. *
  451. */
  452. function triggerProjectforkScriptFlot()
  453. {
  454. JHtml::_('script', 'com_projectfork/flot/jquery.flot.min.js', false, true, false, false, false);
  455. JHtml::_('script', 'com_projectfork/flot/jquery.flot.pie.min.js', false, true, false, false, false);
  456. JHtml::_('script', 'com_projectfork/flot/jquery.flot.resize.min.js', false, true, false, false, false);
  457. }
  458. /**
  459. * Stupid but necessary way of adding PF comments JS to the document head.
  460. * This function is called by the "onCompileHead" system event and makes sure that the comments JS is loaded after jQuery
  461. *
  462. */
  463. function triggerProjectforkScriptComments()
  464. {
  465. JHtml::_('script', 'com_projectfork/projectfork/comments.js', false, true, false, false, false);
  466. }
  467. /**
  468. * Stupid but necessary way of adding PF form JS to the document head.
  469. * This function is called by the "onCompileHead" system event and makes sure that the form JS is loaded after jQuery
  470. *
  471. */
  472. function triggerProjectforkScriptForm()
  473. {
  474. JHtml::_('script', 'com_projectfork/projectfork/form.js', false, true, false, false, false);
  475. }
  476. /**
  477. * Stupid but necessary way of adding PF list form JS to the document head.
  478. * This function is called by the "onCompileHead" system event and makes sure that the list form JS is loaded after jQuery
  479. *
  480. */
  481. function triggerProjectforkScriptListForm()
  482. {
  483. JHtml::_('script', 'com_projectfork/projectfork/list.js', false, true, false, false, false);
  484. }
  485. /**
  486. * Stupid but necessary way of adding PF tasks JS to the document head.
  487. * This function is called by the "onCompileHead" system event and makes sure that the tasks JS is loaded after jQuery
  488. *
  489. */
  490. function triggerProjectforkScriptTask()
  491. {
  492. JHtml::_('script', 'com_projectfork/projectfork/task.js', false, true, false, false, false);
  493. }
  494. /**
  495. * Stupid but necessary way of adding PF time rec JS to the document head.
  496. * This function is called by the "onCompileHead" system event and makes sure that the tasks JS is loaded after jQuery
  497. *
  498. */
  499. function triggerProjectforkScriptTimerec()
  500. {
  501. JHtml::_('script', 'com_projectfork/projectfork/recorder.js', false, true, false, false, false);
  502. }
  503. function triggerProjectforkScriptUpload()
  504. {
  505. JHtml::_('script', 'com_projectfork/projectfork/upload.js', false, true, false, false, false);
  506. }
  507. /**
  508. * Stupid but necessary way of adding PF core JS to the document head.
  509. * This function is called by the "onCompileHead" system event and makes sure that the core JS is loaded after jQuery
  510. *
  511. */
  512. function triggerProjectforkScriptCore()
  513. {
  514. JHtml::_('script', 'com_projectfork/projectfork/projectfork.js', false, true, false, false, false);
  515. }