Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
Wikipatents (talk | contribs) |
Wikipatents (talk | contribs) |
||
Line 1: | Line 1: | ||
− | mw.loader. | + | mw.loader.using(['mediawiki.util', 'oojs-ui-core', 'oojs-ui-windows'], function () { |
+ | $(function () { | ||
+ | // Check if the popup has been shown recently | ||
+ | var lastShown = localStorage.getItem('patentPopupLastShown'); | ||
+ | var now = new Date().getTime(); | ||
+ | if (lastShown && now - lastShown < 86400000) { // 24 hours in milliseconds | ||
+ | return; // Don't show the popup if it was shown in the last 24 hours | ||
+ | } | ||
+ | |||
+ | var $popupContent = $('<div>') | ||
+ | .append( | ||
+ | $('<h2>').text('Patent Application Monitoring'), | ||
+ | $('<p>').text('Want to monitor Patent Applications? Submit your custom request and get a free weekly report!'), | ||
+ | $('<div>').append( | ||
+ | new OO.ui.ButtonWidget({ | ||
+ | label: 'Get Alerts', | ||
+ | flags: ['progressive', 'primary'] | ||
+ | }).$element | ||
+ | ) | ||
+ | ); | ||
+ | |||
+ | var popup = new OO.ui.PopupWidget({ | ||
+ | $content: $popupContent, | ||
+ | padded: true, | ||
+ | width: 300, | ||
+ | height: 'auto', | ||
+ | head: true, | ||
+ | label: 'Patent Monitoring' | ||
+ | }); | ||
+ | |||
+ | $('body').append(popup.$element); | ||
+ | |||
+ | // Show popup after a short delay | ||
+ | setTimeout(function () { | ||
+ | popup.toggle(true); | ||
+ | }, 1000); | ||
+ | |||
+ | // Add click event to the CTA button | ||
+ | $popupContent.find('.oo-ui-buttonElement-button').on('click', function () { | ||
+ | window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank'); | ||
+ | popup.toggle(false); | ||
+ | // Remember that we've shown the popup | ||
+ | localStorage.setItem('patentPopupLastShown', new Date().getTime()); | ||
+ | }); | ||
+ | }); | ||
+ | }); |
Revision as of 17:02, 5 July 2024
mw.loader.using(['mediawiki.util', 'oojs-ui-core', 'oojs-ui-windows'], function () { $(function () { // Check if the popup has been shown recently var lastShown = localStorage.getItem('patentPopupLastShown'); var now = new Date().getTime(); if (lastShown && now - lastShown < 86400000) { // 24 hours in milliseconds return; // Don't show the popup if it was shown in the last 24 hours } var $popupContent = $('<div>') .append( $('<h2>').text('Patent Application Monitoring'), $('<p>').text('Want to monitor Patent Applications? Submit your custom request and get a free weekly report!'), $('<div>').append( new OO.ui.ButtonWidget({ label: 'Get Alerts', flags: ['progressive', 'primary'] }).$element ) ); var popup = new OO.ui.PopupWidget({ $content: $popupContent, padded: true, width: 300, height: 'auto', head: true, label: 'Patent Monitoring' }); $('body').append(popup.$element); // Show popup after a short delay setTimeout(function () { popup.toggle(true); }, 1000); // Add click event to the CTA button $popupContent.find('.oo-ui-buttonElement-button').on('click', function () { window.open('https://docs.google.com/forms/d/e/1FAIpQLSfvGeHyDW-ND9TqqVhbPOrYsKWsvUgFp9Rl-gfsyZCaLp7fXA/viewform?usp=sf_link', '_blank'); popup.toggle(false); // Remember that we've shown the popup localStorage.setItem('patentPopupLastShown', new Date().getTime()); }); }); });