retreaverjs-rails 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9b374f9d6b7c8aa36c2d301d0e82f0f19bdd1c8
4
- data.tar.gz: 974c41df52ebeb2367e689a8ca183e431a7bef2a
3
+ metadata.gz: 3885137c8fe180bd0b33e52826f5b26523dc8ca1
4
+ data.tar.gz: 9ad2f9a3b1c520459db7d64a98c666c3c8102b69
5
5
  SHA512:
6
- metadata.gz: 4393a40c72fdae3705e7c1ea508e5bf4ca383bce317a6d3338f84894f6fe36f85dc4bfc790ea5539c02cdf99410a77a90e39ede996def8d56d289012abf91338
7
- data.tar.gz: bea65da334b8c3863a7e87523350fb453390d6240325cb6aa7dc7346b701b489acd58ebbe0070b73ca98332ed118d5d76bfeff87d5658587ebba6dbba06b7541
6
+ metadata.gz: 47f7256897d21e8a218c5f60a6a5c3f7478c4debbfdb63e9d3acc5a17d95adfd45aa99d06978b3d13651ff5c0743f1fdebfc665e876b246d6f9f60c5f00cc221
7
+ data.tar.gz: a114c84069a0068da6e8b7779b8f32989beff73077391f29abb55a93205d261c0c94241952a9ebf3852a75ca49939754519e51408e6591dc1b4863cb2b8a5721
data/Gruntfile.js CHANGED
@@ -19,7 +19,8 @@ module.exports = function (grunt) {
19
19
  'src/retreaver/cache.js',
20
20
  'src/retreaver/number.js',
21
21
  'src/retreaver/campaign.js',
22
- 'src/retreaver/callpixels.js'
22
+ 'src/retreaver/callpixels.js',
23
+ 'src/retreaver/vendor/find_and_replace_dom_text.js'
23
24
  ],
24
25
  dest: 'dist/<%= pkg.name %>.js'
25
26
  }
@@ -46,4 +47,4 @@ module.exports = function (grunt) {
46
47
  grunt.loadNpmTasks('grunt-contrib-concat');
47
48
 
48
49
  grunt.registerTask('default', ['concat', 'uglify']);
49
- };
50
+ };
@@ -1,5 +1,5 @@
1
1
  module Retreaver
2
2
  module Rails
3
- VERSION = '0.2.5'
3
+ VERSION = '0.2.6'
4
4
  end
5
5
  end
data/package.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "node": ">= 0.6.x"
39
39
  },
40
40
  "dependencies": {
41
+ "findandreplacedomtext": "^0.4.4"
41
42
  },
42
43
  "devDependencies": {
43
44
  "grunt": "~0.4.5",
@@ -48,4 +49,4 @@
48
49
  "grunt-contrib-watch": "~0.6.1",
49
50
  "grunt-contrib-concat": "~0.4.0"
50
51
  }
51
- }
52
+ }
@@ -16,6 +16,27 @@
16
16
  self.store(data);
17
17
  }
18
18
 
19
+ function find_and_replace_number(replacement_numbers) {
20
+ for (i = 0; i < replacement_numbers.length; i++) {
21
+ rn = replacement_numbers[i];
22
+
23
+ Retreaver.Vendor.findAndReplaceDOMText(document.getElementsByTagName('body')[0], {
24
+ find: rn['find'],
25
+ replace: rn['replace_with']
26
+ });
27
+
28
+ var links = document.getElementsByTagName('a');
29
+ for (j = 0; j < links.length; j++) {
30
+ link = links[j];
31
+ href = link.getAttribute('href');
32
+ match = href.match(/tel:(.*)/);
33
+ if (match && match[1] === rn['find']) {
34
+ link.setAttribute('href', 'tel:' + rn['replace_with']);
35
+ }
36
+ }
37
+ }
38
+ }
39
+
19
40
  var self = this;
20
41
  self.type = 'campaigns';
21
42
  self.primary_key('campaign_key');
@@ -55,6 +76,12 @@
55
76
  if (typeof(data) !== 'undefined' && typeof(data.number) !== 'undefined' && data.number !== '') {
56
77
  // initialize number
57
78
  var number = new Retreaver.Number(data.number);
79
+
80
+ // if there is a replacement in the response, replace all occurances
81
+ // of that number on the page with the retreaver number
82
+ if (typeof(data.number.replacement_numbers) !== 'undefined') {
83
+ find_and_replace_number(data.number.replacement_numbers);
84
+ }
58
85
  // call callback
59
86
  callback.apply(self, [number]);
60
87
  }
@@ -64,6 +91,35 @@
64
91
  }
65
92
  });
66
93
  };
94
+
95
+ /**
96
+ * Auto replace all numbers on page according to campaign settings
97
+ * Calls campaign.request_number
98
+ * @memberOf Retreaver.Campaign
99
+ * @function auto_replace_number
100
+ * @instance
101
+ * @param {getNumberCallback} callback - Callback fired if the request completes successfully.
102
+ * @param {Function} error_callback - Callback fired if the request raises an error.
103
+ * @example
104
+ * campaign.auto_replace_number({calling_about: 'support'}, function (number) {
105
+ * alert(number.get('number'))
106
+ * }, function(response){
107
+ * alert('something went wrong: ' + response);
108
+ * };
109
+ */
110
+ self.auto_replace_numbers = function (callback, error_callback) {
111
+ if (typeof callback === 'undefined') {
112
+ callback = function () {
113
+ };
114
+ }
115
+
116
+ if (typeof error_callback === 'undefined') {
117
+ error_callback = function () {
118
+ };
119
+ }
120
+ self.request_number({}, callback, error_callback);
121
+ };
122
+
67
123
  /**
68
124
  * Retreaver.Campaign#request_number callback fired after the request completes.
69
125
  * @callback getNumberCallback
@@ -95,8 +151,7 @@
95
151
  }
96
152
  if (tags && (typeof tags === "object") && !(tags instanceof Array)) {
97
153
  return tags
98
- }
99
- else {
154
+ } else {
100
155
  throw "ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";
101
156
  }
102
157
  };
@@ -105,4 +160,4 @@
105
160
  };
106
161
  Campaign.prototype = new Retreaver.Base.Model();
107
162
  Retreaver.Campaign = Campaign;
108
- })();
163
+ })();
@@ -1103,6 +1103,27 @@
1103
1103
  self.store(data);
1104
1104
  }
1105
1105
 
1106
+ function find_and_replace_number(replacement_numbers) {
1107
+ for (i = 0; i < replacement_numbers.length; i++) {
1108
+ rn = replacement_numbers[i];
1109
+
1110
+ Retreaver.Vendor.findAndReplaceDOMText(document.getElementsByTagName('body')[0], {
1111
+ find: rn['find'],
1112
+ replace: rn['replace_with']
1113
+ });
1114
+
1115
+ var links = document.getElementsByTagName('a');
1116
+ for (j = 0; j < links.length; j++) {
1117
+ link = links[j];
1118
+ href = link.getAttribute('href');
1119
+ match = href.match(/tel:(.*)/);
1120
+ if (match && match[1] === rn['find']) {
1121
+ link.setAttribute('href', 'tel:' + rn['replace_with']);
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+
1106
1127
  var self = this;
1107
1128
  self.type = 'campaigns';
1108
1129
  self.primary_key('campaign_key');
@@ -1142,6 +1163,12 @@
1142
1163
  if (typeof(data) !== 'undefined' && typeof(data.number) !== 'undefined' && data.number !== '') {
1143
1164
  // initialize number
1144
1165
  var number = new Retreaver.Number(data.number);
1166
+
1167
+ // if there is a replacement in the response, replace all occurances
1168
+ // of that number on the page with the retreaver number
1169
+ if (typeof(data.number.replacement_numbers) !== 'undefined') {
1170
+ find_and_replace_number(data.number.replacement_numbers);
1171
+ }
1145
1172
  // call callback
1146
1173
  callback.apply(self, [number]);
1147
1174
  }
@@ -1151,6 +1178,35 @@
1151
1178
  }
1152
1179
  });
1153
1180
  };
1181
+
1182
+ /**
1183
+ * Auto replace all numbers on page according to campaign settings
1184
+ * Calls campaign.request_number
1185
+ * @memberOf Retreaver.Campaign
1186
+ * @function auto_replace_number
1187
+ * @instance
1188
+ * @param {getNumberCallback} callback - Callback fired if the request completes successfully.
1189
+ * @param {Function} error_callback - Callback fired if the request raises an error.
1190
+ * @example
1191
+ * campaign.auto_replace_number({calling_about: 'support'}, function (number) {
1192
+ * alert(number.get('number'))
1193
+ * }, function(response){
1194
+ * alert('something went wrong: ' + response);
1195
+ * };
1196
+ */
1197
+ self.auto_replace_numbers = function (callback, error_callback) {
1198
+ if (typeof callback === 'undefined') {
1199
+ callback = function () {
1200
+ };
1201
+ }
1202
+
1203
+ if (typeof error_callback === 'undefined') {
1204
+ error_callback = function () {
1205
+ };
1206
+ }
1207
+ self.request_number({}, callback, error_callback);
1208
+ };
1209
+
1154
1210
  /**
1155
1211
  * Retreaver.Campaign#request_number callback fired after the request completes.
1156
1212
  * @callback getNumberCallback
@@ -1182,8 +1238,7 @@
1182
1238
  }
1183
1239
  if (tags && (typeof tags === "object") && !(tags instanceof Array)) {
1184
1240
  return tags
1185
- }
1186
- else {
1241
+ } else {
1187
1242
  throw "ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";
1188
1243
  }
1189
1244
  };
@@ -1192,6 +1247,7 @@
1192
1247
  };
1193
1248
  Campaign.prototype = new Retreaver.Base.Model();
1194
1249
  Retreaver.Campaign = Campaign;
1195
- })();;(function (context) {
1250
+ })();
1251
+ ;(function (context) {
1196
1252
  context.Callpixels = window.Retreaver;
1197
1253
  })(window);
@@ -1,2 +1,2 @@
1
- /*! retreaver 26-05-2016 */
2
- !function(a){var b={configure:function(a){var c={addr:a.host,http_prefix:"http",urlregex:"/\\/\\/[^\\/]*\\/(.*)/"};"undefined"!=typeof a.prefix&&(c.http_prefix=a.prefix),window.Retreaver._connection=new b.Base.Request(c)}};a.Retreaver=b}(window),function(){"undefined"==typeof window.Retreaver&&(window.Retreaver={});var a={};a.assert_required_keys=function(){for(var a=Array.prototype.slice.call(arguments),b=a.shift(),c=0;c<a.length;c++){var d=a[c];if("undefined"==typeof b||"undefined"==typeof b[d])throw"ArgumentError: Required keys are not defined: "+a.join(", ")}return b},a.merge=function(b,c){for(var d in c)try{c[d].constructor==Object?b[d]=a.merge(b[d],c[d]):b[d]=c[d]}catch(e){b[d]=c[d]}return b},a.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.ieVersion=function(){return null==a._ieVersion&&(a._ieVersion=function(){for(var a=3,b=document.createElement("div"),c=b.getElementsByTagName("i");b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->",c[0];);return a>4?a:!1}()),6!=a._ieVersion&&7!=a._ieVersion||null==Retreaver.easyxdm_loaded&&(Retreaver.easyxdm_loaded=!1),a._ieVersion},Retreaver.Base=a}(),function(a){var b=function(a,c,d){return 1===arguments.length?b.get(a):b.set(a,c,d)};b._document=document,b._navigator=navigator,b.defaults={path:"/"},b.get=function(a){return b._cachedDocumentCookie!==b._document.cookie&&b._renewCache(),b._cache[a]},b.set=function(a,c,d){return d=b._getExtendedOptions(d),b._document.cookie=b._generateCookieString(a,c,d),b},b._getExtendedOptions=function(c){return{path:c&&c.path||b.defaults.path,domain:c&&c.domain||b.defaults.domain,secure:c&&c.secure!==a?c.secure:b.defaults.secure}},b._isValidDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a.getTime())},b._generateCookieString=function(a,b,c){return a=encodeURIComponent(a),b=(b+"").replace(/[^!#$&-+\--:<-\[\]-~]/g,encodeURIComponent),c=c||{},a=a+"="+b+(c.path?";path="+c.path:""),a+=c.domain?";domain="+c.domain:"",a+=c.secure?";secure":""},b._getCookieObjectFromString=function(c){var d={};c=c?c.split("; "):[];for(var e=0;e<c.length;e++){var f=b._getKeyValuePairFromCookieString(c[e]);d[f.key]===a&&(d[f.key]=f.value)}return d},b._getKeyValuePairFromCookieString=function(a){var b=a.indexOf("="),b=0>b?a.length:b;return{key:decodeURIComponent(a.substr(0,b)),value:decodeURIComponent(a.substr(b+1))}},b._renewCache=function(){b._cache=b._getCookieObjectFromString(b._document.cookie),b._cachedDocumentCookie=b._document.cookie},b._areEnabled=function(){return b._navigator.cookieEnabled||"1"===b.set("cookies.js",1).get("cookies.js")},b.enabled=b._areEnabled(),"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=b),exports.Cookies=b):b,Retreaver.Base.Cookies=b}(),function(){var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};Base64.encode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=Base64._utf8_encode(a);j<a.length;)b=a.charCodeAt(j++),c=a.charCodeAt(j++),d=a.charCodeAt(j++),e=b>>2,f=(3&b)<<4|c>>4,g=(15&c)<<2|d>>6,h=63&d,isNaN(c)?g=h=64:isNaN(d)&&(h=64),i=i+Base64._keyStr.charAt(e)+Base64._keyStr.charAt(f)+Base64._keyStr.charAt(g)+Base64._keyStr.charAt(h);return i},Base64.decode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");j<a.length;)e=Base64._keyStr.indexOf(a.charAt(j++)),f=Base64._keyStr.indexOf(a.charAt(j++)),g=Base64._keyStr.indexOf(a.charAt(j++)),h=Base64._keyStr.indexOf(a.charAt(j++)),b=e<<2|f>>4,c=(15&f)<<4|g>>2,d=(3&g)<<6|h,i+=String.fromCharCode(b),64!=g&&(i+=String.fromCharCode(c)),64!=h&&(i+=String.fromCharCode(d));return i=Base64._utf8_decode(i)},Base64._utf8_encode=function(string){string=string.replace(eval("/\\r\\n/g"),eval("String('\\n')"));for(var utftext="",n=0;n<string.length;n++){var c=string.charCodeAt(n);128>c?utftext+=String.fromCharCode(c):c>127&&2048>c?(utftext+=String.fromCharCode(c>>6|192),utftext+=String.fromCharCode(63&c|128)):(utftext+=String.fromCharCode(c>>12|224),utftext+=String.fromCharCode(c>>6&63|128),utftext+=String.fromCharCode(63&c|128))}return utftext},Base64._utf8_decode=function(a){for(var b="",c=0,d=c1=c2=0;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):d>191&&224>d?(c2=a.charCodeAt(c+1),b+=String.fromCharCode((31&d)<<6|63&c2),c+=2):(c2=a.charCodeAt(c+1),c3=a.charCodeAt(c+2),b+=String.fromCharCode((15&d)<<12|(63&c2)<<6|63&c3),c+=3);return b},Retreaver.Base.Base64=Base64}(),function(){var a=Retreaver.Base,b=function(b){function c(){a.assert_required_keys(b,"type","primary_key"),"undefined"==typeof Retreaver.Base.Data._store[b.type]&&(Retreaver.Base.Data._store[b.type]={}),"undefined"==typeof Retreaver.Base.Data._store[b.type][b.primary_key]&&(Retreaver.Base.Data._store[b.type][b.primary_key]={})}var d=this;d.get=function(){var a={};if("undefined"==typeof arguments[0])a=Retreaver.Base.Data._store[b.type][b.primary_key];else if(1===arguments.length)a=Retreaver.Base.Data._store[b.type][b.primary_key][arguments[0]];else for(var c=0;c<arguments.length;c++){var d=arguments[c];a[d]=Retreaver.Base.Data._store[b.type][b.primary_key][d]}return a},d.set=function(a,c){return Retreaver.Base.Data._store[b.type][b.primary_key][a]=c,c},d.merge=function(a){for(var c in a)Retreaver.Base.Data._store[b.type][b.primary_key][c]=a[c];return a},c()};b._store={},Retreaver.Base.Data=b}(),function(){var a=Retreaver.Base,b=Retreaver.Base.Data,c=function(){this.api_host_uri="/api/v1/",this.type="model",this.primary_key=function(a){return c.primary_key(this.type,a)},this.store=function(a){if("undefined"!=typeof a){var b=this.primary_key();if("undefined"==typeof a[b])throw"ArgumentError: Expected to receive primary_key "+b;"undefined"==typeof this._store&&(this._store=new Retreaver.Base.Data({type:this.type,primary_key:a[b]})),this._store.merge(a),c.update_visitor_id(a)}return this._store},this.get_data=function(a,b){return this.connection().getJSON(this.api_host_uri+a,null,[c.update,b],this)},this.post_data=function(a,b,d){return this.connection().postJSON(this.api_host_uri+a,b,[c.update,d],this)},this.set=function(){return"function"==typeof this["set_"+arguments[0]]&&(arguments[1]=this["set_"+arguments[0]].apply(this,[arguments[1]])),this._store.set.apply(this,arguments)},this.get=function(){return this._store.get.apply(this,arguments)},this.connection=function(){return Retreaver.Base.Request.connection()}};c.inflections={number:"numbers",campaign:"campaigns"},c.update=function(d){for(var e in d){var f=e,g=d[e];if("undefined"!=typeof c.inflections[e]&&(f=c.inflections[e]),"undefined"!=typeof b._store[f])if(a.isArray(g))for(var h=0;h<g.length;h++)c.update_record(f,g[h]);else c.update_record(f,g[h])}return d},c.update_record=function(a,b){if(c.update_visitor_id(b),"undefined"!=typeof b.id){var d=c.primary_key(a);for(var e in b)Retreaver.Base.Data._store[a][b[d]][e]=b[e];return!0}return!1},c.update_visitor_id=function(a){"undefined"!=typeof a&&"undefined"!=typeof a.visitor_id&&Retreaver.Base.Cookies.set("CallPixels-vid",a.visitor_id)},c.primary_key=function(a,b){return"undefined"==typeof c.primary_keys&&(c.primary_keys={}),"undefined"==typeof c.primary_keys[a]&&(c.primary_keys[a]="id"),"undefined"!=typeof b&&(c.primary_keys[a]=b),c.primary_keys[a]},Retreaver.Base.Model=c}(),function(){var Base=window.Retreaver.Base,Cookies=window.Retreaver.Base.Cookies,Request=function(options){function initialize(a){config=Base.assert_required_keys(a,"http_prefix","addr","urlregex")}function with_ie_scripts(a){Retreaver.easyxdm_loaded?a():self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/easyXDM.min.js",function(){self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/json2.js",function(){Retreaver.easyxdm_loaded=!0,a()})})}var self=this,config={};self.getJSON=function(a,b,c,d){"function"==typeof c&&(c=[c]),"undefined"==typeof d&&(d=self);var e=function(){self.apiRequest(a,function(a){response=JSON.parse(a);for(var b in c)"function"==typeof c[b]&&c[b].apply(d,[response])},b)};6==Base.ieVersion()||7==Base.ieVersion()?with_ie_scripts(e):e()},self.postJSON=function(){return self.getJSON.apply(this,arguments)},self.apiRequest=function(request_uri,callbackFunctions,payload){function ignored(){}function runCallbacks(a){for(var b in callbackFunctions)"function"==typeof callbackFunctions[b]&&callbackFunctions[b](a)}function forwardResponse(){runCallbacks(xdr.responseText)}function sendXdm(){var remote=http_prefix+"://"+addr+"/ie_provider",swf=http_prefix+"://"+addr+"/easyxdm.swf",rpc=eval('new window.easyXDM.Rpc({ remote: "'+remote+'", swf: "'+swf+'"},{remote: {request: {}}});');rpc.request({url:"/"+request_url.match(urlregex)[1],method:"POST",data:payload},function(a){runCallbacks(a.data)})}var http_prefix=config.http_prefix,addr=config.addr,urlregex=eval(config.urlregex),request_url=http_prefix+"://"+addr+request_uri;if(payload&&"undefined"!=typeof Cookies.get("CallPixels-vid")&&"null"!==Cookies.get("CallPixels-vid")&&(payload.visitor_id=Cookies.get("CallPixels-vid")),"function"==typeof callbackFunctions&&(callbackFunctions=[callbackFunctions]),window.XDomainRequest){var xdr=new XDomainRequest;xdr.onload=forwardResponse,xdr.onprogress=ignored,xdr.onerror=ignored,xdr.ontimeout=ignored,xdr.timeout=3e4,payload?(xdr.open("post",request_url),xdr.send(self.buildPost(payload))):(xdr.open("get",request_url),xdr.send())}else if(6==Base.ieVersion()||7==Base.ieVersion())with_ie_scripts(sendXdm);else{var request=new XMLHttpRequest;payload?(request.open("POST",request_url,!1),request.setRequestHeader("Content-Type","application/json"),request.send(JSON.stringify(payload))):(request.open("GET",request_url,!1),request.send()),runCallbacks(request.responseText)}},self.buildPost=function(a){var b="";for(var c in a)b+=c+"="+a[c]+"&";return b},self.loadScript=function(a,b){var c=document.getElementsByTagName("script")[0],d=document.createElement("script");d.type="text/javascript",d.async=!1,d.src=a;var e=function(a,b){"loaded"==a.readyState||"complete"==a.readyState?b():setTimeout(function(){e(a,b)},100)};"function"==typeof b&&("undefined"!=typeof d.addEventListener?d.addEventListener("load",b,!1):d.onreadystatechange=function(){d.onreadystatechange=null,e(d,b)}),c.parentNode.insertBefore(d,c)},initialize(options),self.config=config};Request.connection=function(){if("undefined"==typeof window.Retreaver._connection){var a=window.location.protocol.replace(":","");window.Retreaver._connection=new Retreaver.Base.Request({addr:"api.rtvrapi.com",http_prefix:a,urlregex:"/\\/\\/[^\\/]*\\/(.*)/"})}return window.Retreaver._connection},Retreaver.Base.Request=Request}(),function(){function tags_to_script_tags(a){var b="";for(var c in a){var d=a[c];b=b+"&"+c+"="+d}return b}var Base=Retreaver.Base,Cookies=Retreaver.Base.Cookies,Base64=Retreaver.Base.Base64,Request=Retreaver.Base.Request,RequestNumber=function(options){function initialize(a){config=Base.assert_required_keys(a,"campaign_key")}function getParts(a){for(var b={},c=0;c<a.length;c++){var d=getUrlParts(a[c]);for(var e in d)b[e]=d[e]}return b}function getUrlParts(url){var objURL=new Object;try{url=url.match(eval("/\\?(.*)/"))[0]}catch(e){return objURL}return url.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"),function(a,b,c,d){objURL[b.toLowerCase()]=d}),objURL}function getGACookies(){var a=["__utma","__utmb","__utmc","__utmz","__utmv"],b=new Object;for(var c in a){var d=extractCookie(a[c]);if(!(d||c>0))break;d&&(b[a[c]]=d)}return b}function extractCookie(a){var b=new RegExp(a+"=([^;]*)","g");try{return b.exec(document.cookie)[1]}catch(c){return!1}}function findOne(a,b){for(var c in b)for(var d in a)if(d==b[c])return a[d];return!1}var self=this,config={},resource_url="/api/v1/numbers?";self.perform=function(callback){function sendGARequest(a,b){body.ga=Base64.encode(a),body.c=Base64.encode(JSON.stringify(b)),Request.connection().getJSON(request_url,body,callback)}if("function"!=typeof callback)throw"ArgumentError: Expected to receive a callback function";var request_url=resource_url+"&campaign_key="+config.campaign_key;config.default_number_replacement&&(request_url=request_url+"&default_number="+config.default_number_replacement),config.message_replacement&&(request_url=request_url+"&message="+config.message_replacement);var body=new Object,uri=document.location.href;body.u=Base64.encode(uri),body.st=Base64.encode(tags_to_script_tags(config.number_matching_tags));var ou=Cookies.get("CallPixels-ou");getParts([document.location.href]).cpreset||!ou?Cookies.set("CallPixels-ou",body.u):body.ou=ou;var ga_acct="FAILED";try{_gaq.push(function(){ga_acct=eval("_gat._getTrackerByName()._getAccount()"),sendGARequest(ga_acct,getGACookies())})}catch(e){try{ga(function(tracker){if(tracker&&tracker.get)try{var clientId=tracker.get("clientId"),allTrackers=eval("ga.getAll()");ga_acct=allTrackers[0].get("trackingId");var ga_cookies={};ga_cookies.__utma=clientId,ga_cookies.mp="yes",sendGARequest(ga_acct,ga_cookies)}catch(g){sendGARequest("",{})}else sendGARequest("",{})})}catch(f){Request.connection().getJSON(request_url,body,callback)}}},initialize(options)};Retreaver.Base.RequestNumber=RequestNumber}(),window.Retreaver.Cache={},function(){function a(b){if("undefined"!=typeof Retreaver.Base.Data._store){var c=Retreaver.Base.Data._store.numbers;if("undefined"!=typeof c){var d={};for(var e in c){var f=c[e];"true"===f.is_active&&("undefined"==typeof d[f.campaign_key]&&(d[f.campaign_key]=[],d[f.campaign_key].ids=[],d[f.campaign_key].hashes=[]),d[f.campaign_key].ids.push(f.id),d[f.campaign_key].hashes.push(f.id_checksum))}for(var g in d){var h={ids:d[g].ids,hashes:d[g].hashes};Retreaver.Base.Request.connection().postJSON("/api/v1/numbers/ping",h,[Retreaver.Base.Model.update,b],this)}}}setTimeout(a,15e3)}var b=Retreaver.Base;Retreaver.Number=function(a){function c(a){g.store(a),g.set("is_active","true")}function d(a){return"string"==typeof a&&(a=Retreaver.Number.extract_tags_from_string(a)),{tag_values:a,ids:[e("id")],campaign_key:e("campaign_key")}}function e(a){return g.get(a)}function f(){if(g.get("is_per_visitor")===!1)throw"Error: Tried to add tags to non per-visitor number."}var g=this;g.type="numbers",g.add_tags=function(a,b){f(),g.post_data("numbers/tag",d(a),b)},g.remove_tags=function(a,b){f(),g.post_data("numbers/untag",d(a),b)},g.remove_tags_by_keys=function(a,b){f(),"string"==typeof a&&(a=a.split(","));var c={tag_keys:a,ids:[e("id")],campaign_key:e("campaign_key")};g.post_data("numbers/untag/keys",c,b)},g.clear_tags=function(a){f();var b={ids:[e("id")],campaign_key:e("campaign_key"),all:"true"};g.post_data("numbers/untag",b,a)},g.release=function(){g.set("is_active","false")},g.initiate_call=function(a,c,d){"undefined"==typeof c&&(c={}),c.dial=a,c=b.merge(g.get("id","campaign_key"),c),g.post_data("numbers/initiate_call",c,d)},c(a)},Retreaver.Number.extract_tags_from_string=function(a){for(var b={},a=a.split(","),c=0;c<a.length;c++){var d=a[c].split(":");b[d[0]]=d[1]}return b},Retreaver.Number.prototype=new Retreaver.Base.Model,a()}(),function(){var a=Retreaver.Base.RequestNumber,b=function(b){function c(a){d.store(a)}var d=this;d.type="campaigns",d.primary_key("campaign_key"),d.numbers=[],d.request_number=function(b,c,e){"function"==typeof b&&(e=c,c=b,b={}),d.set("number_matching_tags",b),new a(d.get("campaign_key","number_matching_tags")).perform(function(a){if("undefined"!=typeof a&&"undefined"!=typeof a.number&&""!==a.number){var b=new Retreaver.Number(a.number);c.apply(d,[b])}else"function"==typeof e&&e.apply(d,[a])})},d.numbers=function(){var a=[];if("undefined"!=typeof Retreaver.Base.Data._store){var b=Retreaver.Base.Data._store.numbers;if("undefined"!=typeof b)for(var c in b){var e=b[c];d.get("campaign_key")==e.campaign_key&&a.push(new Retreaver.Number(e))}}return a},d.set_number_matching_tags=function(a){if("string"==typeof a&&(a=Retreaver.Number.extract_tags_from_string(a)),!a||"object"!=typeof a||a instanceof Array)throw"ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";return a},c(b)};b.prototype=new Retreaver.Base.Model,Retreaver.Campaign=b}(),function(a){a.Callpixels=window.Retreaver}(window);
1
+ /*! retreaver 27-10-2016 */
2
+ !function(a){var b={configure:function(a){var c={addr:a.host,http_prefix:"http",urlregex:"/\\/\\/[^\\/]*\\/(.*)/"};"undefined"!=typeof a.prefix&&(c.http_prefix=a.prefix),window.Retreaver._connection=new b.Base.Request(c)}};a.Retreaver=b}(window),function(){"undefined"==typeof window.Retreaver&&(window.Retreaver={});var a={};a.assert_required_keys=function(){for(var a=Array.prototype.slice.call(arguments),b=a.shift(),c=0;c<a.length;c++){var d=a[c];if("undefined"==typeof b||"undefined"==typeof b[d])throw"ArgumentError: Required keys are not defined: "+a.join(", ")}return b},a.merge=function(b,c){for(var d in c)try{c[d].constructor==Object?b[d]=a.merge(b[d],c[d]):b[d]=c[d]}catch(e){b[d]=c[d]}return b},a.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.ieVersion=function(){return null==a._ieVersion&&(a._ieVersion=function(){for(var a=3,b=document.createElement("div"),c=b.getElementsByTagName("i");b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->",c[0];);return a>4?a:!1}()),6!=a._ieVersion&&7!=a._ieVersion||null==Retreaver.easyxdm_loaded&&(Retreaver.easyxdm_loaded=!1),a._ieVersion},Retreaver.Base=a}(),function(a){var b=function(a,c,d){return 1===arguments.length?b.get(a):b.set(a,c,d)};b._document=document,b._navigator=navigator,b.defaults={path:"/"},b.get=function(a){return b._cachedDocumentCookie!==b._document.cookie&&b._renewCache(),b._cache[a]},b.set=function(a,c,d){return d=b._getExtendedOptions(d),b._document.cookie=b._generateCookieString(a,c,d),b},b._getExtendedOptions=function(c){return{path:c&&c.path||b.defaults.path,domain:c&&c.domain||b.defaults.domain,secure:c&&c.secure!==a?c.secure:b.defaults.secure}},b._isValidDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a.getTime())},b._generateCookieString=function(a,b,c){return a=encodeURIComponent(a),b=(b+"").replace(/[^!#$&-+\--:<-\[\]-~]/g,encodeURIComponent),c=c||{},a=a+"="+b+(c.path?";path="+c.path:""),a+=c.domain?";domain="+c.domain:"",a+=c.secure?";secure":""},b._getCookieObjectFromString=function(c){var d={};c=c?c.split("; "):[];for(var e=0;e<c.length;e++){var f=b._getKeyValuePairFromCookieString(c[e]);d[f.key]===a&&(d[f.key]=f.value)}return d},b._getKeyValuePairFromCookieString=function(a){var b=a.indexOf("="),b=0>b?a.length:b;return{key:decodeURIComponent(a.substr(0,b)),value:decodeURIComponent(a.substr(b+1))}},b._renewCache=function(){b._cache=b._getCookieObjectFromString(b._document.cookie),b._cachedDocumentCookie=b._document.cookie},b._areEnabled=function(){return b._navigator.cookieEnabled||"1"===b.set("cookies.js",1).get("cookies.js")},b.enabled=b._areEnabled(),"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=b),exports.Cookies=b):b,Retreaver.Base.Cookies=b}(),function(){var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};Base64.encode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=Base64._utf8_encode(a);j<a.length;)b=a.charCodeAt(j++),c=a.charCodeAt(j++),d=a.charCodeAt(j++),e=b>>2,f=(3&b)<<4|c>>4,g=(15&c)<<2|d>>6,h=63&d,isNaN(c)?g=h=64:isNaN(d)&&(h=64),i=i+Base64._keyStr.charAt(e)+Base64._keyStr.charAt(f)+Base64._keyStr.charAt(g)+Base64._keyStr.charAt(h);return i},Base64.decode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");j<a.length;)e=Base64._keyStr.indexOf(a.charAt(j++)),f=Base64._keyStr.indexOf(a.charAt(j++)),g=Base64._keyStr.indexOf(a.charAt(j++)),h=Base64._keyStr.indexOf(a.charAt(j++)),b=e<<2|f>>4,c=(15&f)<<4|g>>2,d=(3&g)<<6|h,i+=String.fromCharCode(b),64!=g&&(i+=String.fromCharCode(c)),64!=h&&(i+=String.fromCharCode(d));return i=Base64._utf8_decode(i)},Base64._utf8_encode=function(string){string=string.replace(eval("/\\r\\n/g"),eval("String('\\n')"));for(var utftext="",n=0;n<string.length;n++){var c=string.charCodeAt(n);128>c?utftext+=String.fromCharCode(c):c>127&&2048>c?(utftext+=String.fromCharCode(c>>6|192),utftext+=String.fromCharCode(63&c|128)):(utftext+=String.fromCharCode(c>>12|224),utftext+=String.fromCharCode(c>>6&63|128),utftext+=String.fromCharCode(63&c|128))}return utftext},Base64._utf8_decode=function(a){for(var b="",c=0,d=c1=c2=0;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):d>191&&224>d?(c2=a.charCodeAt(c+1),b+=String.fromCharCode((31&d)<<6|63&c2),c+=2):(c2=a.charCodeAt(c+1),c3=a.charCodeAt(c+2),b+=String.fromCharCode((15&d)<<12|(63&c2)<<6|63&c3),c+=3);return b},Retreaver.Base.Base64=Base64}(),function(){var a=Retreaver.Base,b=function(b){function c(){a.assert_required_keys(b,"type","primary_key"),"undefined"==typeof Retreaver.Base.Data._store[b.type]&&(Retreaver.Base.Data._store[b.type]={}),"undefined"==typeof Retreaver.Base.Data._store[b.type][b.primary_key]&&(Retreaver.Base.Data._store[b.type][b.primary_key]={})}var d=this;d.get=function(){var a={};if("undefined"==typeof arguments[0])a=Retreaver.Base.Data._store[b.type][b.primary_key];else if(1===arguments.length)a=Retreaver.Base.Data._store[b.type][b.primary_key][arguments[0]];else for(var c=0;c<arguments.length;c++){var d=arguments[c];a[d]=Retreaver.Base.Data._store[b.type][b.primary_key][d]}return a},d.set=function(a,c){return Retreaver.Base.Data._store[b.type][b.primary_key][a]=c,c},d.merge=function(a){for(var c in a)Retreaver.Base.Data._store[b.type][b.primary_key][c]=a[c];return a},c()};b._store={},Retreaver.Base.Data=b}(),function(){var a=Retreaver.Base,b=Retreaver.Base.Data,c=function(){this.api_host_uri="/api/v1/",this.type="model",this.primary_key=function(a){return c.primary_key(this.type,a)},this.store=function(a){if("undefined"!=typeof a){var b=this.primary_key();if("undefined"==typeof a[b])throw"ArgumentError: Expected to receive primary_key "+b;"undefined"==typeof this._store&&(this._store=new Retreaver.Base.Data({type:this.type,primary_key:a[b]})),this._store.merge(a),c.update_visitor_id(a)}return this._store},this.get_data=function(a,b){return this.connection().getJSON(this.api_host_uri+a,null,[c.update,b],this)},this.post_data=function(a,b,d){return this.connection().postJSON(this.api_host_uri+a,b,[c.update,d],this)},this.set=function(){return"function"==typeof this["set_"+arguments[0]]&&(arguments[1]=this["set_"+arguments[0]].apply(this,[arguments[1]])),this._store.set.apply(this,arguments)},this.get=function(){return this._store.get.apply(this,arguments)},this.connection=function(){return Retreaver.Base.Request.connection()}};c.inflections={number:"numbers",campaign:"campaigns"},c.update=function(d){for(var e in d){var f=e,g=d[e];if("undefined"!=typeof c.inflections[e]&&(f=c.inflections[e]),"undefined"!=typeof b._store[f])if(a.isArray(g))for(var h=0;h<g.length;h++)c.update_record(f,g[h]);else c.update_record(f,g[h])}return d},c.update_record=function(a,b){if(c.update_visitor_id(b),"undefined"!=typeof b.id){var d=c.primary_key(a);for(var e in b)Retreaver.Base.Data._store[a][b[d]][e]=b[e];return!0}return!1},c.update_visitor_id=function(a){"undefined"!=typeof a&&"undefined"!=typeof a.visitor_id&&Retreaver.Base.Cookies.set("CallPixels-vid",a.visitor_id)},c.primary_key=function(a,b){return"undefined"==typeof c.primary_keys&&(c.primary_keys={}),"undefined"==typeof c.primary_keys[a]&&(c.primary_keys[a]="id"),"undefined"!=typeof b&&(c.primary_keys[a]=b),c.primary_keys[a]},Retreaver.Base.Model=c}(),function(){var Base=window.Retreaver.Base,Cookies=window.Retreaver.Base.Cookies,Request=function(options){function initialize(a){config=Base.assert_required_keys(a,"http_prefix","addr","urlregex")}function with_ie_scripts(a){Retreaver.easyxdm_loaded?a():self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/easyXDM.min.js",function(){self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/json2.js",function(){Retreaver.easyxdm_loaded=!0,a()})})}var self=this,config={};self.getJSON=function(a,b,c,d){"function"==typeof c&&(c=[c]),"undefined"==typeof d&&(d=self);var e=function(){self.apiRequest(a,function(a){response=JSON.parse(a);for(var b in c)"function"==typeof c[b]&&c[b].apply(d,[response])},b)};6==Base.ieVersion()||7==Base.ieVersion()?with_ie_scripts(e):e()},self.postJSON=function(){return self.getJSON.apply(this,arguments)},self.apiRequest=function(request_uri,callbackFunctions,payload){function ignored(){}function runCallbacks(a){for(var b in callbackFunctions)"function"==typeof callbackFunctions[b]&&callbackFunctions[b](a)}function forwardResponse(){runCallbacks(xdr.responseText)}function sendXdm(){var remote=http_prefix+"://"+addr+"/ie_provider",swf=http_prefix+"://"+addr+"/easyxdm.swf",rpc=eval('new window.easyXDM.Rpc({ remote: "'+remote+'", swf: "'+swf+'"},{remote: {request: {}}});');rpc.request({url:"/"+request_url.match(urlregex)[1],method:"POST",data:payload},function(a){runCallbacks(a.data)})}var http_prefix=config.http_prefix,addr=config.addr,urlregex=eval(config.urlregex),request_url=http_prefix+"://"+addr+request_uri;if(payload&&"undefined"!=typeof Cookies.get("CallPixels-vid")&&"null"!==Cookies.get("CallPixels-vid")&&(payload.visitor_id=Cookies.get("CallPixels-vid")),"function"==typeof callbackFunctions&&(callbackFunctions=[callbackFunctions]),window.XDomainRequest){var xdr=new XDomainRequest;xdr.onload=forwardResponse,xdr.onprogress=ignored,xdr.onerror=ignored,xdr.ontimeout=ignored,xdr.timeout=3e4,payload?(xdr.open("post",request_url),xdr.send(self.buildPost(payload))):(xdr.open("get",request_url),xdr.send())}else if(6==Base.ieVersion()||7==Base.ieVersion())with_ie_scripts(sendXdm);else{var request=new XMLHttpRequest;payload?(request.open("POST",request_url,!1),request.setRequestHeader("Content-Type","application/json"),request.send(JSON.stringify(payload))):(request.open("GET",request_url,!1),request.send()),runCallbacks(request.responseText)}},self.buildPost=function(a){var b="";for(var c in a)b+=c+"="+a[c]+"&";return b},self.loadScript=function(a,b){var c=document.getElementsByTagName("script")[0],d=document.createElement("script");d.type="text/javascript",d.async=!1,d.src=a;var e=function(a,b){"loaded"==a.readyState||"complete"==a.readyState?b():setTimeout(function(){e(a,b)},100)};"function"==typeof b&&("undefined"!=typeof d.addEventListener?d.addEventListener("load",b,!1):d.onreadystatechange=function(){d.onreadystatechange=null,e(d,b)}),c.parentNode.insertBefore(d,c)},initialize(options),self.config=config};Request.connection=function(){if("undefined"==typeof window.Retreaver._connection){var a=window.location.protocol.replace(":","");window.Retreaver._connection=new Retreaver.Base.Request({addr:"api.rtvrapi.com",http_prefix:a,urlregex:"/\\/\\/[^\\/]*\\/(.*)/"})}return window.Retreaver._connection},Retreaver.Base.Request=Request}(),function(){function tags_to_script_tags(a){var b="";for(var c in a){var d=a[c];b=b+"&"+c+"="+d}return b}var Base=Retreaver.Base,Cookies=Retreaver.Base.Cookies,Base64=Retreaver.Base.Base64,Request=Retreaver.Base.Request,RequestNumber=function(options){function initialize(a){config=Base.assert_required_keys(a,"campaign_key")}function getParts(a){for(var b={},c=0;c<a.length;c++){var d=getUrlParts(a[c]);for(var e in d)b[e]=d[e]}return b}function getUrlParts(url){var objURL=new Object;try{url=url.match(eval("/\\?(.*)/"))[0]}catch(e){return objURL}return url.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"),function(a,b,c,d){objURL[b.toLowerCase()]=d}),objURL}function getGACookies(){var a=["__utma","__utmb","__utmc","__utmz","__utmv"],b=new Object;for(var c in a){var d=extractCookie(a[c]);if(!(d||c>0))break;d&&(b[a[c]]=d)}return b}function extractCookie(a){var b=new RegExp(a+"=([^;]*)","g");try{return b.exec(document.cookie)[1]}catch(c){return!1}}function findOne(a,b){for(var c in b)for(var d in a)if(d==b[c])return a[d];return!1}var self=this,config={},resource_url="/api/v1/numbers?";self.perform=function(callback){function sendGARequest(a,b){body.ga=Base64.encode(a),body.c=Base64.encode(JSON.stringify(b)),Request.connection().getJSON(request_url,body,callback)}if("function"!=typeof callback)throw"ArgumentError: Expected to receive a callback function";var request_url=resource_url+"&campaign_key="+config.campaign_key;config.default_number_replacement&&(request_url=request_url+"&default_number="+config.default_number_replacement),config.message_replacement&&(request_url=request_url+"&message="+config.message_replacement);var body=new Object,uri=document.location.href;body.u=Base64.encode(uri),body.st=Base64.encode(tags_to_script_tags(config.number_matching_tags));var ou=Cookies.get("CallPixels-ou");getParts([document.location.href]).cpreset||!ou?Cookies.set("CallPixels-ou",body.u):body.ou=ou;var ga_acct="FAILED";try{_gaq.push(function(){ga_acct=eval("_gat._getTrackerByName()._getAccount()"),sendGARequest(ga_acct,getGACookies())})}catch(e){try{ga(function(tracker){if(tracker&&tracker.get)try{var clientId=tracker.get("clientId"),allTrackers=eval("ga.getAll()");ga_acct=allTrackers[0].get("trackingId");var ga_cookies={};ga_cookies.__utma=clientId,ga_cookies.mp="yes",sendGARequest(ga_acct,ga_cookies)}catch(g){sendGARequest("",{})}else sendGARequest("",{})})}catch(f){Request.connection().getJSON(request_url,body,callback)}}},initialize(options)};Retreaver.Base.RequestNumber=RequestNumber}(),window.Retreaver.Cache={},function(){function a(b){if("undefined"!=typeof Retreaver.Base.Data._store){var c=Retreaver.Base.Data._store.numbers;if("undefined"!=typeof c){var d={};for(var e in c){var f=c[e];"true"===f.is_active&&("undefined"==typeof d[f.campaign_key]&&(d[f.campaign_key]=[],d[f.campaign_key].ids=[],d[f.campaign_key].hashes=[]),d[f.campaign_key].ids.push(f.id),d[f.campaign_key].hashes.push(f.id_checksum))}for(var g in d){var h={ids:d[g].ids,hashes:d[g].hashes};Retreaver.Base.Request.connection().postJSON("/api/v1/numbers/ping",h,[Retreaver.Base.Model.update,b],this)}}}setTimeout(a,15e3)}var b=Retreaver.Base;Retreaver.Number=function(a){function c(a){g.store(a),g.set("is_active","true")}function d(a){return"string"==typeof a&&(a=Retreaver.Number.extract_tags_from_string(a)),{tag_values:a,ids:[e("id")],campaign_key:e("campaign_key")}}function e(a){return g.get(a)}function f(){if(g.get("is_per_visitor")===!1)throw"Error: Tried to add tags to non per-visitor number."}var g=this;g.type="numbers",g.add_tags=function(a,b){f(),g.post_data("numbers/tag",d(a),b)},g.remove_tags=function(a,b){f(),g.post_data("numbers/untag",d(a),b)},g.remove_tags_by_keys=function(a,b){f(),"string"==typeof a&&(a=a.split(","));var c={tag_keys:a,ids:[e("id")],campaign_key:e("campaign_key")};g.post_data("numbers/untag/keys",c,b)},g.clear_tags=function(a){f();var b={ids:[e("id")],campaign_key:e("campaign_key"),all:"true"};g.post_data("numbers/untag",b,a)},g.release=function(){g.set("is_active","false")},g.initiate_call=function(a,c,d){"undefined"==typeof c&&(c={}),c.dial=a,c=b.merge(g.get("id","campaign_key"),c),g.post_data("numbers/initiate_call",c,d)},c(a)},Retreaver.Number.extract_tags_from_string=function(a){for(var b={},a=a.split(","),c=0;c<a.length;c++){var d=a[c].split(":");b[d[0]]=d[1]}return b},Retreaver.Number.prototype=new Retreaver.Base.Model,a()}(),function(){var a=Retreaver.Base.RequestNumber,b=function(b){function c(a){e.store(a)}function d(a){for(i=0;i<a.length;i++){rn=a[i],Retreaver.Vendor.findAndReplaceDOMText(document.getElementsByTagName("body")[0],{find:rn.find,replace:rn.replace_with});var b=document.getElementsByTagName("a");for(j=0;j<b.length;j++)link=b[j],href=link.getAttribute("href"),match=href.match(/tel:(.*)/),match&&match[1]===rn.find&&link.setAttribute("href","tel:"+rn.replace_with)}}var e=this;e.type="campaigns",e.primary_key("campaign_key"),e.numbers=[],e.request_number=function(b,c,f){"function"==typeof b&&(f=c,c=b,b={}),e.set("number_matching_tags",b),new a(e.get("campaign_key","number_matching_tags")).perform(function(a){if("undefined"!=typeof a&&"undefined"!=typeof a.number&&""!==a.number){var b=new Retreaver.Number(a.number);"undefined"!=typeof a.number.replacement_numbers&&d(a.number.replacement_numbers),c.apply(e,[b])}else"function"==typeof f&&f.apply(e,[a])})},e.auto_replace_numbers=function(a,b){"undefined"==typeof a&&(a=function(){}),"undefined"==typeof b&&(b=function(){}),e.request_number({},a,b)},e.numbers=function(){var a=[];if("undefined"!=typeof Retreaver.Base.Data._store){var b=Retreaver.Base.Data._store.numbers;if("undefined"!=typeof b)for(var c in b){var d=b[c];e.get("campaign_key")==d.campaign_key&&a.push(new Retreaver.Number(d))}}return a},e.set_number_matching_tags=function(a){if("string"==typeof a&&(a=Retreaver.Number.extract_tags_from_string(a)),!a||"object"!=typeof a||a instanceof Array)throw"ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";return a},c(b)};b.prototype=new Retreaver.Base.Model,Retreaver.Campaign=b}(),function(a){a.Callpixels=window.Retreaver}(window);
@@ -224,6 +224,156 @@
224
224
 
225
225
  <dl>
226
226
 
227
+ <dt>
228
+ <h4 class="name" id="auto_replace_number"><span class="type-signature"></span>auto_replace_number<span class="signature">(callback, error_callback)</span><span class="type-signature"></span></h4>
229
+
230
+
231
+ </dt>
232
+ <dd>
233
+
234
+
235
+ <div class="description">
236
+ Auto replace all numbers on page according to campaign settings
237
+ Calls campaign.request_number
238
+ </div>
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+ <h5>Parameters:</h5>
247
+
248
+
249
+ <table class="params">
250
+ <thead>
251
+ <tr>
252
+
253
+ <th>Name</th>
254
+
255
+
256
+ <th>Type</th>
257
+
258
+
259
+
260
+
261
+
262
+ <th class="last">Description</th>
263
+ </tr>
264
+ </thead>
265
+
266
+ <tbody>
267
+
268
+
269
+ <tr>
270
+
271
+ <td class="name"><code>callback</code></td>
272
+
273
+
274
+ <td class="type">
275
+
276
+
277
+ <span class="param-type"><a href="global.html#getNumberCallback">getNumberCallback</a></span>
278
+
279
+
280
+
281
+ </td>
282
+
283
+
284
+
285
+
286
+
287
+ <td class="description last">Callback fired if the request completes successfully.</td>
288
+ </tr>
289
+
290
+
291
+
292
+ <tr>
293
+
294
+ <td class="name"><code>error_callback</code></td>
295
+
296
+
297
+ <td class="type">
298
+
299
+
300
+ <span class="param-type">function</span>
301
+
302
+
303
+
304
+ </td>
305
+
306
+
307
+
308
+
309
+
310
+ <td class="description last">Callback fired if the request raises an error.</td>
311
+ </tr>
312
+
313
+
314
+ </tbody>
315
+ </table>
316
+
317
+
318
+
319
+ <dl class="details">
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+ <dt class="tag-source">Source:</dt>
340
+ <dd class="tag-source"><ul class="dummy"><li>
341
+ <a href="campaign.js.html">retreaver/campaign.js</a>, <a href="campaign.js.html#line95">line 95</a>
342
+ </li></ul></dd>
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+ </dl>
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+ <h5>Example</h5>
365
+
366
+ <pre class="prettyprint"><code>campaign.auto_replace_number({calling_about: 'support'}, function (number) {
367
+ alert(number.get('number'))
368
+ }, function(response){
369
+ alert('something went wrong: ' + response);
370
+ };</code></pre>
371
+
372
+
373
+ </dd>
374
+
375
+
376
+
227
377
  <dt>
228
378
  <h4 class="name" id="request_number"><span class="type-signature"></span>request_number<span class="signature">(tags, callback, error_callback)</span><span class="type-signature"></span></h4>
229
379
 
@@ -360,7 +510,7 @@
360
510
 
361
511
  <dt class="tag-source">Source:</dt>
362
512
  <dd class="tag-source"><ul class="dummy"><li>
363
- <a href="campaign.js.html">retreaver/campaign.js</a>, <a href="campaign.js.html#line24">line 24</a>
513
+ <a href="campaign.js.html">retreaver/campaign.js</a>, <a href="campaign.js.html#line45">line 45</a>
364
514
  </li></ul></dd>
365
515
 
366
516
 
@@ -416,7 +566,7 @@
416
566
  <br clear="both">
417
567
 
418
568
  <footer>
419
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
569
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
420
570
  </footer>
421
571
 
422
572
  <script> prettyPrint(); </script>
@@ -1452,7 +1452,7 @@ with per-visitor numbers enabled.
1452
1452
  <br clear="both">
1453
1453
 
1454
1454
  <footer>
1455
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
1455
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
1456
1456
  </footer>
1457
1457
 
1458
1458
  <script> prettyPrint(); </script>
@@ -318,7 +318,7 @@
318
318
  <br clear="both">
319
319
 
320
320
  <footer>
321
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
321
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
322
322
  </footer>
323
323
 
324
324
  <script> prettyPrint(); </script>
@@ -43,6 +43,27 @@
43
43
  self.store(data);
44
44
  }
45
45
 
46
+ function find_and_replace_number(replacement_numbers) {
47
+ for (i = 0; i &lt; replacement_numbers.length; i++) {
48
+ rn = replacement_numbers[i];
49
+
50
+ Retreaver.Vendor.findAndReplaceDOMText(document.getElementsByTagName('body')[0], {
51
+ find: rn['find'],
52
+ replace: rn['replace_with']
53
+ });
54
+
55
+ var links = document.getElementsByTagName('a');
56
+ for (j = 0; j &lt; links.length; j++) {
57
+ link = links[j];
58
+ href = link.getAttribute('href');
59
+ match = href.match(/tel:(.*)/);
60
+ if (match && match[1] === rn['find']) {
61
+ link.setAttribute('href', 'tel:' + rn['replace_with']);
62
+ }
63
+ }
64
+ }
65
+ }
66
+
46
67
  var self = this;
47
68
  self.type = 'campaigns';
48
69
  self.primary_key('campaign_key');
@@ -82,6 +103,12 @@
82
103
  if (typeof(data) !== 'undefined' && typeof(data.number) !== 'undefined' && data.number !== '') {
83
104
  // initialize number
84
105
  var number = new Retreaver.Number(data.number);
106
+
107
+ // if there is a replacement in the response, replace all occurances
108
+ // of that number on the page with the retreaver number
109
+ if (typeof(data.number.replacement_numbers) !== 'undefined') {
110
+ find_and_replace_number(data.number.replacement_numbers);
111
+ }
85
112
  // call callback
86
113
  callback.apply(self, [number]);
87
114
  }
@@ -91,6 +118,35 @@
91
118
  }
92
119
  });
