Difference between revisions of "MediaWiki:Common.js"

Jump to: navigation, search

Difference between revisions of "MediaWiki:Common.js"

 
(106 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
// Terms Modal
 
$(document).ready(function() {
 
$(document).ready(function() {
    mw.loader.load('ext.wikiEditor.toolbar');
 
  
    var customizeToolbar = function() {
+
  setTimeout(function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
+
    const termsModal = $('#termsModal');
            section: 'main',
+
 
            group: 'format',
+
    if (termsModal.length) {
            tools: {
+
      // Check if the "rpmTermsAgreement" cookie is present
                "strikethrough": {
+
      if (!document.cookie.includes('rpmTermsAgreement')) {
                    label: 'Strike',
+
        // Show the Bootstrap modal
                    type: 'button',
+
        termsModal.modal({
                    icon: '//upload.wikimedia.org/wikipedia/commons/3/30/Btn_toolbar_rayer.png',
+
          backdrop: "static"
                    action: {
 
                        type: 'encapsulate',
 
                        options: {
 
                            pre: "<s>",
 
                            post: "</s>"
 
                        }
 
                    }
 
                }
 
            }
 
 
         });
 
         });
    };
+
      }
  
    /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
+
      // Agree button click event to set the "rpm" cookie
    if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
+
      $('#agreeTermsButton').click(function() {
         mw.loader.using('user.options', function() {
+
         termsModal.modal('hide');
            // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
+
       
            if (mw.user.options.get('usebetatoolbar') == 1) {
+
        // Set the "rpmTermsAgreement" cookie with expiration date five years from now
                $.when(
+
        var expirationDate = new Date();
                    mw.loader.using('ext.wikiEditor.toolbar'), $.ready
+
        expirationDate.setFullYear(expirationDate.getFullYear() + 5);
                ).then(customizeToolbar);
+
        document.cookie = "rpmTermsAgreement=true; expires=" + expirationDate.toUTCString() + "; path=/";
            }
+
      });
        });
 
 
     }
 
     }
    // Add the customizations to LiquidThreads' edit toolbar, if available
+
  }, 200);
     mw.hook('ext.lqt.textareaCreated').add(customizeToolbar);
+
 
 +
  /* MailChimp Form */
 +
 
 +
  var mailchimpFormHTML =
 +
    '<div id="mc_embed_signup">' +
 +
     '    <form action="https://rcabc.us21.list-manage.com/subscribe/post?u=aa570610c198792349997a983&amp;id=91bc758592&amp;f_id=000857e1f0" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_self">' +
 +
    '        <div id="mc_embed_signup_scroll">' +
 +
    '            <div class="mc-field-group form-group">' +
 +
    '                <label for="mce-EMAIL">Email Address</label>' +
 +
    '                <input type="email" value="" name="EMAIL" class="required email form-control" id="mce-EMAIL" required>' +
 +
    '                <span id="mce-EMAIL-HELPERTEXT" class="helper_text"></span>' +
 +
    '            </div>' +
 +
    '            <div id="mce-responses" class="clear foot">' +
 +
    '                <div class="response" id="mce-error-response" style="display:none"></div>' +
 +
    '                <div class="response" id="mce-success-response" style="display:none"></div>' +
 +
    '            </div>' +
 +
    '            <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_aa570610c198792349997a983_91bc758592" tabindex="-1" value=""></div>' +
 +
    '            <input type="submit" value="Subscribe To RPM Updates" name="subscribe" id="mc-embedded-subscribe" class="btn btn-primary">' +
 +
    '        </div>' +
 +
    '    </form>' +
 +
    '</div>';
  
    var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+
  $('#mailchimpForm').html(mailchimpFormHTML);
    x = new Date;
 
    var y = ' || ' + x.getFullYear() + '-' + monthNames[(x.getMonth() + 3)] + '-' + x.getDate() + ' }}';
 
 
});
 
});

Latest revision as of 22:13, 19 June 2023

// Terms Modal
$(document).ready(function() {

  setTimeout(function() {
    const termsModal = $('#termsModal');

    if (termsModal.length) {
      // Check if the "rpmTermsAgreement" cookie is present
      if (!document.cookie.includes('rpmTermsAgreement')) {
        // Show the Bootstrap modal
        termsModal.modal({
          backdrop: "static"
        });
      }

      // Agree button click event to set the "rpm" cookie
      $('#agreeTermsButton').click(function() {
        termsModal.modal('hide');
        
        // Set the "rpmTermsAgreement" cookie with expiration date five years from now
        var expirationDate = new Date();
        expirationDate.setFullYear(expirationDate.getFullYear() + 5);
        document.cookie = "rpmTermsAgreement=true; expires=" + expirationDate.toUTCString() + "; path=/";
      });
    }
  }, 200);

  /* MailChimp Form */

  var mailchimpFormHTML =
    '<div id="mc_embed_signup">' +
    '    <form action="https://rcabc.us21.list-manage.com/subscribe/post?u=aa570610c198792349997a983&amp;id=91bc758592&amp;f_id=000857e1f0" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_self">' +
    '        <div id="mc_embed_signup_scroll">' +
    '            <div class="mc-field-group form-group">' +
    '                <label for="mce-EMAIL">Email Address</label>' +
    '                <input type="email" value="" name="EMAIL" class="required email form-control" id="mce-EMAIL" required>' +
    '                <span id="mce-EMAIL-HELPERTEXT" class="helper_text"></span>' +
    '            </div>' +
    '            <div id="mce-responses" class="clear foot">' +
    '                <div class="response" id="mce-error-response" style="display:none"></div>' +
    '                <div class="response" id="mce-success-response" style="display:none"></div>' +
    '            </div>' +
    '            <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_aa570610c198792349997a983_91bc758592" tabindex="-1" value=""></div>' +
    '            <input type="submit" value="Subscribe To RPM Updates" name="subscribe" id="mc-embedded-subscribe" class="btn btn-primary">' +
    '        </div>' +
    '    </form>' +
    '</div>';

  $('#mailchimpForm').html(mailchimpFormHTML);
});