'use strict';

/**
 * @param {FetcherIndex} index to use for URL resolution
 * @param {Object} context e.g. jQuery, $, etc
 * @param {String} method name e.g. 'ajax'
 * @returns {Function} the shim
 */

//var cheerio = require('cheerio');

module.exports = function (index, context, method) {
  var oldMethod = context[method];

  var fixSrc = function (whole, value) {
    console.log('input whole is: '+ whole + ', value is: ' + value);
    var fixValue;
    if (value && typeof value === 'string') {
      fixValue = index.resolveLocalUrl(value);
      whole = whole.replace(value, fixValue);
    }
    console.log('fixed whole is: '+ whole + ', value is: ' + fixValue);
    return whole;
  };

  var fixHtml = function (value) {
    if (value && typeof value === 'string') {
      value = value.replace(/<img[-_\s\=\"\'\.\/\w]* src="([-_\.\/\w]+)"/gmi, fixSrc);
    }

    return value;
  };

  context[method] = function (htmlString) {
    var args;
    if (!arguments.length) {
      return oldMethod.call(this);
    }

    if (htmlString && typeof htmlString === 'string') {
      htmlString = fixHtml(htmlString);
    }
    return oldMethod.call(this, htmlString);
  };

  return context[method];

};

@@ -110,16 +110,19 @@
 Query, $
+.fn
 , etc%0A *
@@ -160,12 +160,12 @@
 g. '
-ajax
+html
 '%0A *
@@ -203,45 +203,8 @@
 */%0A%0A
-//var cheerio = require('cheerio');%0A%0A
 modu
@@ -333,77 +333,8 @@
 ) %7B%0A
-    console.log('input whole is: '+ whole + ', value is: ' + value);%0A
     
@@ -496,80 +496,8 @@
   %7D%0A
-    console.log('fixed whole is: '+ whole + ', value is: ' + fixValue);%0A
     

remove console log