Solved

JavaScript in SharePoint 2010 List

Posted on 2016-08-29
5
98 Views
Last Modified: 2016-08-29
Hello Experts,

This code is located within a SharePoint list and I believe is used within a Nintex Form.  I have no idea of its function because I do not know JavaScript.  Can someone please tell me what this is doing?


var hiddenIntervalTimer = 2 * 1000;
var hiddenInputs = new Array();
var hiddenTimerStarted = false;

function EnableConditionControlOnView(controlWithConditionName) {
    var controlWithCondition = NWF$("#" + controlWithConditionName)[0];
    NWF$(controlWithCondition).find("span").removeAttr("disabled");
    NWF$(controlWithCondition).find("input").removeAttr("disabled");
    NWF$(controlWithCondition).removeAttr("disabled");
}

function DisplayControlConditionally(controlToConditionalDisplayClass, controlWithConditionName, displayCondition) {
    if (controlToConditionalDisplayClass != "" && controlWithConditionName != "") {
        var controlWithCondition = NWF$("#" + controlWithConditionName)[0];

        var displayControl = ShouldDisplayControl(controlWithCondition, displayCondition)

        var controlToConditionalDisplay = NWF$("." + controlToConditionalDisplayClass + ".nf-filler-control");

        if (!displayControl) ConditionalDisplayOfControl(controlToConditionalDisplay, displayControl);
        BindConditionalControls(controlToConditionalDisplay, controlWithCondition, displayCondition);
    }
}

function ConditionalDisplayOfControl(controlToConditionalDisplay, displayControl) {

    var controlToConditionalDisplayTop = 0;
    var heightIncrease = 0;
    var hasChanged = false;
    if (displayControl) {
        hasChanged = !controlToConditionalDisplay.is(":visible");
        controlToConditionalDisplay.show();
        controlToConditionalDisplayTop = parseInt(controlToConditionalDisplay.css("top")) - 1;
        heightIncrease = parseInt(controlToConditionalDisplay.css("height"));
    } else {
        hasChanged = controlToConditionalDisplay.is(":visible");
        controlToConditionalDisplayTop = parseInt(controlToConditionalDisplay.css("top")) + parseInt(controlToConditionalDisplay.css("height")) - 1;
        heightIncrease = -parseInt(controlToConditionalDisplay.css("height"));
        controlToConditionalDisplay.hide();
    }
    if (hasChanged) {
        NWF.Utilities.RepositionAndResizeOtherControls(controlToConditionalDisplay, controlToConditionalDisplayTop, heightIncrease);
    }
}

function ShouldDisplayControl(controlWithCondition, displayCondition) {
    var controlValue = null;

    if ((controlWithCondition.type == "radio" || controlWithCondition.type == "checkbox") && typeof (controlWithCondition.checked) != undefined) {
        controlValue = controlWithCondition.checked;
    }
    else if (controlWithCondition.value != undefined) {
        controlValue = controlWithCondition.value;
    }
    else if (NWF$(NWF$(controlWithCondition).find("input:checked")).val() != undefined) {
        controlValue = NWF$(NWF$(controlWithCondition).find("input:checked")).val();
    }

    var displayControl = true;

    if (typeof displayCondition == "function") {
        displayControl = displayCondition(controlValue);
    } else {
        displayControl = controlValue == displayCondition;
    }

    return displayControl;
}

function BindConditionalControls(controlToConditionalDisplay, controlWithCondition, displayCondition) {
    if (controlWithCondition.type == "hidden") {
        hiddenInputs[hiddenInputs.length] = [controlWithCondition, displayCondition, controlToConditionalDisplay, ""];

        if (!hiddenTimerStarted) {
            setTimeout('hiddenInputTimer()', hiddenIntervalTimer);
            hiddenTimerStarted = true;
        }
    } else {

        NWF$(controlWithCondition).bind({
            change: function (event) {

                var displayControl = ShouldDisplayControl(this, displayCondition)

                ConditionalDisplayOfControl(controlToConditionalDisplay, displayControl);
            }
        });
    }
}

function hiddenInputTimer() {
    for (var i = 0; i < hiddenInputs.length; i++) {
        var current = hiddenInputs[i];
        var controlWithCondition = current[0];
        var displayCondition = current[1];
        var controlToConditionalDisplay = current[2];
        var previousValue = current[3];

        if (controlWithCondition.value != previousValue) {
            var displayControl = ShouldDisplayControl(controlWithCondition, displayCondition)

            ConditionalDisplayOfControl(controlToConditionalDisplay, displayControl);
            hiddenInputs[i][3] = controlWithCondition.value;
        }
    }

    setTimeout('hiddenInputTimer()', hiddenIntervalTimer);
}

Open in new window

0
Comment
Question by:ShadowIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 31

Accepted Solution

by:
Jamie McAllister MVP earned 250 total points
ID: 41775369
It's not doing much at all. Very specialized to some sort of custom control. It's there for the display, auto-hiding and refresh/data binding.

I think you're right, part of a product, possibly Nintex.
0
 
LVL 56

Assisted Solution

by:Julian Hansen
Julian Hansen earned 125 total points
ID: 41775472
There is not enough here to determine what is happening.

There is a function that sets a timeout to run every 2 seconds and check through some hidden controls but it refers to a variable current which we can't see in the code. There is also nothing to say what kicks off the process - the code is just a collection of functions - on their own they don't do anything unless called and there is nothing in the source you have posted that says how they are called.
0
 
LVL 17

Assisted Solution

by:Walter Curtis
Walter Curtis earned 125 total points
ID: 41775484
The NWF$ variable does make it seem to be a "Nintex Work Flow" script, used to hide, or enable and disable some control depending upon a condition.

My question is, why do you ask? It is causing problems? Thinking of deleting it? How is it used in the list? How is it deployed?

What other question(s) do you have about it?

Thanks
0
 

Author Comment

by:ShadowIT
ID: 41775496
I ask because I will be assuming responsibility for managing a tool in which the code is being used.  In order to support that I am write a technical specification because this tool was sort of thrown together half-baked and I want to be sure I know how to properly support it.  I've got most of it scoped with the exception of this particular JavaScript which is why I asked others for assistance.
0
 
LVL 17

Expert Comment

by:Walter Curtis
ID: 41775531
Sounds good, thanks for the summary!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sharepoint doesn't work wirth Mozilla Firefox 1 22
Hide and Unhide Table 6 27
How do I post more than 1 item to php backend 24 31
Boolean 13 24
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question