0
|
1 //>>excludeStart("exclude", pragmas.exclude);
|
|
2 define([ "shoestring" ], function(){
|
|
3 //>>excludeEnd("exclude");
|
|
4
|
|
5 (function() {
|
|
6 shoestring.trackedMethodsKey = "shoestringMethods";
|
|
7
|
|
8 // simple check for localStorage from Modernizr - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js
|
|
9 function supportsStorage() {
|
|
10 var mod = "modernizr";
|
|
11 try {
|
|
12 localStorage.setItem(mod, mod);
|
|
13 localStorage.removeItem(mod);
|
|
14 return true;
|
|
15 } catch(e) {
|
|
16 return false;
|
|
17 }
|
|
18 }
|
|
19
|
|
20 // return a new function closed over the old implementation
|
|
21 function recordProxy( old, name ) {
|
|
22 return function() {
|
|
23 var tracked;
|
|
24 try {
|
|
25 tracked = JSON.parse(win.localStorage.getItem( shoestring.trackedMethodsKey ) || "{}");
|
|
26 } catch (e) {
|
|
27 if( e instanceof SyntaxError) {
|
|
28 tracked = {};
|
|
29 }
|
|
30 }
|
|
31
|
|
32 tracked[ name ] = true;
|
|
33 win.localStorage.setItem( shoestring.trackedMethodsKey, JSON.stringify(tracked) );
|
|
34
|
|
35 return old.apply(this, arguments);
|
|
36 };
|
|
37 }
|
|
38
|
|
39 // proxy each of the methods defined on fn
|
|
40 if( supportsStorage() ){
|
|
41 for( var method in shoestring.fn ){
|
|
42 if( shoestring.fn.hasOwnProperty(method) ) {
|
|
43 shoestring.fn[ method ] = recordProxy(shoestring.fn[ method ], method);
|
|
44 }
|
|
45 }
|
|
46 }
|
|
47 })();
|
|
48
|
|
49 //>>excludeStart("exclude", pragmas.exclude);
|
|
50 });
|
|
51 //>>excludeEnd("exclude");
|