Advertisement
verygoodplugins

Untitled

Nov 30th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkPasswordStrength( $pass1,
  2.                                 $pass2,
  3.                                 $strengthResult,
  4.                                 $submitButton,
  5.                                 blacklistArray ) {
  6.     var pass1 = $pass1.val();
  7.     var pass2 = $pass2.val();
  8.  
  9.     // Reset the form & meter
  10.     $submitButton.attr( 'disabled', 'disabled' );
  11.     $strengthResult.removeClass( 'short bad good strong' );
  12.  
  13.     // Extend our blacklist array with those from the inputs & site data
  14.     blacklistArray = blacklistArray.concat( wp.passwordStrength.userInputBlacklist() )
  15.  
  16.     // Get the password strength
  17.     var strength = wp.passwordStrength.meter( pass1, blacklistArray, pass2 );
  18.  
  19.     // Add the strength meter results
  20.     switch ( strength ) {
  21.  
  22.         case 2:
  23.             $strengthResult.addClass( 'bad' ).html( pwsL10n.bad );
  24.             break;
  25.  
  26.         case 3:
  27.             $strengthResult.addClass( 'good' ).html( pwsL10n.good );
  28.             break;
  29.  
  30.         case 4:
  31.             $strengthResult.addClass( 'strong' ).html( pwsL10n.strong );
  32.             break;
  33.  
  34.         case 5:
  35.             $strengthResult.addClass( 'short' ).html( pwsL10n.mismatch );
  36.             break;
  37.  
  38.         default:
  39.             $strengthResult.addClass( 'short' ).html( pwsL10n.short );
  40.  
  41.     }
  42.  
  43.     // The meter function returns a result even if pass2 is empty,
  44.     // enable only the submit button if the password is strong and
  45.     // both passwords are filled up
  46.     if ( 4 === strength && '' !== pass2.trim() ) {
  47.         $submitButton.removeAttr( 'disabled' );
  48.     }
  49.  
  50.     return strength;
  51. }
  52.  
  53. jQuery(document).ready(function($){
  54.  
  55.     /**
  56.      * Preserves user's currently selected tab after page reload
  57.      */
  58.    
  59.     var hash = window.location.hash;
  60.     hash && $('ul.nav a[href="' + hash + '"]').tab('show');
  61.  
  62.     $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  63.  
  64.         var scrollmem = $('body').scrollTop();
  65.         window.location.hash = e.target.hash;
  66.         $('html,body').scrollTop(scrollmem);
  67.  
  68.         $(".code_text").each(function(i) {
  69.             editor[i].refresh();
  70.         });
  71.  
  72.     });
  73.  
  74.     // Binding to trigger checkPasswordStrength
  75.     $( 'body' ).on( 'keyup', 'input[type=password]',
  76.         function( event ) {
  77.             checkPasswordStrength(
  78.                 $('input[type=password]'),         // First password field
  79.                 $('input[type=password].retyped'), // Second password field
  80.                 $('#password-strength'),           // Strength meter
  81.                 $('input[type=submit]'),           // Submit button
  82.                 ['password']        // Blacklisted words
  83.             );
  84.         }
  85.     );
  86.  
  87.  
  88.     // Select2 select fields
  89.  
  90.     if( $(".select2").length ) {
  91.  
  92.         $("select.select2").select2({
  93.             minimumResultsForSearch: -1,
  94.             allowClear: true,
  95.             placeholder: function(){
  96.                 $(this).data('placeholder');
  97.             }
  98.         });
  99.        
  100.     }
  101.  
  102.     /**
  103.      * Code Editor Field
  104.      * @since 2.0
  105.      */
  106.    
  107.     var editor = new Array();
  108.  
  109.     function codemirror_resize_fix() {
  110.         var evt = document.createEvent('UIEvents');
  111.         evt.initUIEvent('resize', true, false, window, 0);
  112.         window.dispatchEvent(evt);
  113.     }
  114.  
  115.     $(".code_text").each(function(i) {
  116.  
  117.         var lang = jQuery(this).attr("data-lang");
  118.         switch(lang) {
  119.             case 'php':
  120.                 lang = 'application/x-httpd-php';
  121.                 break;
  122.             case 'css':
  123.                 lang = 'text/css';
  124.                 break;
  125.             case 'html':
  126.                 lang = 'text/html';
  127.                 break;
  128.             case 'javascript':
  129.                 lang = 'text/javascript';
  130.                 break;
  131.             default:
  132.                 lang = 'application/x-httpd-php';
  133.         }
  134.  
  135.         var theme = $(this).attr("data-theme");
  136.  
  137.         switch(theme) {
  138.             case 'default':
  139.                 theme = 'default';
  140.                 break;
  141.             case 'dark':
  142.                 theme = 'twilight';
  143.                 break;
  144.             default:
  145.                 theme = 'default';
  146.         }
  147.  
  148.         editor[i] = CodeMirror.fromTextArea(this, {
  149.             lineNumbers:    true,
  150.             //matchBrackets:  true,
  151.             mode:           lang,
  152.             indentUnit:     4,
  153.             indentWithTabs: true
  154.             //enterMode:      "keep",
  155.             //tabMode:        "shift"
  156.         });
  157.  
  158.         editor[i].setOption("theme", theme);
  159.     });
  160.  
  161.     /**
  162.      * File upload button
  163.      * @since 2.0
  164.      */
  165.     $('.fileinput-field .btn-file').bind('click', function(e) {
  166.         tb_show('', 'media-upload.php?post_id=0&type=image&apc=apc&TB_iframe=true');
  167.         var filebutton = $(this);
  168.         //store old send to editor function
  169.         window.restore_send_to_editor = window.send_to_editor;
  170.  
  171.         //overwrite send to editor function
  172.         window.send_to_editor = function(html) {
  173.  
  174.             imgurl = $('img', html).attr('src');
  175.  
  176.             var index = imgurl.lastIndexOf("/") + 1;
  177.             var filename = imgurl.substr(index);
  178.  
  179.             filebutton.find('.fileinput-input').val(imgurl);
  180.             filebutton.prev().find('.fileinput-filename').text(filename);
  181.  
  182.             filebutton.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
  183.  
  184.             // Update image preview
  185.             filebutton.parent().parent().find('.fileinput-preview').html("<img src='" + imgurl + "'>");
  186.  
  187.             //load_images_muploader();
  188.             tb_remove();
  189.             //restore old send to editor function
  190.             window.send_to_editor = window.restore_send_to_editor;
  191.  
  192.         }
  193.  
  194.         return false;
  195.     });
  196.  
  197.     $('.fileinput-field .btn.fileinput-exists').bind('click', function(e) {
  198.  
  199.         $(this).parent().parent().removeClass('fileinput-exists').addClass('fileinput-new');
  200.         $(this).prev().find('.fileinput-input').val('');
  201.         $(this).prev().prev().find('.fileinput-filename').text('');
  202.  
  203.  
  204.     });
  205.  
  206. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement