Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript][HTML][PHP] Jak zrobić opóźnienie funkcji wyskakującego PopUp-a
Forum PHP.pl > Forum > Przedszkole
danieele
Jak zrobić opóźnienie funkcji wyskakującego PopUp-a.
Teraz okno wyskakuje automatycznie po załadowaniu strony, a ja chciałbym aby pojawiało się po 15 sekundach
Może ktoś podpowie?

  1. <?php
  2. /**
  3.  * @Package Plugin System Modal Popups Content - BECóV
  4.  * @Version 1.2
  5.  * @Author ROALCANA
  6.  * @AuthorUrl www.roalcana.com
  7.  * @copyright (C) 2011 ROALCANA. All rights reserved.
  8.  * @license GNU/GPL <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">http://www.gnu.org/copyleft/gpl.html</a>
  9.  * Plugin System Modal Popups Content is Free Software
  10.  */
  11.  
  12. // Check to ensure this file is included in Joomla!
  13. defined( '_JEXEC' ) or die( 'Restricted access' );
  14.  
  15. jimport( 'joomla.plugin.plugin' );
  16.  
  17. class plgSystemMpcontent extends JPlugin
  18.  
  19.  
  20.  
  21. {
  22.  
  23. /**
  24.   * plgSystemMPContent::plgSystemMPContent()
  25.   *
  26.   * @param mixed $subject
  27.   * @return
  28.   */
  29. function plgSystemMpcontent( &$subject, $config )
  30. {
  31. parent::__construct($subject, $config);
  32. }
  33.  
  34. /**
  35.   * plgSystemMPContent::onAfterInitialise()
  36.   *
  37.   * @return
  38.   */
  39. function onAfterRoute()
  40. {
  41. # Disable the popup if not corresponding Itemid (menu item)
  42. $filter = $this->params->get( 'mpc_filter', '0' );
  43. $menuop = $this->params->get( 'mpc_when', '' );
  44.  
  45. if ( $filter && $menuop != '' && $menuop != JRequest::getInt( 'Itemid' , 0 ) ) {
  46. return;
  47. }
  48.  
  49. # Disable the popup if there is nothing to display
  50. $id = $this->params->get( 'mpc_content', null );
  51. if ( !$id ) {
  52. return;
  53. }
  54.  
  55. # Disable the popup for non-HTML interface (like RSS)
  56. $document = &JFactory::getDocument();
  57. $doctype = $document->getType();
  58. if ( $doctype !== 'html' ) {
  59. return;
  60. }
  61.  
  62. # Get the required path info
  63. $uri = &JURI::getInstance();
  64. $base = str_replace( '/administrator', '', JURI::Base(true) );
  65.  
  66. # Determine if we're in the backend
  67. if ( JPATH_BASE != JPATH_ADMINISTRATOR ) {
  68. $isadmin = false;
  69. } else {
  70. $isadmin = true;
  71. }
  72.  
  73. # Disable the popup on joomla_root/index2.php calls
  74. if ( JRequest::getVar('tmpl') == 'component' ) {
  75. return;
  76. }
  77.  
  78. # Get where the popup will be shown
  79. $mpc_where = $this->params->get( 'mpc_where', 0 );
  80.  
  81. # If we're in the backend and the plugin is configured to display only in frontend
  82. # then disable the popup
  83. if ( $isadmin && $mpc_where == 0 ) {
  84. return;
  85. }
  86.  
  87. # If we're in the frontend and the plugin is configured to display only in backend
  88. # then disable the popup
  89. if ( !$isadmin && $mpc_where == 1 ) {
  90. return;
  91. }
  92.  
  93. # Get how often the popup will be shown
  94. $mpc_freq = $this->params->get( 'mpc_freq', 1 );
  95.  
  96. # Determine if it's time for the popup to be displayed
  97. if ( $mpc_freq > 0 ) {
  98. $mpc_next = JRequest::getVar( 'mpc_next_' . $id, null, 'cookie', 'int' );
  99. if ( $mpc_next > time() ) {
  100. return;
  101. }
  102. }
  103.  
  104. # Get the popup's remaining parameters
  105. $mpc_width = $this->params->get( 'mpc_width', 500 );
  106. $mpc_height = $this->params->get( 'mpc_height', 500 );
  107. if ( $mpc_width == 0 )
  108. $mpc_width = 500;
  109. if ( $mpc_height == 0 )
  110. $mpc_height = 500;
  111.  
  112. # Display the popup
  113. $content = "
  114.  
  115. function init() {
  116. SqueezeBox.fromElement(
  117. '" . $base . "/index.php?option=com_content&view=article&id={$id}&tmpl=component',
  118. {handler: 'iframe', size: {x: $mpc_width, y: $mpc_height}}
  119. )
  120. };
  121.  
  122. if (document.addEventListener) {
  123. document.addEventListener(\"DOMContentLoaded\", init, false);
  124. } else {
  125. window.onload = init;
  126. }";
  127.  
  128. JHTML::_( 'behavior.modal' );
  129. $document->addScriptDeclaration( $content, 'text/javascript' );
  130.  
  131. #Set coockie as required
  132. $period = 60 * 60 * 24 * 365;
  133. switch ( $mpc_freq ) {
  134. case 1:
  135. setcookie( 'mpc_next_' . $id, '', time() - $period, '/' );
  136. setcookie( 'mpc_next_' . $id, time() + $period, 0, '/' );
  137. break;
  138. case 2:
  139. setcookie( 'mpc_next_' . $id, '', time() - $period, '/' );
  140. setcookie( 'mpc_next_' . $id, time() + $period, time() + $period, '/' );
  141. break;
  142. case 3:
  143. setcookie( 'mpc_next_' . $id, '', time() - $period, '/' );
  144. $period = $this->params->get( 'mpc_period', 600 );
  145. setcookie( 'mpc_next_' . $id, time() + $period, time() + (60 * 60 * 24 * 365), '/' );
  146. break;
  147. default:
  148. break;
  149. }
  150. #End of plugin
  151. return;
  152. }
  153. }

Fifi209
Javascript setTimeout
kpt_lucek
[JAVASCRIPT] pobierz, plaintext
  1. var funkcja = function() {
  2. //zawartość funkcji
  3. setTimeout( "funkcja()", 1000 );// 1000(ms) = 1s -> analogicznie 1min = 1000 * 60 etc
  4.  
  5. }
  6. $(document).ready(function() {
  7. funkcja();
  8. });
[JAVASCRIPT] pobierz, plaintext
danieele
Może dokładniej wytłumaczę. Na mojej stronie opartej na Joomli zainstalowałem plugin z popup. Adres strony http://www.healthscreeningsolutions.co.uk/ popup wyskakuje jest ok ale chciałbym aby pojawiał się po 10 sekundach. Plugin ten składa się z pliku .php, którego kod wstawiłem w pierwszym poście oraz z pliku modal.js
Gdzie i jaki mam wstawić kod aby otrzymać to opóżnienie
Pomóżcie proszę

kod pliku modal.js

  1. * SqueezeBox - Expandable Lightbox
  2. *
  3. * Allows to open various content as modal,
  4. * centered and animated box.
  5. *
  6. * Inspired by
  7. * ... Lokesh Dhakar - The original Lightbox v2
  8. * ... Cody Lindley - ThickBox
  9. *
  10. * @version 1.0rc1
  11. *
  12. * @license MIT-style license
  13. * @author Harald Kirschner <mail [at] digitarald.de>
  14. * @copyright Author
  15. */
  16. var SqueezeBox = {
  17.  
  18. presets: {
  19. size: {x: 600, y: 450},
  20. sizeLoading: {x: 200, y: 150},
  21. marginInner: {x: 20, y: 20},
  22. marginImage: {x: 150, y: 200},
  23. handler: false,
  24. adopt: null,
  25. closeWithOverlay: true,
  26. zIndex: 65555,
  27. overlayOpacity: 0.7,
  28. classWindow: '',
  29. classOverlay: '',
  30. disableFx: false,
  31. onOpen: Class.empty,
  32. onClose: Class.empty,
  33. onUpdate: Class.empty,
  34. onResize: Class.empty,
  35. onMove: Class.empty,
  36. onShow: Class.empty,
  37. onHide: Class.empty,
  38. fxOverlayDuration: 250,
  39. fxResizeDuration: 750,
  40. fxContentDuration: 250,
  41. ajaxOptions: {}
  42. },
  43.  
  44. initialize: function(options) {
  45. if (this.options) return this;
  46. this.presets = $merge(this.presets, options)
  47. this.setOptions(this.presets);
  48. this.build();
  49. this.listeners = {
  50. window: this.reposition.bind(this, [null]),
  51. close: this.close.bind(this),
  52. key: this.onkeypress.bind(this)};
  53. this.isOpen = this.isLoading = false;
  54. this.window.close = this.listeners.close;
  55. return this;
  56. },
  57.  
  58. build: function() {
  59. this.overlay = new Element('div', {
  60. id: 'sbox-overlay',
  61. styles: {
  62. display: 'none',
  63. zIndex: this.options.zIndex
  64. }
  65. });
  66. this.content = new Element('div', {
  67. id: 'sbox-content'
  68. });
  69. this.btnClose = new Element('a', {
  70. id: 'sbox-btn-close',
  71. href: '#'
  72. });
  73. this.window = new Element('div', {
  74. id: 'sbox-window',
  75. styles: {
  76. display: 'none',
  77. zIndex: this.options.zIndex + 2
  78. }
  79. }).adopt(this.btnClose, this.content);
  80.  
  81. if (!window.ie6) {
  82. this.overlay.setStyles({
  83. position: 'fixed',
  84. top: 0,
  85. left: 0
  86. });
  87. this.window.setStyles({
  88. position: 'fixed',
  89. top: '50%',
  90. left: '50%'
  91. });
  92. } else {
  93. this.overlay.style.setExpression('marginTop', 'document.documentElement.scrollTop + "px"');
  94. this.window.style.setExpression('marginTop', '0 - parseInt(this.offsetHeight / 2) + document.documentElement.scrollTop + "px"');
  95.  
  96. this.overlay.setStyles({
  97. position: 'absolute',
  98. top: '0%',
  99. left: '0%'
  100. //,marginTop: "expression(document.documentElement.scrollTop + 'px')"
  101. });
  102.  
  103. this.window.setStyles({
  104. position: 'absolute',
  105. top: '0%',
  106. left: '0%'
  107. //,marginTop: "(expression(0 - parseInt(this.offsetHeight / 2) + document.documentElement.scrollTop + 'px')"
  108. });
  109. }
  110.  
  111. $(document.body).adopt(this.overlay, this.window);
  112.  
  113. this.fx = {
  114. overlay: this.overlay.effect('opacity', {
  115. duration: this.options.fxOverlayDuration,
  116. wait: false}).set(0),
  117. window: this.window.effects({
  118. duration: this.options.fxResizeDuration,
  119. wait: false}),
  120. content: this.content.effect('opacity', {
  121. duration: this.options.fxContentDuration,
  122. wait: false}).set(0)
  123. };
  124. },
  125.  
  126. addClick: function(el) {
  127. return el.addEvent('click', function() {
  128. if (this.fromElement(el)) return false;
  129. }.bind(this));
  130. },
  131.  
  132. fromElement: function(el, options) {
  133. this.initialize();
  134. this.element = $(el);
  135. if (this.element && this.element.rel) options = $merge(options || {}, Json.evaluate(this.element.rel));
  136. this.setOptions(this.presets, options);
  137. this.assignOptions();
  138. this.url = (this.element ? (this.options.url || this.element.href) : el) || '';
  139.  
  140. if (this.options.handler) {
  141. var handler = this.options.handler;
  142. return this.setContent(handler, this.parsers[handler].call(this, true));
  143. }
  144. var res = false;
  145. for (var key in this.parsers) {
  146. if ((res = this.parsers[key].call(this))) return this.setContent(key, res);
  147. }
  148. return this;
  149. },
  150.  
  151. assignOptions: function() {
  152. this.overlay.setProperty('class', this.options.classOverlay);
  153. this.window.setProperty('class', this.options.classWindow);
  154. },
  155.  
  156. close: function(e) {
  157. if (e) new Event(e).stop();
  158. if (!this.isOpen) return this;
  159. this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));
  160. this.window.setStyle('display', 'none');
  161. this.trashImage();
  162. this.toggleListeners();
  163. this.isOpen = null;
  164. this.fireEvent('onClose', [this.content]).removeEvents();
  165. this.options = {};
  166. this.setOptions(this.presets).callChain();
  167. return this;
  168. },
  169.  
  170. onError: function() {
  171. if (this.image) this.trashImage();
  172. this.setContent('Error during loading');
  173. },
  174.  
  175. trashImage: function() {
  176. if (this.image) this.image = this.image.onload = this.image.onerror = this.image.onabort = null;
  177. },
  178.  
  179. setContent: function(handler, content) {
  180. this.content.setProperty('class', 'sbox-content-' + handler);
  181. this.applyTimer = this.applyContent.delay(this.fx.overlay.options.duration, this, [this.handlers[handler].call(this, content)]);
  182. if (this.overlay.opacity) return this;
  183. this.toggleOverlay(true);
  184. this.fx.overlay.start(this.options.overlayOpacity);
  185. this.reposition();
  186. return this;
  187.  


  1. },
  2.  
  3. applyContent: function(content, size) {
  4. this.applyTimer = $clear(this.applyTimer);
  5. this.hideContent();
  6. if (!content) this.toggleLoading(true);
  7. else {
  8. if (this.isLoading) this.toggleLoading(false);
  9. this.fireEvent('onUpdate', [this.content], 20);
  10. }
  11. this.content.empty()[['string', 'array', false].contains($type(content)) ? 'setHTML' : 'adopt'](content || '');
  12. this.callChain();
  13. if (!this.isOpen) {
  14. this.toggleListeners(true);
  15. this.resize(size, true);
  16. this.isOpen = true;
  17. this.fireEvent('onOpen', [this.content]);
  18. } else this.resize(size);
  19. },
  20.  
  21. resize: function(size, instantly) {
  22. var sizes = window.getSize();
  23. this.size = $merge(this.isLoading ? this.options.sizeLoading : this.options.size, size);
  24. var to = {
  25. width: this.size.x,
  26. height: this.size.y,
  27. marginLeft: - this.size.x / 2,
  28. marginTop: - this.size.y / 2
  29. //left: (sizes.scroll.x + (sizes.size.x - this.size.x - this.options.marginInner.x) / 2).toInt(),
  30. //top: (sizes.scroll.y + (sizes.size.y - this.size.y - this.options.marginInner.y) / 2).toInt()
  31. };
  32. $clear(this.showTimer || null);
  33. this.hideContent();
  34. if (!instantly) this.fx.window.start(to).chain(this.showContent.bind(this));
  35. else {
  36. this.window.setStyles(to).setStyle('display', '');
  37. this.showTimer = this.showContent.delay(50, this);
  38. }
  39. this.reposition(sizes);
  40. },
  41.  
  42. toggleListeners: function(state) {
  43. var task = state ? 'addEvent' : 'removeEvent';
  44. this.btnClose[task]('click', this.listeners.close);
  45. if (this.options.closeWithOverlay) this.overlay[task]('click', this.listeners.close);
  46. document[task]('keydown', this.listeners.key);
  47. window[task]('resize', this.listeners.window);
  48. window[task]('scroll', this.listeners.window);
  49. },
  50.  
  51. toggleLoading: function(state) {
  52. this.isLoading = state;
  53. this.window[state ? 'addClass' : 'removeClass']('sbox-loading');
  54. if (state) this.fireEvent('onLoading', [this.window]);
  55. },
  56.  
  57. toggleOverlay: function(state) {
  58. this.overlay.setStyle('display', state ? '' : 'none');
  59. $(document.body)[state ? 'addClass' : 'removeClass']('body-overlayed');
  60. },
  61.  
  62. showContent: function() {
  63. if (this.content.opacity) this.fireEvent('onShow', [this.window]);
  64. this.fx.content.start(1);
  65. },
  66.  
  67. hideContent: function() {
  68. if (!this.content.opacity) this.fireEvent('onHide', [this.window]);
  69. this.fx.content.stop().set(0);
  70. },
  71.  
  72. onkeypress: function(e) {
  73. switch (e.key) {
  74. case 'esc':
  75. case 'x':
  76. this.close();
  77. break;
  78. }
  79. },
  80.  
  81. reposition: function(sizes) {
  82. sizes = sizes || window.getSize();
  83. this.overlay.setStyles({
  84. //'left': sizes.scroll.x, 'top': sizes.scroll.y,
  85. width: sizes.size.x,
  86. height: sizes.size.y
  87. });
  88. /*
  89. this.window.setStyles({
  90. left: (sizes.scroll.x + (sizes.size.x - this.window.offsetWidth) / 2).toInt(),
  91. top: (sizes.scroll.y + (sizes.size.y - this.window.offsetHeight) / 2).toInt()
  92. });
  93. */
  94. this.fireEvent('onMove', [this.overlay, this.window, sizes]);
  95. },
  96.  
  97. removeEvents: function(type){
  98. if (!this.$events) return this;
  99. if (!type) this.$events = null;
  100. else if (this.$events[type]) this.$events[type] = null;
  101. return this;
  102. },
  103.  
  104. parsers: {
  105. 'image': function(preset) {
  106. return (preset || this.url.test(/\.(jpg|jpeg|png|gif|bmp)$/i)) ? this.url : false;
  107. },
  108. 'adopt': function(preset) {
  109. if ($(this.options.adopt)) return $(this.options.adopt);
  110. if (preset || ($(this.element) && !this.element.parentNode)) return $(this.element);
  111. var bits = this.url.match(/#([\w-]+)$/);
  112. return bits ? $(bits[1]) : false;
  113. },
  114. 'url': function(preset) {
  115. return (preset || (this.url && !this.url.test(/^java script:/i))) ? this.url: false;
  116. },
  117. 'iframe': function(preset) {
  118. return (preset || this.url) ? this.url: false;
  119. },
  120. 'string': function(preset) {
  121. return true;
  122. }
  123. },
  124.  
  125. handlers: {
  126. 'image': function(url) {
  127. this.image = new Image();
  128. var events = {
  129. loaded: function() {
  130. var win = {x: window.getWidth() - this.options.marginImage.x, y: window.getHeight() - this.options.marginImage.y};
  131. var size = {x: this.image.width, y: this.image.height};
  132. for (var i = 0; i < 2; i++)
  133. if (size.x > win.x) {
  134. size.y *= win.x / size.x;
  135. size.x = win.x;
  136. } else if (size.y > win.y) {
  137. size.x *= win.y / size.y;
  138. size.y = win.y;
  139. }
  140. size = {x: parseInt(size.x), y: parseInt(size.y)};
  141. if (window.webkit419) this.image = new Element('img', {'src': this.image.src});
  142. else $(this.image);
  143. this.image.setProperties({
  144. 'width': size.x,
  145. 'height': size.y});
  146. this.applyContent(this.image, size);
  147. }.bind(this),
  148. failed: this.onError.bind(this)
  149. };
  150. (function() {
  151. this.src = url;
  152. }).delay(10, this.image);
  153. this.image.onload = events.loaded;
  154. this.image.onerror = this.image.onabort = events.failed;
  155. },
  156. 'adopt': function(el) {
  157. return el.clone();
  158. },
  159. 'url': function(url) {
  160. this.ajax = new Ajax(url, this.options.ajaxOptions);
  161. this.ajax.addEvent('onSuccess', function(resp) {
  162. this.applyContent(resp);
  163. this.ajax = null;
  164. }.bind(this));
  165. this.ajax.addEvent('onFailure', this.onError.bind(this));
  166. this.ajax.request.delay(10, this.ajax);
  167. },
  168. 'iframe': function(url) {
  169. return new Element('iframe', {
  170. 'src': url,
  171. 'frameBorder': 0,
  172. 'width': this.options.size.x,
  173. 'height': this.options.size.y
  174. });
  175. },
  176. 'string': function(str) {
  177. return str;
  178. }
  179. },
  180.  
  181. extend: $extend
  182. };
  183.  
  184. SqueezeBox.extend(SqueezeBox, Events.prototype);
  185. SqueezeBox.extend(SqueezeBox, Options.prototype);
  186. SqueezeBox.extend(SqueezeBox, Chain.prototype);
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.