diff --git a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js index 88f2ace..299ae3e 100644 --- a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js @@ -198,8 +198,7 @@ exports.module = function(phantomas) { callDetails: { context: { length: this.length, - firstElementPath: phantomas.getDOMPath(context), - toto: this + firstElementPath: phantomas.getDOMPath(context) }, arguments: [selector] }, @@ -213,6 +212,40 @@ exports.module = function(phantomas) { phantomas.leaveContext(moreData); }) || phantomas.log('jQuery: can not measure jQuerySizzleCalls (jQuery used on the page is too old)!'); + + phantomas.spy(jQuery.fn, 'init', function(selector, context) { + if (typeof selector === 'string' && /^#([\w\-]*)$/.exec(selector) !== null && !context) { + + phantomas.enterContext({ + type: 'jQuery - find', + callDetails: { + context: { + length: 1, + firstElementPath: '#document' + }, + arguments: [selector] + }, + backtrace: phantomas.getBacktrace() + }); + + } + + }, function(result) { + var data = phantomas.getContextData(); + + if (data.type === 'jQuery - find' && + data.callDetails.context.firstElementPath === '#document' && + data.callDetails.arguments.length === 1 && + /^#([\w\-]*)$/.exec(data.callDetails.arguments[0]) !== null) { + + var moreData = { + resultsNumber : (result && result.length) ? result.length : 0 + }; + phantomas.leaveContext(moreData); + } + }); + + /*if (!jQuery.event) { phantomas.spy(jQuery.event, 'trigger', function(ev, data, elem) { var path = phantomas.getDOMPath(elem), @@ -243,7 +276,6 @@ exports.module = function(phantomas) { // Add spys on many jQuery functions jQueryFunctions.forEach(function(functionName) { - var capitalizedName = functionName.substring(0,1).toUpperCase() + functionName.substring(1); phantomas.spy(jQuery.fn, functionName, function(args) { @@ -303,14 +335,9 @@ exports.module = function(phantomas) { args[index] = arg; }); - // Differentiate between $('.foo') and $(...).find('.foo') - var functionNameDisplayed = functionName; - if (functionName === 'find' && this.prevObject === undefined) { - functionNameDisplayed = '$'; - } phantomas.enterContext({ - type: 'jQuery - ' + functionNameDisplayed, + type: 'jQuery - ' + functionName, callDetails: { context: { length: this.length, @@ -323,7 +350,7 @@ exports.module = function(phantomas) { }, function(result) { phantomas.leaveContext(); - }) || phantomas.log('jQuery: can not track jQuery - ' + capitalizedName + ' (this version of jQuery doesn\'t support it)'); + }) || phantomas.log('jQuery: can not track jQuery - ' + functionName + ' (this version of jQuery doesn\'t support it)'); }); }); })(window.__phantomas);