<commit_before>/*!
 *  opentok-whiteboard (http://github.com/aullman/opentok-whiteboard)
 *  
 *  Shared Whiteboard that works with OpenTok
 *
 *  @Author: <NAME> (http://github.com/aullman)
 *  @Copyright (c) 2014 <NAME>
 *  @License: Released under the MIT license (http://opensource.org/licenses/MIT)
**/

var OpenTokWhiteboard = angular.module('opentok-whiteboard', ['opentok'])
.directive('otWhiteboard', ['OTSession', '$window', function (OTSession, $window) {
    return {
        restrict: 'E',
        template: '<canvas></canvas>' + 

            '<div class="OT_panel">' +

            '<input type="button" ng-class="{OT_color: true, OT_selected: c[\'background-color\'] === color}" ' +
            'ng-repeat="c in colors" ng-style="c" ng-click="changeColor(c)">' +
            '</input>' +

            '<input type="button" ng-click="erase()" ng-class="{OT_erase: true, OT_selected: erasing}"' +
            ' value="Eraser"></input>' +
            
            '<input type="button" ng-click="capture()" class="OT_capture" value="{{captureText}}"></input>' +

            '<input type="button" ng-click="undo()" class="OT_capture" value="Undo"></input>' +

            '<input type="button" ng-click="redo()" class="OT_capture" value="Redo"></input>' +

            '<input type="button" ng-click="clear()" class="OT_clear" value="Clear"></input>',

        link: function (scope, element, attrs) {
            var canvas = element.context.querySelector("canvas"),
                select = element.context.querySelector("select"),
                input = element.context.querySelector("input"),
                client = {dragging:false},
                ctx,
                start = 0, //Grabs the end position of each stroke
                count = 0, //Grabs the total count of each continuous stroke
                undoStack = [], //Stores the value of start and count for each continuous stroke
                redoStack = [], //When undo pops, data is sent to redoStack
                drawHistory = [],
                drawHistoryReceivedFrom,
                drawHistoryReceived,
                batchUpdates = [],
                iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
                

            // Create an empty project and a view for the canvas:
            paper.setup(canvas);

            scope.colors = [{'background-color': 'black'},
                            {'background-color': 'blue'},
                            {'background-color': 'red'},
                            {'background-color': 'green'},
                            {'background-color': 'orange'},
                            {'background-color': 'purple'},
                            {'background-color': 'brown'}];
            scope.captureText = iOS ? 'Email' : 'Capture';
            
            scope.strokeCap = 'round';
            scope.strokeJoin = 'round';

            canvas.width = attrs.width || element.width();
            canvas.height = attrs.height || element.height();
            
            if (!ctx) {
              ctx = canvas.getContext("2d");
            }
            
            var clearCanvas = function () {
	            	paper.project.clear();
	            	paper.view.update();
            };

            var clearStack = function () {
                drawHistory = [];
                undoStack = [];
                redoStack = [];
                start = 0;
                count = 0;
            }
            
            scope.changeColor = function (color) {
                scope.color = color['background-color'];
                scope.lineWidth = 2;
                scope.erasing = false;
            };
            
            scope.changeColor(scope.colors[Math.floor(Math.random() * scope.colors.length)]);
            
            scope.clear = function () {
                clearCanvas();
                if (OTSession.session) {
                    OTSession.session.signal({
                        type: 'otWhiteboard_clear'
                    });
                }
            };
            
            scope.erase = function () {
                //scope.color = element.css("background-color") || "#fff";
                scope.lineWidth = 50;
                scope.erasing = true;
            };
            
            scope.capture = function () {
                if (iOS) {
                    // On iOS you can put HTML in a mailto: link
                    window.location.href = "mailto:?subject=Whiteboard&Body=<img src='" + canvas.toDataURL('image/png') + "'>";
                } else {
                    // We just open the image in a new window
                    window.open(canvas.toDataURL('image/png'));
                }
            };

            scope.undo = function () {
                if (!undoStack.length)
                    return;
                var undodata = undoStack.pop();
                undoWhiteBoard(undodata);
                redoStack.push(undodata);
                sendUpdate('otWhiteboard_undo', undodata);
            };

            var undoWhiteBoard = function (data) {
	            data.visible = false;
	            paper.view.update();
            };

            scope.redo = function () {
                if (!redoStack.length)
                    return;
                var redodata = redoStack.pop();
                redoWhiteBoard(redodata);
                undoStack.push(redodata);
                sendUpdate('otWhiteboard_redo', redodata);
            };

            var redoWhiteBoard = function (data) {
                data.visible = true;
                paper.view.update();
            };

            var draw = function (update) {
                window.path.add(update.toX, update.toY);
                drawHistory.push(update);
            };
            
            var drawUpdates = function (updates) {
                updates.forEach(function (update) {
                    draw(update);
                    drawHistory.push(update);
                });
            };
            
            var batchSignal = function (type, data, toConnection) {
                // We send data in small chunks so that they fit in a signal
                // Each packet is maximum ~250 chars, we can fit 8192/250 ~= 32 updates per signal
                var dataCopy = data.slice();
                var signalError = function (err) {<commit_msg>Applies full draw to sendUpdates<commit_after>/*!
 *  opentok-whiteboard (http://github.com/aullman/opentok-whiteboard)
 *  
 *  Shared Whiteboard that works with OpenTok
 *
 *  @Author: <NAME> (http://github.com/aullman)
 *  @Copyright (c) 2014 <NAME>
 *  @License: Released under the MIT license (http://opensource.org/licenses/MIT)
**/

var OpenTokWhiteboard = angular.module('opentok-whiteboard', ['opentok'])
.directive('otWhiteboard', ['OTSession', '$window', function (OTSession, $window) {
    return {
        restrict: 'E',
        template: '<canvas></canvas>' + 

            '<div class="OT_panel">' +

            '<input type="button" ng-class="{OT_color: true, OT_selected: c[\'background-color\'] === color}" ' +
            'ng-repeat="c in colors" ng-style="c" ng-click="changeColor(c)">' +
            '</input>' +

            '<input type="button" ng-click="erase()" ng-class="{OT_erase: true, OT_selected: erasing}"' +
            ' value="Eraser"></input>' +
            
            '<input type="button" ng-click="capture()" class="OT_capture" value="{{captureText}}"></input>' +

            '<input type="button" ng-click="undo()" class="OT_capture" value="Undo"></input>' +

            '<input type="button" ng-click="redo()" class="OT_capture" value="Redo"></input>' +

            '<input type="button" ng-click="clear()" class="OT_clear" value="Clear"></input>',

        link: function (scope, element, attrs) {
            var canvas = element.context.querySelector("canvas"),
                select = element.context.querySelector("select"),
                input = element.context.querySelector("input"),
                client = {dragging:false},
                ctx,
                start = 0, //Grabs the end position of each stroke
                count = 0, //Grabs the total count of each continuous stroke
                undoStack = [], //Stores the value of start and count for each continuous stroke
                redoStack = [], //When undo pops, data is sent to redoStack
                drawHistory = [],
                drawHistoryReceivedFrom,
                drawHistoryReceived,
                batchUpdates = [],
                iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
                

            // Create an empty project and a view for the canvas:
            paper.setup(canvas);

            scope.colors = [{'background-color': 'black'},
                            {'background-color': 'blue'},
                            {'background-color': 'red'},
                            {'background-color': 'green'},
                            {'background-color': 'orange'},
                            {'background-color': 'purple'},
                            {'background-color': 'brown'}];
            scope.captureText = iOS ? 'Email' : 'Capture';
            
            scope.strokeCap = 'round';
            scope.strokeJoin = 'round';

            canvas.width = attrs.width || element.width();
            canvas.height = attrs.height || element.height();
            
            if (!ctx) {
              ctx = canvas.getContext("2d");
            }
            
            var clearCanvas = function () {
	            	paper.project.clear();
	            	paper.view.update();
            };

            var clearStack = function () {
                drawHistory = [];
                undoStack = [];
                redoStack = [];
                start = 0;
                count = 0;
            }
            
            scope.changeColor = function (color) {
                scope.color = color['background-color'];
                scope.lineWidth = 2;
                scope.erasing = false;
            };
            
            scope.changeColor(scope.colors[Math.floor(Math.random() * scope.colors.length)]);
            
            scope.clear = function () {
                clearCanvas();
                if (OTSession.session) {
                    OTSession.session.signal({
                        type: 'otWhiteboard_clear'
                    });
                }
            };
            
            scope.erase = function () {
                //scope.color = element.css("background-color") || "#fff";
                scope.lineWidth = 50;
                scope.erasing = true;
            };
            
            scope.capture = function () {
                if (iOS) {
                    // On iOS you can put HTML in a mailto: link
                    window.location.href = "mailto:?subject=Whiteboard&Body=<img src='" + canvas.toDataURL('image/png') + "'>";
                } else {
                    // We just open the image in a new window
                    window.open(canvas.toDataURL('image/png'));
                }
            };

            scope.undo = function () {
                if (!undoStack.length)
                    return;
                var undodata = undoStack.pop();
                undoWhiteBoard(undodata);
                redoStack.push(undodata);
                sendUpdate('otWhiteboard_undo', undodata);
            };

            var undoWhiteBoard = function (data) {
	            data.visible = false;
	            paper.view.update();
            };

            scope.redo = function () {
                if (!redoStack.length)
                    return;
                var redodata = redoStack.pop();
                redoWhiteBoard(redodata);
                undoStack.push(redodata);
                sendUpdate('otWhiteboard_redo', redodata);
            };

            var redoWhiteBoard = function (data) {
                data.visible = true;
                paper.view.update();
            };

            var draw = function (update, full) {
	            	
	            	typeof( full !== undefined ) ? full : false;
	            	
	            	if( full ) {
		            	// Create a new path object
                  window.path = new paper.Path();

                  // Apply properties
                  path.strokeColor = scope.color;
                  path.strokeWidth = scope.lineWidth;
                  path.strokeCap = scope.strokeCap;
                  path.strokeJoin = scope.strokeJoin;
                  
                  if(mode=="pen"){
                  	path.blendMode = 'destination-out';
                  }

                  // Move to start and draw a line from there
                  start = new paper.Point(update.fromX, update.fromY);
                  path.moveTo(start);
	            	}
	            
                window.path.add(update.toX, update.toY);
                drawHistory.push(update);
                
                if( full ) {
	                 // Apply smoothing.
                    window.path.smooth();
                    
                    // End dragging.
                    client.dragging = false;
                }
            };
            
            var drawUpdates = function (updates) {
                updates.forEach(function (update) {
                    draw(update, true);
                    drawHistory.push(update);
                });
            };
            
            var batchSignal = function (type, data, toConnection) {
                // We send data in small chunks so that they fit in a signal
                // Each packet is maximum ~250 chars, we can fit 8192/250 ~= 32 updates per signal
                var dataCopy = data.slice();
                var signalError = function (err) {
{'fraction_non_alphanumeric': 0.12405337179949513, 'fraction_numerical': 0.0034619545618463756, 'mean_word_length': 1.3249496981891349, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2059193', 'n_tokens_mistral': 3614, 'n_tokens_neox': 3370, 'n_words': 761}