#StackBounty: #javascript #jquery #stackexchange #userscript Tampermonkey script to beautify related tags in Stack Exchange

Bounty: 50

I’ve got the following code which is ran inside tampermonkey (It’s a userscript), but there is a variable that is being declared, used, then overwritten by the next line. I’m looking for a way to shorten this code, or possibly remove the line if I can get the same results another way.

$(function() {
        /***** RELATED TAGS *****/
        var oldtags = main_content.find('div#related-tags, .module.js-gps-related-tags');
        var vctags = genSBWidget('Related Tags', '<svg aria-hidden="true" class="svg-icon" width="18" height="18" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"></path></svg>', 'relatedtags');

        oldtags.before(vctags).children('h4, a').remove().parent();

        vctags = main_content.find('div#visualcrumbs-relatedtags'); //THIS LINE

        vctags.prepend(oldtags.children()).children().wrapAll('
').each(function() { $(this).toggleClass('dno js-hidden js-tag grid--cell').children().slice(1).remove(); }); });

genSBWidget simply generates some HTML, not sure if this is really relevant but I’ll post the function anyways:

function genSBWidget(title, icon, innerid) {
        var widget = '
        
'+ icon +' ' + title + '
</div> '; return widget; }

Side not: This script just takes “Related tags” in the right sidebar of stackoverflow and puts it into one of the new style boxes in the sidebar, and gives it the same styling as Watched Tags.

My actual userscript works on more than just related tags, it converts everything in the sidebar into this new style box, what I’m hoping to do from this question is learn some new methods of doing what I’m trying to do with related tags, so I can expand this accross my entire script.

Here is a minimal example of the script:

// ==UserScript==
// @name         Related Tags Beautifier
// @namespace    https://github.com/GrumpyCrouton/Userscripts
// @version      1.0
// @description  Customizes StackExchange to your liking.
// @author       GrumpyCrouton
// @match          *://*.stackoverflow.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var $ = window.jQuery;

    /***** GLOBAL SITE CHANGES *****/
    var main_content = $('body div.container').find('div#content');

    $(function() {
        /***** RELATED TAGS *****/
        var oldtags = main_content.find('div#related-tags, .module.js-gps-related-tags');
        var vctags = genSBWidget('Related Tags', '<svg aria-hidden="true" class="svg-icon" width="18" height="18" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"></path></svg>', 'relatedtags');

        oldtags.before(vctags).children('h4, a').remove().parent();
        vctags = main_content.find('div#visualcrumbs-relatedtags');
        vctags.prepend(oldtags.children()).children().wrapAll('
').each(function() { $(this).toggleClass('dno js-hidden js-tag grid--cell').children().slice(1).remove(); }); }); function genSBWidget(title, icon, innerid) { var widget = '
'+ icon +' ' + title + '
</div> '; return widget; } })();


Get this bounty!!!

#StackBounty: #2013 #javascript #jquery #list-view #css Responsive content to list view width in SharePoint 2013

Bounty: 50

When I change the width of a SharePoint list to a certain amount of Pixels, I have the problem that some content of the list gets cut off on the right side – see the following Screenshot:

enter image description here

Is there any trick, that SharePoint automatically wraps text or adjusts the width of pictures (in other words: adjusts the content) to the chosen list width – so that content won’t get cut off?

I unfortunately do not have permissions to use SharePoint-Designer. I am working with SharePoint 2013 On-Premise.


Get this bounty!!!

#StackBounty: #javascript #jquery #reactjs Modify React Component's State using jQuery/Plain Javascript from Chrome Extension

Bounty: 50

I am building a tiny Chrome Extension for my own personal use.

In Facebook’s ads manager(Uses React) i want to change a textarea field’s value to a value generated by my chrome extension.

i tried it doing the old fashion way like this

document.querySelector('textarea').value = myValue;

this changes the value on screen but in chrome’s inspect element the value doesn’t change and when i focus on the input element value resets.

Here is the picture of how react component looks like:

1]

Here is the picture of this react components props & states:

2]

In above component i want to change the state.displayValue to my value.

how it can be done?


Get this bounty!!!

#StackBounty: #php #customization #jquery Removing jQuery migrate and working with dependencies

Bounty: 50

I have jQuery setup in my enqueue scripts section as a dependency, such as:

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts.min.js', array( 'jquery' ) );

Now, I want to remove jquery-migrate, but keep jQuery itself obviously, so I found this answer stating to do it like this:

add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );

function remove_jquery_migrate( &$scripts){
    if(!is_admin()){
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.2.1' );
    }
}

Firstly, I thought we had removed jQuery migrate here, so not sure what the need of adding the latest version of it is with the comment:

1.2.1 = latest version of jquery-migrate

Secondly, with the way I set my enqueue scripts up, how does that affect the dependencies since I have now removed jQuery and added jquery-core?

Is there a better way to handle this?


Get this bounty!!!

#StackBounty: #jquery #animation #fadein #fadeout #cross-fade jQuery: eliminate white screen "pause" between animations

Bounty: 50

I have just discovered Barba.js and find it very useful. It provides smooth transitions between URLs of the same website.

I have put together a Plunker consisting of two pages (index.html and about.html) that are loaded smoothly, with the help of jQuery’s fadeIn() and fadeOut() methods.

$(document).ready(function() {
  var transEffect = Barba.BaseTransition.extend({
    start: function() {
      this.newContainerLoading.then(val => this.fadeInNewcontent($(this.newContainer)));
    },
    fadeInNewcontent: function(nc) {
      nc.hide();
      var _this = this;
      $(this.oldContainer).fadeOut(1000).promise().done(() => {
        nc.css('visibility', 'visible');
        nc.fadeIn(1000, function() {
          _this.done();
        });
        $('html, body').animate({
          scrollTop: 300
        },1000);
      });
    }
  });
  Barba.Pjax.getTransition = function() {
    return transEffect;
  }
  Barba.Pjax.start();
});

The problem with this animations is that there is a white screen interval between them.

How could I eliminate this interval, to make the transition smoother? By “smoother” I mean similar to this one (click “view case”).


Get this bounty!!!

#StackBounty: #magento2 #checkout #javascript #jquery jQuery not working for custom checkbox on checkout page

Bounty: 50

I am looking to create a custom checkbox field on the checkout process that a customer can click to define if they are a business customer or a consumer.

To do so I made a module with the file SomeProcessor.php:

    <?php
namespace BusinessCheckoutCustomCheckoutBlockCheckout;

class SomeProcessor
{
    /**
     * @param MagentoCheckoutBlockCheckoutLayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        array  $jsLayout
    ) {

        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['custom_checkbox'] = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => '.custom_checkbox',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/checkbox',
                'options' => [],
                'id' => 'custom-field'
            ],
            'dataScope' => '.custom_checkbox',
            'label' => 'Is this a business order? Business T&C's apply.',
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' => [],
            'sortOrder' => 50,
            'id' => 'custom-field'
        ];


        return $jsLayout;
    }
}
?>

All good so far and the checkbox appears on the checkout page as expected.

Now I’ve added the following jQuery to the footer of the site:



jQuery(document).ready(function() {

  jQuery('form input[name="custom_checkbox"]').attr('checked', false)
  jQuery('form input[name="company"]').prop("disabled", true);

  jQuery('form input[name="custom_checkbox"]').click(function() {

    if (jQuery(this).prop("checked") == true) {

      jQuery('form input[name="company"]').prop("disabled", false);

    } else if (jQuery(this).prop("checked") == false) {

      jQuery('form input[name="company"]').prop("disabled", true);

    }

  });

});


This seems to work when I enter it directly into console but not on the site footer.

The expected functionality is to have the checkbox unticked when the page loads and the company field disabled. Then if the user clicks the checkbox the company field becomes enabled.

Any thoughts on how I can get this working?


Get this bounty!!!

#StackBounty: #javascript #jquery #css Rearrange grid items within resized container keeping one tile constant

Bounty: 100

I have a grid, that has been design with fixed width and height. See image below.

enter image description here

This grid, must work on all screen sizes, while keeping the items in the grid in the same positions.

My code currently resizes these items based off the original width/height of the design and fits them within the new width/height.

Although they do not get positioned correctly in the example below, the calculation does work.

The difficulty I have, is that I need the centre grid tile, which is 504×504, to be static and the others to adjust with this taken into account.

Currently all items, including the centre one adjust, I just want to stop the centre one from adjusting and the others to remove/add the difference to their width/height.

This is a tricky on to explain, let me know if I can add any more details.

<

div class=”snippet”>

const initalWidth = 1043;
const initialHeight = 708;

const resize = (baseDimension, newDimension, itemDimension) => {
  const diff = ((baseDimension - newDimension) / baseDimension) * 100;

  return (Math.ceil(diff) / 100) * itemDimension;
}


const update = () => {
  const newWidth = jQuery(document).width();
  const newHeight = jQuery(document).height();

  jQuery('.grid').css({
    width: newWidth,
    height: newHeight
  })
  
  jQuery('.grid-item').each((i, item) => {
    const itemWidth = jQuery(item).data('width');
    const itemHeight = jQuery(item).data('height');

    const widthDiff = resize(initalWidth, newWidth, itemWidth);
    const heightDiff = resize(initialHeight, newHeight, itemHeight);
    

    jQuery(item).width(Math.floor((itemWidth - widthDiff)));
    jQuery(item).height(Math.floor((itemHeight - heightDiff)));
  })
}

jQuery(document).ready(() => {
    // Run once
  update()
  
  // Run on resize
  jQuery(window).resize(update);
});
.grid{
  border: 1px solid blue;
  width: 100%;
  height: 100%;
}

.grid-item{
  background-color: red;
  float: left;
}
https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
</div>


Get this bounty!!!