AjaxContent.php 895 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class UI_AjaxContent implements UITagInterface {
  3. /**
  4. * @param string $tagName = 'p5:AjaxContent'
  5. * @param array $props
  6. * @param array $childrens
  7. *
  8. * @return string html code
  9. */
  10. static function h($tagName, $props = [], $childrens = []) {
  11. // if (empty($props['url'])) throw new Exception("Missing url!");
  12. // if (empty($props['url'])) throw new Exception("Missing url!");
  13. $idHtmlNode = self::generateUniqueID();
  14. $loading = V::get('loading', "Wczytywanie danych ...", $props);
  15. return UI::h(null, [], [
  16. UI::h('div', [ 'id' => $idHtmlNode ], $loading),
  17. UI::hScript($jsFile = __FILE__ . '.script.js', $jsonVars = [
  18. 'ID_HTML_NODE' => $idHtmlNode,
  19. 'URL_FETCH_CONTENT' => $props['url'],
  20. 'LOADING' => $loading,
  21. ]),
  22. ]);
  23. }
  24. static function generateUniqueID() {
  25. static $_counter = 0;
  26. $_counter += 1;
  27. return "p5_ajax_content_{$_counter}";
  28. }
  29. }