93
120
  };
121
+
122
+ /**
123
+ * Auto replace all numbers on page according to campaign settings
124
+ * Calls campaign.request_number
125
+ * @memberOf Retreaver.Campaign
126
+ * @function auto_replace_number
127
+ * @instance
128
+ * @param {getNumberCallback} callback - Callback fired if the request completes successfully.
129
+ * @param {Function} error_callback - Callback fired if the request raises an error.
130
+ * @example
131
+ * campaign.auto_replace_number({calling_about: 'support'}, function (number) {
132
+ * alert(number.get('number'))
133
+ * }, function(response){
134
+ * alert('something went wrong: ' + response);
135
+ * };
136
+ */
137
+ self.auto_replace_numbers = function (callback, error_callback) {
138
+ if (typeof callback === 'undefined') {
139
+ callback = function () {
140
+ };
141
+ }
142
+
143
+ if (typeof error_callback === 'undefined') {
144
+ error_callback = function () {
145
+ };
146
+ }
147
+ self.request_number({}, callback, error_callback);
148
+ };
149
+
94
150
  /**
95
151
  * Retreaver.Campaign#request_number callback fired after the request completes.
96
152
  * @callback getNumberCallback
@@ -122,8 +178,7 @@
122
178
  }
123
179
  if (tags && (typeof tags === "object") && !(tags instanceof Array)) {
124
180
  return tags
125
- }
126
- else {
181
+ } else {
127
182
  throw "ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";
128
183
  }
129
184
  };
@@ -132,7 +187,8 @@
132
187
  };
133
188
  Campaign.prototype = new Retreaver.Base.Model();
134
189
  Retreaver.Campaign = Campaign;
135
- })();</code></pre>
190
+ })();
191
+ </code></pre>
136
192
  </article>
137
193
  </section>
138
194
 
@@ -148,7 +204,7 @@
148
204
  <br clear="both">
149
205
 
150
206
  <footer>
151
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
207
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
152
208
  </footer>
153
209
 
154
210
  <script> prettyPrint(); </script>
@@ -178,7 +178,7 @@
178
178
 
179
179
  <dt class="tag-source">Source:</dt>
180
180
  <dd class="tag-source"><ul class="dummy"><li>
181
- <a href="campaign.js.html">retreaver/campaign.js</a>, <a href="campaign.js.html#line67">line 67</a>
181
+ <a href="campaign.js.html">retreaver/campaign.js</a>, <a href="campaign.js.html#line123">line 123</a>
182
182
  </li></ul></dd>
183
183
 
184
184
 
@@ -223,7 +223,7 @@
223
223
  <br clear="both">
224
224
 
225
225
  <footer>
226
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
226
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
227
227
  </footer>
228
228
 
229
229
  <script> prettyPrint(); </script>
@@ -58,7 +58,7 @@
58
58
  <br clear="both">
59
59
 
60
60
  <footer>
61
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
61
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
62
62
  </footer>
63
63
 
64
64
  <script> prettyPrint(); </script>
@@ -249,7 +249,7 @@
249
249
  <br clear="both">
250
250
 
251
251
  <footer>
252
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
252
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
253
253
  </footer>
254
254
 
255
255
  <script> prettyPrint(); </script>
@@ -74,7 +74,7 @@
74
74
  <br clear="both">
75
75
 
76
76
  <footer>
77
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu May 26 2016 00:13:23 GMT-0400 (EDT)
77
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Oct 27 2016 21:43:00 GMT-0400 (EDT)
78
78
  </footer>
79
79
 
80
80
  <script> prettyPrint(); </script>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retreaverjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-26 00:00:00.000000000 Z
12
+ date: 2016-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties