TheBigK
Well-known member
I'm referring to the scratchpad.js which is a part of Kier's Scratchpad addon. The file starts with this -
!function($, window, document, _undefined)
I've following questions:-
1. Why does it have "!" before function()? Is it not negating the private scope of stuff inside the function?
2. Why is undefined variable written as _undefined? Is it just a way of writing or there's something more to it?
3. Why do we have a namespace when we already are inside a function? [Does this question make sense?]
This is the JS file:-
	
	
	
		
				
			!function($, window, document, _undefined)
I've following questions:-
1. Why does it have "!" before function()? Is it not negating the private scope of stuff inside the function?
2. Why is undefined variable written as _undefined? Is it just a way of writing or there's something more to it?
3. Why do we have a namespace when we already are inside a function? [Does this question make sense?]
This is the JS file:-
		Code:
	
	/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
    // new namespace for this add-on: XenForo.Scratchpad
    XenForo.Scratchpad =
    {
        /**
         * A bit like quick reply, but for scratchpad notes
         *
         * @param jQuery form.ScratchpadQuickNote
         */
        QuickNote: function($form)
        {
            // bind a function onto the AutoValidationComplete event of the form AutoValidator
            $form.bind('AutoValidationComplete', function(e)
            {
                // check that templateHtml was received from the AJAX request
                if (e.ajaxData.templateHtml)
                {
                    // prevent the normal AutoValidator success message and redirect stuff
                    e.preventDefault();
                    // hide the 'no notes' message if it's there, and when it is hidden...
                    $('#ScratchpadNoNotes').slideUp(XenForo.speed.fast, function()
                    {
                        // ... load any externals specified by the template, and when that's done...
                        new XenForo.ExtLoader(e.ajaxData, function()
                        {
                            // ... prepend the templateHtml into the notes area
                            $(e.ajaxData.templateHtml).xfInsert('prependTo', '#ScratchpadNewNotes');
                        });
                        // clear the textarea contents and refocus it
                        $form.find('textarea[name=message]').val('').focus();
                        // set the 'date' input field to contain the date of the most recent post (from ajaxData)
                        $form.find('input[name=date]').val(e.ajaxData.date);
                        // re-enable the submit button if it's been disabled
                        $form.find('input:submit').removeAttr('disabled').removeClass('disabled');
                    });
                }
            });
        }
    };
    // register the QuickNote functionality
    XenForo.register('form.ScratchpadQuickNote', 'XenForo.Scratchpad.QuickNote');
}
(jQuery, this, document); 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		