Namespace: jQueryExtensions

jMod. jQueryExtensions

Methods

staticjMod.jQueryExtensions.addCrossOriginSupport(_jQueryObj, dataType)

F:/Projects/jMod/main/bin/jMod.full.js, line 4798
Adds Cross Origin support to a jQuery instance by allowing it to use GM_xmlhttpRequest.
Name Type Default Description
_jQueryObj object optional jQuery object - Defaults to first jQuery instance accessible by jMod
dataType string "* text html xml json" optional A string identifying the data types GM_xmlhttpRequest should handle
Example
if($){
	$(document).ready(function() {
		function test_jQueryFunctions(){
			jMod.jQueryExtensions.addCrossOriginSupport($);
			
			// Test $.ajax()
			console.log('Test $.ajax("http://google.com")');
			$.ajax({
					url: 'http://google.com',
					contentType: 'text/html',
					type: 'GET',
					dataType: 'html',
					onprogress: function(response){
						console.log('onprogress response', response);
					},
					onreadystatechange: function(response){
						console.log('onreadystatechange response', response);
					}
				})
				.done(function(data, textStatus, jqXHR) {
					console.log("$.ajax() success: ", jqXHR);
				})
				.fail(function() {
					console.log("$.ajax() error");
				});
			
			// Test $(element).load()
			console.log('Test $(element).load("http://google.com #hplogo")');
			var tmpDiv = document.createElement('div');
			tmpDiv.id = 'tmpDiv';
			document.body.appendChild(tmpDiv);
			
			$('#tmpDiv').load('http://google.com #hplogo', function(responseText, textStatus, jqXHR){
				console.log('$(element).load() ' + textStatus, jqXHR);
			});
		}

		test_jQueryFunctions();
	});
} else {
	console.log('Test Failed! No jQuery');
}

staticjMod.jQueryExtensions.addSiblingTokens(_jQueryObj)

F:/Projects/jMod/main/bin/jMod.full.js, line 5215
Adds custom sibling selectors ++, +> and +< to the given jQuery instance.
Name Type Default Description
_jQueryObj object jMod.jQuery optional jQuery object

staticjMod.jQueryExtensions.exportCrossOriginSupport(_jQueryObj, dataType)

F:/Projects/jMod/main/bin/jMod.full.js, line 4867
Similar to addCrossOriginSupport, but exports the transport function to the unsafeWindow before extending jQuery. Thus, it can be used on a jQuery instance that exists in the unsafeWindow. This is less safe than using "addCrossOriginSupport" and should only be used if there is no alternative.
Name Type Default Description
_jQueryObj object optional jQuery object - Defaults to first jQuery instance accessible by jMod
dataType string "* text html xml json" optional A string identifying the data types GM_xmlhttpRequest should handle

staticjMod.jQueryExtensions.extendTokenizer(_jQueryObj)

F:/Projects/jMod/main/bin/jMod.full.js, line 4954
Extend more than just jQuery's (aka sizzle) pseudo-selectors (ex ".class:selector"). With this you can completely override the main jQuery find function with a custom tokenizer. You can augment, or completely replace the default selector syntax.

For example, you could add the token "++" to select all of an element's siblings that match a selector: $(".example ++ .sibling-class") or $(".example ++ *")
Or you could add "+>" and "+<" to match siblings that appear before and after the matched elements: $(".example +> .next-sibling") or $(".example +< .prev-sibling")
Name Type Default Description
_jQueryObj object jMod.jQuery optional jQuery object
Example
console.log('Test jQuery Tokenizer');
var newEl = jMod.Element.createNewElement({
	id: 'testElement',
	innerHTML: [
		{
			className: 'tc1',
			innerHTML: [
				{
					className: 'tc1-1 childElement-1'
				},
				{
					className: 'tc1-2 childElement-1'
				},
				{
					className: 'tc1-3 childElement-1',
					innerHTML: {
						className: 'tc1-3-1 childElement-2',
						innerHTML: {
							className: 'tc1-3-1-1 childElement-3'
						}
					}
				}
			]
		},
		{
			className: 'tc2',
			innerHTML: [
				{
					className: 'tc2-1 childElement-1'
				},
				{
					className: 'tc2-3 childElement-1'
				}
			]
		},
		{
			className: 'tc3',
			innerHTML: [
				{
					className: 'tc3-1 childElement-1'
				}
			]
		}
	]
});

document.body.appendChild(newEl);

console.log('Add Tokenizer');
jMod.jQueryExtensions.extendTokenizer($);

console.log('Add Sibling Tokens');
jMod.jQueryExtensions.addSiblingTokens($);

console.log("jQuery Find Function:");
console.dir($.find);

// Test 1
var test1 = $(".tc1-2 + .tc1-3");
console.log('test: sibling matching ".tc1-3"', test1, test1.length == 1 ? "Pass!" : "Fail!");

// Test 2
var test2 = $(".tc1-2 ++ *");
console.log('test: all siblings', test2, test2.length == 2 ? "Pass!" : "Fail!");

// Test 3
var test3 = $(".tc1-2 +< *");
console.log('test: all previous siblings', test3, test3.length == 1 ? "Pass!" : "Fail!");

// Test 4
var test4 = $(".tc1-2 +> *");
console.log('test: all next siblings', test4, test4.length == 1 ? "Pass!" : "Fail!");

// Test 5
var test5 = $(".tc1-2 ++ * .childElement-3");
console.log('test: child of sibling with class name "childElement-3"', test5, test5.length == 1 ? "Pass!" : "Fail!");

// Test 6
var test6 = $(".tc3 ++ * .childElement-1");
console.log('test: child of sibling with class name "childElement-1"', test6, test6.length == 5 ? "Pass!" : "Fail!");

console.log('End Test jQuery Tokenizer');

staticjMod.jQueryExtensions.removeTokenizer(_jQueryObj)

F:/Projects/jMod/main/bin/jMod.full.js, line 5272
Removes the jMod tokenizer extension from the given jQuery instance.
Name Type Default Description
_jQueryObj object jMod.jQuery optional jQuery object