]> _ Git - fluidbook-html5.git/commitdiff
wip #801 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Oct 2016 12:31:34 +0000 (12:31 +0000)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Oct 2016 12:31:34 +0000 (12:31 +0000)
js/libs/cube/util.js
js/libs/fluidbook/fluidbook.stats.js
js/widget.js

index 9d81383577eca85b497c35328f46b96e079aca2a..116a771b5f8cd9f57ac75f666c60f627ef8b896d 100644 (file)
 function ucfirst(str) {
-       str += '';
-       var f = str.charAt(0).toUpperCase();
-       return f + str.substr(1);
+    str += '';
+    var f = str.charAt(0).toUpperCase();
+    return f + str.substr(1);
 }
 
 function arrayRemove(array, element) {
-       var index = array.indexOf(element);
-       if (index == -1) {
-               return;
-       }
-       array.splice(index, 1);
-       return array;
+    var index = array.indexOf(element);
+    if (index == -1) {
+        return;
+    }
+    array.splice(index, 1);
+    return array;
 }
 
 function json_parse(str, info) {
-       try {
-               return JSON.parse(str);
-       } catch (err) {
-               if (info != undefined) {
+    try {
+        return JSON.parse(str);
+    } catch (err) {
+        if (info != undefined) {
 
-               }
-               console.error('Error parsing json :: ' + err + ' :: ' + str);
-       }
+        }
+        console.error('Error parsing json :: ' + err + ' :: ' + str);
+    }
 }
 
 function trim(str, charlist) {
-       // http://kevin.vanzonneveld.net
-       // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
-       // +   improved by: mdsjack (http://www.mdsjack.bo.it)
-       // +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
-       // +      input by: Erkekjetter
-       // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
-       // +      input by: DxGx
-       // +   improved by: Steven Levithan (http://blog.stevenlevithan.com)
-       // +    tweaked by: Jack
-       // +   bugfixed by: Onno Marsman
-       // *     example 1: trim('    Kevin van Zonneveld    ');
-       // *     returns 1: 'Kevin van Zonneveld'
-       // *     example 2: trim('Hello World', 'Hdle');
-       // *     returns 2: 'o Wor'
-       // *     example 3: trim(16, 1);
-       // *     returns 3: 6
-       var whitespace, l = 0,
-                       i = 0;
-       str += '';
+    // http://kevin.vanzonneveld.net
+    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+    // +   improved by: mdsjack (http://www.mdsjack.bo.it)
+    // +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
+    // +      input by: Erkekjetter
+    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+    // +      input by: DxGx
+    // +   improved by: Steven Levithan (http://blog.stevenlevithan.com)
+    // +    tweaked by: Jack
+    // +   bugfixed by: Onno Marsman
+    // *     example 1: trim('    Kevin van Zonneveld    ');
+    // *     returns 1: 'Kevin van Zonneveld'
+    // *     example 2: trim('Hello World', 'Hdle');
+    // *     returns 2: 'o Wor'
+    // *     example 3: trim(16, 1);
+    // *     returns 3: 6
+    var whitespace, l = 0,
+        i = 0;
+    str += '';
 
-       if (!charlist) {
-               // default list
-               whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
-       } else {
-               // preg_quote custom list
-               charlist += '';
-               whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
-       }
+    if (!charlist) {
+        // default list
+        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
+    } else {
+        // preg_quote custom list
+        charlist += '';
+        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
+    }
 
-       l = str.length;
-       for (i = 0; i < l; i++) {
-               if (whitespace.indexOf(str.charAt(i)) === -1) {
-                       str = str.substring(i);
-                       break;
-               }
-       }
+    l = str.length;
+    for (i = 0; i < l; i++) {
+        if (whitespace.indexOf(str.charAt(i)) === -1) {
+            str = str.substring(i);
+            break;
+        }
+    }
 
-       l = str.length;
-       for (i = l - 1; i >= 0; i--) {
-               if (whitespace.indexOf(str.charAt(i)) === -1) {
-                       str = str.substring(0, i + 1);
-                       break;
-               }
-       }
+    l = str.length;
+    for (i = l - 1; i >= 0; i--) {
+        if (whitespace.indexOf(str.charAt(i)) === -1) {
+            str = str.substring(0, i + 1);
+            break;
+        }
+    }
 
-       return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
+    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
 }
 
 
