/** * This function sets YDAjax to automagically handle a waiting message * * @param $html (Optional) Html to use in the message. * @param $options (Optional) Js options for the html object * @param $effectStart (Optional) YDAjaxEffect object on page load (by default a simple 'hide' will be used) * @param $effectShow (Optional) YDAjaxEffect object when submitting requests (by default a simple 'show' will be used) * @param $effectHide (Optional) YDAjaxEffect object on response (by default a simple 'hide' will be used) */ function useWaitingMessage($html = '<h3> Please wait ... <\\/h3>', $options = array(), $effectStart = null, $effectShow = null, $effectHide = null) { // if we already had invoke this method, then we don't need to add another js code for message creation if (isset($this->wtID)) { return; } // create js variable name for html message element $this->wtID = $this->prefix . "waitingmessage"; // check custom options if (!isset($options['style.backgroundColor'])) { $options['style.backgroundColor'] = '#cccccc'; } if (!isset($options['style.top'])) { $options['style.top'] = '40%'; } if (!isset($options['style.left'])) { $options['style.left'] = '44%'; } // static values $options['id'] = $this->wtID . "id"; $options['innerHTML'] = $html; $options['style.position'] = "absolute"; $options['style.position'] = "absolute"; $options['style.zindex'] = 9999; // create js for html element creation $this->waitingMessageCode = "\n\tvar " . $this->wtID . " = document.createElement('div');"; // add custom options foreach ($options as $name => $value) { $this->waitingMessageCode .= $this->wtID . "." . $name . " = '" . $value . "';"; } // append div box to document body $this->waitingMessageCode .= "document.body.appendChild(" . $this->wtID . ");"; // create start effect if (is_null($effectStart)) { $effectStart = new YDAjaxEffect('', 'hide', '', 0); } // append start code $this->waitingMessageCode .= $effectStart->getJSHead($this->wtID . "id") . $effectStart->getJSBody($this->wtID . "id"); // create function name to show div $this->wtFunction = $this->wtID . "show()"; // create show effect if (is_null($effectShow)) { $effectShow = new YDAjaxEffect('', 'show', '', 0); } // save hide effect to be used on response if (is_null($effectHide)) { $this->effectHide = new YDAjaxEffect('', 'hide', '', 0); } else { $this->effectHide = $effectHide; } // create js function to show div $this->waitingMessageCodeFunction = "\nfunction " . $this->wtFunction . "{" . $effectShow->getJSHead($this->wtID . "id") . $effectShow->getJSBody($this->wtID . "id") . "}"; }
/** * This function sets YDAjax to automagically handle a waiting message * * @param $html (Optional) Html to use in the message. * @param $options (Optional) Js options for the html object * @param $effectStart (Optional) YDAjaxEffect object on page load (by default a simple 'hide' will be used) * @param $effectShow (Optional) YDAjaxEffect object when submitting requests (by default a simple 'show' will be used) * @param $effectHide (Optional) YDAjaxEffect object on response (by default a simple 'hide' will be used) */ function useWaitingMessage($html = '<h3> Please wait ... <\\/h3>', $options = array(), $effectStart = null, $effectShow = null, $effectHide = null) { // if we already had invoke this method, then we don't need to add another js code for message creation if (isset($this->wtID)) { return; } // create js variable name for html message element $this->wtID = "waitingmessage"; // check custom options if (!isset($options['style.backgroundColor'])) { $options['style.backgroundColor'] = '#cccccc'; } if (!isset($options['style.border'])) { $options['style.border'] = '1px solid #110000'; } if (!isset($options['style.width'])) { $options['style.width'] = '200px'; } // static values $options['style.cursor'] = "default"; $options['style.position'] = "absolute"; $options['style.top'] = '40%'; $options['style.left'] = '50%'; $options['style.marginLeft'] = '-' . round(intval($options['style.width']) / 2) . 'px'; $options['style.zindex'] = 9999; $options['innerHTML'] = '<center>' . $html . '</center>'; // create js for html element creation $this->waitingMessageCode = "var " . $this->wtID . " = document.createElement('div');"; // append div box to document body $this->waitingMessageCode .= "document.body.appendChild(" . $this->wtID . ");"; // add id $this->waitingMessageCode .= $this->wtID . ".id = '" . $this->wtID . "id';"; // create start effect if (is_null($effectStart)) { $effectStart = new YDAjaxEffect('', 'hide', '', 0); } // append start code $this->waitingMessageCode .= $effectStart->getJSHead($this->wtID . "id") . $effectStart->getJSBody($this->wtID . "id"); // add custom options foreach ($options as $name => $value) { $this->waitingMessageCode .= $this->wtID . "." . $name . " = '" . $value . "';"; } // create show effect if (is_null($effectShow)) { $effectShow = new YDAjaxEffect('', 'show', '', 0); } // create hide effect if (is_null($effectHide)) { $effectHide = new YDAjaxEffect('', 'hide', '', 0); } // create js functions to show/hide div $this->waitingMessageCodeFunction = "xajax.loadingFunction = function(){" . $effectShow->getJSHead($this->wtID . "id") . $effectShow->getJSBody($this->wtID . "id") . "}\n"; $this->waitingMessageCodeFunction .= "xajax.doneLoadingFunction = function(){" . $effectHide->getJSHead($this->wtID . "id") . $effectHide->getJSBody($this->wtID . "id") . "}\n"; }