-(function() {
-       var lastTime = 0;
-       var vendors = ['ms', 'moz', 'webkit', 'o'];
-       for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
-               window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
-               window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame']
-                               || window[vendors[x] + 'CancelRequestAnimationFrame'];
-       }
-       if (!window.requestAnimationFrame)
-               window.requestAnimationFrame = function(callback, element) {
-                       var currTime = new Date().getTime();
-                       var timeToCall = Math.max(0, 16 - (currTime - lastTime));
-                       var id = window.setTimeout(function() {
-                               callback(currTime + timeToCall);
-                       },
-                                       timeToCall);
-                       lastTime = currTime + timeToCall;
-                       return id;
-               };
-       if (!window.cancelAnimationFrame)
-               window.cancelAnimationFrame = function(id) {
-                       clearTimeout(id);
-               };
-}());
\ No newline at end of file
+(function () {
+    var lastTime = 0;
+    var vendors = ['ms', 'moz', 'webkit', 'o'];
+    for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+        window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
+        window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame']
+            || window[vendors[x] + 'CancelRequestAnimationFrame'];
+    }
+    if (!window.requestAnimationFrame)
+        window.requestAnimationFrame = function (callback, element) {
+            var currTime = new Date().getTime();
+            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
+            var id = window.setTimeout(function () {
+                    callback(currTime + timeToCall);
+                },
+                timeToCall);
+            lastTime = currTime + timeToCall;
+            return id;
+        };
+    if (!window.cancelAnimationFrame)
+        window.cancelAnimationFrame = function (id) {
+            clearTimeout(id);
+        };
+}());
+
+function guid() {
+    function s4() {
+        return Math.floor((1 + Math.random()) * 0x10000)
+            .toString(16)
+            .substring(1);
+    }
+
+    return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
+        s4() + '-' + s4() + s4() + s4();
+}
\ No newline at end of file
index 546520c63ccd58abe47332668d11628f2609ebc9..497341527b6ab1a422296114b74116353e7eaa22 100644 (file)
@@ -1,66 +1,68 @@
 function FluidbookStats(fluidbook) {\r
-       this.fluidbook = fluidbook;\r
-       this.id = this.fluidbook.datas.id;\r
-       this.init();\r
+    this.fluidbook = fluidbook;\r
+    this.id = this.fluidbook.datas.id;\r
+    this.vid = guid();\r
+    this.init();\r
 }\r
 \r
 FluidbookStats.prototype = {\r
-       init: function() {\r
-               var $this = this;\r
-               $(document).on('click', 'a[data-track]', function() {\r
-                       $this.track(6, 0, $(this).attr('data-track'));\r
-                       return true;\r
-               });\r
-       },\r
-       trackPageChange: function() {\r
-               if (!this.fluidbook.support.hasNetwork()) {\r
-                       return;\r
-               }\r
-               try {\r
-                       if (_gaq == undefined) {\r
-                               return;\r
-                       }\r
-                       var page = location.pathname + location.search + location.hash;\r
-                       if (_gatrackers != undefined) {\r
-                               $.each(_gatrackers, function(k, v) {\r
-                                       _gaq.push([v + '._trackPageview', page]);\r
-                               });\r
-                       } else {\r
-                               _gaq.push(['_trackPageview', page]);\r
-                       }\r
-               } catch (err) {\r
+    init: function () {\r
+        var $this = this;\r
+        $(document).on('click', 'a[data-track]', function () {\r
+            $this.track(6, 0, $(this).attr('data-track'));\r
+            return true;\r
+        });\r
+    },\r
+    trackPageChange: function () {\r
+        if (!this.fluidbook.support.hasNetwork()) {\r
+            return;\r
+        }\r
+        try {\r
+            if (_gaq == undefined) {\r
+                return;\r
+            }\r
+            var page = location.pathname + location.search + location.hash;\r
+            if (_gatrackers != undefined) {\r
+                $.each(_gatrackers, function (k, v) {\r
+                    _gaq.push([v + '._trackPageview', page]);\r
+                });\r
+            } else {\r
+                _gaq.push(['_trackPageview', page]);\r
+            }\r
+        } catch (err) {\r
 \r
-               }\r
-       },\r
-       track: function(type, page, extra) {\r
-               if (!this.fluidbook.support.hasNetwork()) {\r
-                       return;\r
-               }\r
+        }\r
+    },\r
+    track: function (type, page, extra) {\r
+        if (!this.fluidbook.support.hasNetwork()) {\r
+            return;\r
+        }\r
 \r
-               if (page == undefined) {\r
-                       page = 0;\r
-               }\r
-               if (extra == undefined) {\r
-                       extra = '';\r
-               }\r
+        if (page == undefined) {\r
+            page = 0;\r
+        }\r
+        if (extra == undefined) {\r
+            extra = '';\r
+        }\r
 \r
-               $.ajax({\r
-                       url: 'https://stats.fluidbook.com/stats2.php',\r
-                       type: 'GET',\r
-                       data: {\r
-                               id: this.id,\r
-                               type: type,\r
-                               page: page,\r
-                               str: extra,\r
-                               time: new Date().getTime()\r
-                       },\r
-                       success: function() {\r
+        $.ajax({\r
+            url: 'https://stats.fluidbook.com/stats2.php',\r
+            type: 'GET',\r
+            data: {\r
+                id: this.id,\r
+                vid: this.vid,\r
+                type: type,\r
+                page: page,\r
+                str: extra,\r
+                time: new Date().getTime()\r
+            },\r
+            success: function () {\r
 \r
-                       },\r
-                       error: function() {\r
+            },\r
+            error: function () {\r
 \r
-                       }\r
-               });\r
-       }\r
+            }\r
+        });\r
+    }\r
 };\r
 \r
index 993353e66f03f98b3f917b1d94af35ada6d1c150..95b97a91f0f603adf8cb928a4a754b13b4e4385c 100644 (file)
@@ -356,4 +356,5 @@ function getColor(color) {
 \r
 function resize() {\r
     widget.resize();\r
-}
\ No newline at end of file
+}\r
+\r