<commit_before>/**

 * ============================================== Marquee Manager =============================================== *

 * Author: Conrad Feyt
 * Email: conrad.feyt@gmail.com
 * Version: 1.5
 * Tested only on modern browsers

 // Structure //

 *********************************** - marque-container - *************************************
 *                                                                                *
 *   ******************************* ******************************************************   *
 *   *                             * *                                                    *   *
 *   * - marquee-content-sibling - * *                 - marquee-content -                *   *
 *   *                             * *                                                    *   *
 *   ******************************* ******************************************************   *
 *                                                                                *
 **********************************************************************************************

 // Usage //

 Only need to call the createMarquee() function,
 if desired, pass through the following paramaters:

 $1 duration:                   controls the speed at which the marquee moves

 $2 padding:                    right margin between consecutive marquees.

 $3 marquee_class:             the actual div or span that will be used to create the marquee -
 multiple marquee items may be created using this item's content.
 This item will be removed from the dom

 $4 container_class:           the container div in which the marquee content will animate.

 $5 marquee-content-sibling :   (optional argument) a sibling item to the marqueed item  that
 affects the end point position and available space inside the
 container.

 $6 hover:                     Boolean to indicate whether pause on hover should is required.

 Eg:
 createMarquee({
          duration: 20000,
          padding: 10,
          marquee_class: '.marquee',
          container_class: '.marq-contaniner',
          sibling_class: 'marq-sibling',
          hover: true
        });

 * ============================================================================================================== *

 **/

var marqueeSpawned = [];
var marqueeHovered = false;

if(document.hasFocus()) {
    var focused = true;
} else {
    var focused = false;
}

function marqueeObj (newElement) {
    this.el = newElement;
    this.counter = 0;
    this.getPosition = getCurrentPosition;
    this.name = "";
    this.timeLeft = 0;
    this.currentPos = 0;
    this.distanceLeft = 0;
    this.totalDistance = 0;
    this.contentWidth = 0;
    this.endPoint = 0;
    this.duration = 0;
    this.hovered = false;
    this.padding = 0;
}

function getCurrentPosition() {
    this.currentPos = parseInt($(this.name).css('left'));
    return this.currentPos;
}

function createMarquee(settings) {

    var defaults = {
        duration: 20000,
        padding: 10,
        marquee_class: '.marquee',
        container_class: '.container',

        sibling_class: 0,
        hover: true
    };

    var config = $.extend({}, defaults, settings);

    if($(config.marquee_class).width() == 0){
        console.error('FATAL: marquee css or children css not correct. Width is either set to 0 or the element is collapsing. Make sure overflow is set on the marquee, and the children are postitioned relatively');
        return;
    }

    if(typeof $(config.marquee_class) === 'undefined'){
        console.error('FATAL: marquee class not valid');
        return;
    }

    if(typeof $(config.container_class) === 'undefined'){
        console.error('FATAL: marquee container class not valid');
        return;
    }

    if(config.sibling_class != 0 && typeof $(config.sibling_class) === 'undefined'){
        console.error('FATAL: sibling class container class not valid');
        return;
    }

    var config = $.extend({}, defaults, settings);

    var marqueeContent =  $(config.marquee_class).html()
    var containerWidth = $(config.container_class).width();
    var contentWidth = $(config.marquee_class).width();

    if (config.sibling_class == 0) {
        var widthToIgnore = 0;
    } else {
        var widthToIgnore = $(config.sibling_class).width();
    }

    var spawnAmount = Math.ceil(containerWidth / contentWidth);
    //init vars from input

    $(config.marquee_class).remove();

    if(spawnAmount<=2){
        spawnAmount =3;
    } else {
        spawnAmount++
    }

    var totalContentWidth = (contentWidth + config.padding)*spawnAmount;

    var endPoint = -(totalContentWidth - containerWidth);

    var totalDistance =  containerWidth - endPoint;

    //initialise positions counters, content

    for (i = 0; i < spawnAmount; i++) {

        if(config.hover == true){

            var newElement = $('
' + marqueeContent + '
')
                .mouseenter(function() {

                    if ((focused == true) && (marqueeHovered == false)){
                        marqueeHovered = true;

                        for (var key in marqueeSpawned){
                            marqueeSpawned[key].el.clearQueue().stop();
                            marqueeSpawned[key].hovered = true;
                        }

                    }

                })
                .mouseleave(function() {

                    if ((focused == true) && (marqueeHovered == true)){

                        for (var key in marqueeSpawned){
                            marqueeManager(marqueeSpawned[key]);
                        }

                        marqueeHovered = false;
                    }
                });

        } else {

            var newElement = $('
' + marqueeContent + '
') ;

        }

        marqueeSpawned[i] = new marqueeObj(newElement);

        $(config.container_class).append(newElement);

        marqueeSpawned[i].currentPos = (widthToIgnore + (contentWidth*i))+(config.padding*i);  //initial positioning
        marqueeSpawned[i].name = '.marquee-'+(i+1);

        marqueeSpawned[i].totalDistance = totalDistance;
        marqueeSpawned[i].containerWidth = containerWidth;
        marqueeSpawned[i].contentWidth = contentWidth;
        marqueeSpawned[i].endPoint = endPoint;
        marqueeSpawned[i].duration = config.duration;
        marqueeSpawned[i].padding = config.padding;

        marqueeSpawned[i].el.css('left', marqueeSpawned[i].currentPos+config.padding +'px'); //setting left according to postition

        if (focused == true){
            marqueeManager(marqueeSpawned[i]);
        }

    }
}

function marqueeManager(marqueed_el) {

    if (marqueed_el.hovered == false) {

        if (marqueed_el.counter > 0) {  //this is not the first loop

            marqueed_el.timeLeft = marqueed_el.duration;
            marqueed_el.el.css('left', marqueed_el.containerWidth +'px'); //setting margin
            marqueed_el.currentPos = marqueed_el.containerWidth;
            marqueed_el.distanceLeft = marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition());

        } else {    // this is the first loop

            marqueed_el.timeLeft = (((marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition()))/ marqueed_el.totalDistance)) * marqueed_el.duration;
        }

    } else {
        marqueed_el.hovered = false;
        marqueed_el.currentPos = parseInt(marqueed_el.el.css('left'));
        marqueed_el.distanceLeft = marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition());
        marqueed_el.timeLeft = (((marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.currentPos))/ marqueed_el.totalDistance)) * marqueed_el.duration;
    }

    marqueeAnim(marqueed_el);
}

function marqueeAnim (marqueeObject){
    marqueeObject.counter++
    marqueeObject.el.clearQueue().animate({'left': marqueeObject.endPoint+'px'}, marqueeObject.timeLeft, 'linear', function(){marqueeManager(marqueeObject)});
}

window.onfocus = function(){
    focused = true;
    for (var key in marqueeSpawned){
        marqueeManager(marqueeSpawned[key]);
    }
};

window.onblur = function(){
    focused = false;
    for (var key in marqueeSpawned){
        marqueeSpawned[key].el.clearQueue().stop();
        marqueeSpawned[key].hovered = true;
    }
};

/**
 * Created by ccole on 5/15/2017.
 */
<commit_msg>Update marquee.js<commit_after>/**

 * ============================================== Marquee Manager =============================================== *

 * Author: Conrad Feyt
 * Email: conrad.feyt@gmail.com
 * Version: 1.5
 * Tested only on modern browsers

 // Structure //

 *********************************** - marque-container - *************************************
 *                                                                                *
 *   ******************************* ******************************************************   *
 *   *                             * *                                                    *   *
 *   * - marquee-content-sibling - * *                 - marquee-content -                *   *
 *   *                             * *                                                    *   *
 *   ******************************* ******************************************************   *
 *                                                                                *
 **********************************************************************************************

 // Usage //

 Only need to call the createMarquee() function,
 if desired, pass through the following paramaters:

 $1 duration:                   controls the speed at which the marquee moves

 $2 padding:                    right margin between consecutive marquees.

 $3 marquee_class:             the actual div or span that will be used to create the marquee -
 multiple marquee items may be created using this item's content.
 This item will be removed from the dom

 $4 container_class:           the container div in which the marquee content will animate.

 $5 marquee-content-sibling :   (optional argument) a sibling item to the marqueed item  that
 affects the end point position and available space inside the
 container.

 $6 hover:                     Boolean to indicate whether pause on hover should is required.

 Eg:
 createMarquee({
          duration: 20000,
          padding: 10,
          marquee_class: '.marquee',
          container_class: '.marq-contaniner',
          sibling_class: 'marq-sibling',
          hover: true
        });

 * ============================================================================================================== *

 **/

var marqueeSpawned = [];
var marqueeHovered = false;

if(document.hasFocus()) {
    var focused = true;
} else {
    var focused = false;
}

function marqueeObj (newElement) {
    this.el = newElement;
    this.counter = 0;
    this.getPosition = getCurrentPosition;
    this.name = "";
    this.timeLeft = 0;
    this.currentPos = 0;
    this.distanceLeft = 0;
    this.totalDistance = 0;
    this.contentWidth = 0;
    this.endPoint = 0;
    this.duration = 0;
    this.hovered = false;
    this.padding = 0;
}

function getCurrentPosition() {
    this.currentPos = parseInt($(this.name).css('left'));
    return this.currentPos;
}

function createMarquee(settings) {

    var defaults = {
        duration: 20000,
        padding: 10,
        marquee_class: '.marquee',
        container_class: '.container',

        sibling_class: 0,
        hover: true
    };

    var config = $.extend({}, defaults, settings);

    if($(config.marquee_class).width() == 0){
        console.error('FATAL: marquee css or children css not correct. Width is either set to 0 or the element is collapsing. Make sure overflow is set on the marquee, and the children are postitioned relatively');
        return;
    }

    if(typeof $(config.marquee_class) === 'undefined'){
        console.error('FATAL: marquee class not valid');
        return;
    }

    if(typeof $(config.container_class) === 'undefined'){
        console.error('FATAL: marquee container class not valid');
        return;
    }

    if(config.sibling_class != 0 && typeof $(config.sibling_class) === 'undefined'){
        console.error('FATAL: sibling class container class not valid');
        return;
    }

    var config = $.extend({}, defaults, settings);

    var marqueeContent =  $(config.marquee_class).html()
    var containerWidth = $(config.container_class).width();
    var contentWidth = $(config.marquee_class).width();

    if (config.sibling_class == 0) {
        var widthToIgnore = 0;
    } else {
        var widthToIgnore = $(config.sibling_class).width();
    }

    var spawnAmount = Math.ceil(containerWidth / contentWidth);
    //init vars from input

    $(config.marquee_class).remove();

    if(spawnAmount<=2){
        spawnAmount =3;
    } else {
        spawnAmount++
    }

    var totalContentWidth = (contentWidth + config.padding)*spawnAmount;

    var endPoint = -(totalContentWidth - containerWidth);

    var totalDistance =  containerWidth - endPoint;

    //initialise positions counters, content

    for (i = 0; i < spawnAmount; i++) {

        if(config.hover == true){

            var newElement = $('
' + marqueeContent + '
')
                .mouseenter(function() {

                    if ((focused == true) && (marqueeHovered == false)){
                        marqueeHovered = true;

                        for (var key in marqueeSpawned){
                            marqueeSpawned[key].el.clearQueue().stop();
                            marqueeSpawned[key].hovered = true;
                        }

                    }

                })
                .mouseleave(function() {

                    if ((focused == true) && (marqueeHovered == true)){

                        for (var key in marqueeSpawned){
                            marqueeManager(marqueeSpawned[key]);
                        }

                        marqueeHovered = false;
                    }
                });

        } else {

            var newElement = $('
' + marqueeContent + '
') ;

        }

        marqueeSpawned[i] = new marqueeObj(newElement);

        $(config.container_class).append(newElement);

        marqueeSpawned[i].currentPos = (widthToIgnore + (contentWidth*i))+(config.padding*i);  //initial positioning
        marqueeSpawned[i].name = '.marquee-'+(i+1);

        marqueeSpawned[i].totalDistance = totalDistance;
        marqueeSpawned[i].containerWidth = containerWidth;
        marqueeSpawned[i].contentWidth = contentWidth;
        marqueeSpawned[i].endPoint = endPoint;
        marqueeSpawned[i].duration = config.duration;
        marqueeSpawned[i].padding = config.padding;

        marqueeSpawned[i].el.css('left', marqueeSpawned[i].currentPos+config.padding +'px'); //setting left according to postition

        if (focused == true){
            marqueeManager(marqueeSpawned[i]);
        }

    }
}

function marqueeManager(marqueed_el) {

 console.log(marqueed_el);

    if (marqueed_el.hovered == false) {

        if (marqueed_el.counter > 0) {  //this is not the first loop

            marqueed_el.timeLeft = marqueed_el.duration;
            marqueed_el.el.css('left', marqueed_el.containerWidth +'px'); //setting margin
            marqueed_el.currentPos = marqueed_el.containerWidth;
            marqueed_el.distanceLeft = marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition());

        } else {    // this is the first loop

            marqueed_el.timeLeft = (((marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition()))/ marqueed_el.totalDistance)) * marqueed_el.duration;
        }

    } else {
        marqueed_el.hovered = false;
        marqueed_el.currentPos = parseInt(marqueed_el.el.css('left'));
        marqueed_el.distanceLeft = marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.getPosition());
        marqueed_el.timeLeft = (((marqueed_el.totalDistance - (marqueed_el.containerWidth - marqueed_el.currentPos))/ marqueed_el.totalDistance)) * marqueed_el.duration;
    }

    marqueeAnim(marqueed_el);
}

function marqueeAnim (marqueeObject){
    marqueeObject.counter++
    marqueeObject.el.clearQueue().animate({'left': marqueeObject.endPoint+'px'}, marqueeObject.timeLeft, 'linear', function(){marqueeManager(marqueeObject)});
}

window.onfocus = function(){
    focused = true;
    for (var key in marqueeSpawned){
        marqueeManager(marqueeSpawned[key]);
    }
};

window.onblur = function(){
    focused = false;
    for (var key in marqueeSpawned){
        marqueeSpawned[key].el.clearQueue().stop();
        marqueeSpawned[key].hovered = true;
    }
};

/**
 * Created by ccole on 5/15/2017.
 */
<|endoftext|>


<commit_before>/* global TrelloPowerUp */
var Promise = TrelloPowerUp.Promise;
var t = TrelloPowerUp.iframe();

var gFormUrl = '';
var cardName = '';
var cardShortLink = '';
var userName = t.arg('user');
// var usernick = document.getElementsByClassName("js-member-name")[0].innerText;

// this function we be called once on initial load
// and then called each time something changes
t.render(function(){
  // t.card('members')
  // .get('members')
  // .filter(function(member){
  //   return member.email.indexOf('Alejandro Lizardo Celiz') == 0;
  // })
  // .then(function(members){
  //   console.log(members);
  //   userName = members.map(function(a){ return a.email; });
  //   console.log(userName);
  // })

  return Promise.all([
    t.get('board', 'shared', 'url'),
    t.card('name', 'url'),
    t.card('members').get('members')
  ])
  .spread(function(savedGFormUrl, cardData, members){
    if(savedGFormUrl){
      gFormUrl = savedGFormUrl;
    } else {
      document.getElementById('overlay-message')
      .textContent = 'Please add form url on settings';
    }
    if(cardData){
      cardName = cardData.name;
      cardUrl = cardData.url;
    }
    members
    .filter(function(member){
      return member.email.indexOf('Alejandro Lizardo Celiz') == 0;
    })
    .then(function(members){
      console.log(members);
      userName = members.map(function(a){ return a.email; });
      console.log(userName);
    })
  })
  .then(function(){
    document.getElementsByTagName('iframe')[0].src = gFormUrl +
    "?embedded=true&entry.995291397=" + cardName +
    "&entry.33315152=" + userName +
    "&entry.1600294234=" + cardUrl;
  })

});

// close overlay if user clicks outside our content
document.addEventListener('click', function(e) {
  if(e.target.tagName == 'BODY') {
    t.closeOverlay().done();
  }
});

// close overlay if user presses escape key
document.addEventListener('keyup', function(e) {
  if(e.keyCode == 27) {
    t.closeOverlay().done();
  }
});
<commit_msg>Current User<commit_after>/* global TrelloPowerUp */
var Promise = TrelloPowerUp.Promise;
var t = TrelloPowerUp.iframe();

var gFormUrl = '';
var cardName = '';
var cardShortLink = '';
var userName = t.arg('user');
// var usernick = document.getElementsByClassName("js-member-name")[0].innerText;

// this function we be called once on initial load
// and then called each time something changes
t.render(function(){
  // t.card('members')
  // .get('members')
  // .filter(function(member){
  //   return member.email.indexOf('Alejandro Lizardo Celiz') == 0;
  // })
  // .then(function(members){
  //   console.log(members);
  //   userName = members.map(function(a){ return a.email; });
  //   console.log(userName);
  // })

  return Promise.all([
    t.get('board', 'shared', 'url'),
    t.card('name', 'url'),
    t.card('members').get('members')
  ])
  .spread(function(savedGFormUrl, cardData, members){
    if(savedGFormUrl){
      gFormUrl = savedGFormUrl;
    } else {
      document.getElementById('overlay-message')
      .textContent = 'Please add form url on settings';
    }
    if(cardData){
      cardName = cardData.name;
      cardUrl = cardData.url;
    }
    console.log(members);
    // members
    // .filter(function(member){
    //   return member.email.indexOf('Alejandro Lizardo Celiz') == 0;
    // })
    // .then(function(members){
    //   console.log(members);
    //   userName = members.map(function(a){ return a.email; });
    //   console.log(userName);
    // })
  })
  .then(function(){
    document.getElementsByTagName('iframe')[0].src = gFormUrl +
    "?embedded=true&entry.995291397=" + cardName +
    "&entry.33315152=" + userName +
    "&entry.1600294234=" + cardUrl;
  })

});

// close overlay if user clicks outside our content
document.addEventListener('click', function(e) {
  if(e.target.tagName == 'BODY') {
    t.closeOverlay().done();
  }
});

// close overlay if user presses escape key
document.addEventListener('keyup', function(e) {
  if(e.keyCode == 27) {
    t.closeOverlay().done();
  }
});
<|endoftext|>


<commit_before>if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

define(["require","../deep", "../lib/unit"], function (require, deep, Unit) {

    //_______________________________________________________________ GENERIC STORE TEST CASES

    var unit = {
        title:"deep/units/compositions",
        stopOnError:false,
        setup:function(){
            return {
                a : {
                    func1:function(){
                        //console.log("func1");
                        this.res.push("func1");
                    },
                    func2:deep.compose.before(function(){
                        //console.log("func2");
                        this.res.push("func2");
                    }),
                    func3:deep.compose.after(function(){
                        //console.log("func3");
                        this.res.push("func3");
                    })
                },
                b : {
                    res:[],
                    func1:deep.compose.after(function(){
                        // console.log("func1_1");
                        this.res.push("func1_1");
                    }),
                    func2:deep.compose.after(function(){
                        // console.log("func2_2");
                        this.res.push("func2_2");
                    }),
                    func3:deep.compose.after(function(){
                        // console.log("func3_3");
                        this.res.push("func3_3");
                    })
                },
                c : {
                    res:[],
                    func1:deep.compose.after(function(){
                        // console.log("func1_1_c");
                        this.res.push("func1_1_c");
                    }),
                    func2:deep.compose.after(function(){
                        // console.log("func2_2_c");
                        this.res.push("func2_2_c");
                    }),
                    func3:deep.compose.after(function(){
                        // console.log("func3_3_c");
                        this.res.push("func3_3_c");
                    })
                }
            };
        },
        tests : {
            a:function(){
                return deep(this.b)
                .bottom(this.a)
                .query("/(func.*)")
                .run()
                .query("/res")
                .equal(["func1","func1_1", "func2","func2_2","func3","func3_3"]);

            },
            b:function(){
                return deep(this.c)
                .bottom(this.a)
                .query("./(func.*)")
                .run()
                .query("/res")
                .equal(["func1","func1_1_c", "func2","func2_2_c","func3","func3_3_c"]);
            },
            after:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return closure.test;
                    }
                };
                var b = {
                    test:deep.compose.after(function(){
                        closure.test += " : after";
                        return closure.test;
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("hello test : after");
            },
            delayed_after:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return deep.when(closure.test).delay(2);
                    }
                };
                var b = {
                    test:deep.compose.after(function(){
                        closure.test += " : after";
                        return deep.when(closure.test).delay(1);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal( "hello test : after" );
            },
            around:function(){
                var a = {
                    test:function(){
                        return "test";
                    }
                };
                var b = {
                    test:deep.compose.around(function(old){
                        return function(){
                            return "hello "+ old.apply(this) + " around";
                        };
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("hello test around");
            },
            before:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                    }
                };
                var b = {
                    test:deep.compose.before(function(){
                        closure.test += "before : ";
                    })
                };
                deep.utils.up(b,a);
                a.test();
                return deep(closure.test)
                .equal("before : hello test");
            },
            delayed_before:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return deep(closure.test).delay(1);
                    }
                };
                var b = {
                    test:deep.compose.before(function(){
                        closure.test += "before : ";
                        return deep(closure.test).delay(1);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("before : hello test");
            },
            parallele:function(){
                var a = {
                    test:function(){
                        return "hello test";
                    }
                };
                var b = {
                    test:deep.compose.parallele(function(){
                        return "hello parallele";
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal(["hello test", "hello parallele"]);
            },
            delayed_parallele:function(){
                var a = {
                    test:function(){
                        return deep.when("hello test").delay(2);
                    }
                };
                var b = {
                    test:deep.compose.parallele(function(){
                        return deep.when("hello parallele").delay(3);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal(["hello test", "hello parallele"]);
            },
            before_alone:function(){
                var a = {
                    test:deep.compose.before(function(){
                        return "hello";
                    })
                };
                return deep.when(a.test()).equal("hello");
            },
            before_alone_with_arg:function(){
                var a = {
                    test:deep.compose.before(function(arg){
                        return "hello";
                    })
                };
                return deep.when(a.test()).equal("hello");
            },
            before_replace_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.before(function(arg){
                       return "weee";
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : weee");
            },
             before_dont_replace_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.before(function(arg){
                       // return nothing so arg are forwarded
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : bloup");
            },
            after_forward_result : function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.after(function(arg){
                       // return nothing so result are not changed
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : bloup");
            },
            after_receive_forwarded_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.after(function(arg){
                        return arg+"!";
                    })
                };

                deep.utils.bottom(b, a);
                return deep.when(a.test("bloup"))
                .equal("hello : bloup!");
            },
            argsBefore:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        return ["A1:"+arg1, "A2:"+arg2];
                    }
                };
                var b = {
                    test:deep.compose.before(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return ["B1:"+arg1, "B2:"+arg2];
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["A1:B1:hello", "A2:B2:world"])
                .deep(checker)
                .equal({
                    fromB:["hello","world"],
                    fromA:["B1:hello", "B2:world"]
                });
            },
            argsAfter:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        return ["A1:"+arg1, "A2:"+arg2];
                    }
                };
                var b = {
                    test:deep.compose.after(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return ["B1:"+arg1, "B2:"+arg2];
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["B1:A1:hello", "B2:A2:world"])
                .deep(checker)
                .equal({
                    fromA:["hello","world"],
                    fromB:["A1:hello", "A2:world"]
                });
            },
            argsAfterUndefined:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        //return ["A1:"+arg1, "A2:"+arg2];
                    }
                };
                var b = {
                    test:deep.compose.after(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return ["B1:"+arg1, "B2:"+arg2];
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["B1:hello", "B2:world"])
                .deep(checker)
                .equal({
                    fromA:["hello","world"],
                    fromB:["hello", "world"]
                });
            }

        }
    };

    return unit;
});
<commit_msg>compositions test cases update with deep.arguments<commit_after>if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

define(["require","../deep", "../lib/unit"], function (require, deep, Unit) {

    //_______________________________________________________________ GENERIC STORE TEST CASES

    var unit = {
        title:"deep/units/compositions",
        stopOnError:false,
        setup:function(){
            return {
                a : {
                    func1:function(){
                        //console.log("func1");
                        this.res.push("func1");
                    },
                    func2:deep.compose.before(function(){
                        //console.log("func2");
                        this.res.push("func2");
                    }),
                    func3:deep.compose.after(function(){
                        //console.log("func3");
                        this.res.push("func3");
                    })
                },
                b : {
                    res:[],
                    func1:deep.compose.after(function(){
                        // console.log("func1_1");
                        this.res.push("func1_1");
                    }),
                    func2:deep.compose.after(function(){
                        // console.log("func2_2");
                        this.res.push("func2_2");
                    }),
                    func3:deep.compose.after(function(){
                        // console.log("func3_3");
                        this.res.push("func3_3");
                    })
                },
                c : {
                    res:[],
                    func1:deep.compose.after(function(){
                        // console.log("func1_1_c");
                        this.res.push("func1_1_c");
                    }),
                    func2:deep.compose.after(function(){
                        // console.log("func2_2_c");
                        this.res.push("func2_2_c");
                    }),
                    func3:deep.compose.after(function(){
                        // console.log("func3_3_c");
                        this.res.push("func3_3_c");
                    })
                }
            };
        },
        tests : {
            a:function(){
                return deep(this.b)
                .bottom(this.a)
                .query("/(func.*)")
                .run()
                .query("/res")
                .equal(["func1","func1_1", "func2","func2_2","func3","func3_3"]);

            },
            b:function(){
                return deep(this.c)
                .bottom(this.a)
                .query("./(func.*)")
                .run()
                .query("/res")
                .equal(["func1","func1_1_c", "func2","func2_2_c","func3","func3_3_c"]);
            },
            after:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return closure.test;
                    }
                };
                var b = {
                    test:deep.compose.after(function(){
                        closure.test += " : after";
                        return closure.test;
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("hello test : after");
            },
            delayed_after:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return deep.when(closure.test).delay(2);
                    }
                };
                var b = {
                    test:deep.compose.after(function(){
                        closure.test += " : after";
                        return deep.when(closure.test).delay(1);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal( "hello test : after" );
            },
            around:function(){
                var a = {
                    test:function(){
                        return "test";
                    }
                };
                var b = {
                    test:deep.compose.around(function(old){
                        return function(){
                            return "hello "+ old.apply(this) + " around";
                        };
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("hello test around");
            },
            before:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                    }
                };
                var b = {
                    test:deep.compose.before(function(){
                        closure.test += "before : ";
                    })
                };
                deep.utils.up(b,a);
                a.test();
                return deep(closure.test)
                .equal("before : hello test");
            },
            delayed_before:function(){
                var closure = { test:"" };
                var a = {
                    test:function(){
                        closure.test += "hello test";
                        return deep(closure.test).delay(1);
                    }
                };
                var b = {
                    test:deep.compose.before(function(){
                        closure.test += "before : ";
                        return deep(closure.test).delay(1);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal("before : hello test");
            },
            parallele:function(){
                var a = {
                    test:function(){
                        return "hello test";
                    }
                };
                var b = {
                    test:deep.compose.parallele(function(){
                        return "hello parallele";
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal(["hello test", "hello parallele"]);
            },
            delayed_parallele:function(){
                var a = {
                    test:function(){
                        return deep.when("hello test").delay(2);
                    }
                };
                var b = {
                    test:deep.compose.parallele(function(){
                        return deep.when("hello parallele").delay(3);
                    })
                };
                deep.utils.up(b,a);
                return deep.when(a.test())
                .equal(["hello test", "hello parallele"]);
            },
            before_alone:function(){
                var a = {
                    test:deep.compose.before(function(){
                        return "hello";
                    })
                };
                return deep.when(a.test()).equal("hello");
            },
            before_alone_with_arg:function(){
                var a = {
                    test:deep.compose.before(function(arg){
                        return "hello";
                    })
                };
                return deep.when(a.test()).equal("hello");
            },
            before_replace_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.before(function(arg){
                       return "weee";
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : weee");
            },
             before_dont_replace_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.before(function(arg){
                       // return nothing so arg are forwarded
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : bloup");
            },
            after_forward_result : function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.after(function(arg){
                       // return nothing so result are not changed
                    })
                };

                deep.utils.bottom(b, a);

                return deep.when(a.test("bloup")).equal("hello : bloup");
            },
            after_receive_forwarded_arg:function(){
                var b = {
                    test:function(arg){
                       return "hello : "+arg;
                    }
                };
                var a = {
                    test:deep.compose.after(function(arg){
                        return arg+"!";
                    })
                };

                deep.utils.bottom(b, a);
                return deep.when(a.test("bloup"))
                .equal("hello : bloup!");
            },
            argsBefore:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        return deep.Arguments(["A1:"+arg1, "A2:"+arg2]);
                    }
                };
                var b = {
                    test:deep.compose.before(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return deep.Arguments(["B1:"+arg1, "B2:"+arg2]);
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["A1:B1:hello", "A2:B2:world"])
                .deep(checker)
                .equal({
                    fromB:["hello","world"],
                    fromA:["B1:hello", "B2:world"]
                });
            },
            argsAfter:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        return deep.Arguments(["A1:"+arg1, "A2:"+arg2]);
                    }
                };
                var b = {
                    test:deep.compose.after(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return deep.Arguments(["B1:"+arg1, "B2:"+arg2]);
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["B1:A1:hello", "B2:A2:world"])
                .deep(checker)
                .equal({
                    fromA:["hello","world"],
                    fromB:["A1:hello", "A2:world"]
                });
            },
            argsAfterUndefined:function(){
                var checker = {};
                var a = {
                    test:function(arg1, arg2){
                        checker.fromA = [arg1, arg2];
                        //return ["A1:"+arg1, "A2:"+arg2];
                    }
                };
                var b = {
                    test:deep.compose.after(function(arg1, arg2){
                        checker.fromB = [arg1, arg2];
                        return ["B1:"+arg1, "B2:"+arg2];
                    })
                };
                deep.utils.up(b,a);
                return deep(a.test("hello","world"))
                .equal(["B1:hello", "B2:world"])
                .deep(checker)
                .equal({
                    fromA:["hello", "world"],
                    fromB:["hello", "world"]
                });
            },
            fineFail:function(){
                var closure = {};
                var test = function(a,b){
                    return [a+2,b+3];
                };
                var test2 = deep.compose.after(function(a,b){
                    return new Error("tralala");
                })
                .after(function(a,b){
                    closure.shouldntSeeThis = true;
                });

                var test3 = deep.utils.up(test2, test);

                try{
                    test3(1,3);
                }
                catch(e){
                    console.log("error cacthed : ", e);
                }

            }

        }
    };

    return unit;
});
<|endoftext|>


<commit_before>/**
 * painter.js
 */
'use strict';

const _start = 'mousedown',
_move = 'mousemove',
_end = 'mouseup',
_out = 'mouseout';

const Pen = (() => {

	const operation = 'source-over';

	let color,
	weight,
	cap;

	return {
		getOperation : () => {
			return operation;
		},
		getColor : () => {
			return color;
		},
		getWeight : () => {
			return weight;
		},
		getCap : () => {
			return cap;
		},
		setWeight : w => {
			weight = w;
		},
		setData : data => {
			color = data.color;
			weight = data.weight;
			cap = data.cap;
		}
	};

})();

const canvasPainter = (id, interfaceId, canvasW, canvasH) => {

	const canvas = document.getElementById(id),
	canvasI = document.getElementById(interfaceId),
	ctx = canvas.getContext('2d'),
	ctxI = canvasI.getContext('2d');

	canvas.width = canvasW;
	canvas.height = canvasH;
	canvasI.width = canvasW;
	canvasI.height = canvasH;

	let chose,
	drawData,
	lineScale = 1,
	mouse = { x : 0, y : 0 },
	windowW = window.innerWidth,
	windowH = window.innerHeight,
	offsetLeft = canvas.offsetLeft,
	offsetTop = canvas.offsetTop;

	const _handleMouseDown = () => {
		ctx.beginPath();
		const mouseX = canvas.offsetLeft !== 0 ? (mouse.x - canvas.offsetLeft) : mouse.x;
		const mouseY = canvas.offsetTop !== 0 ? (mouse.y - canvas.offsetTop) : mouse.y;
		ctx.moveTo(mouseX, mouseY);
		canvas.addEventListener(_move, _onPaint, false);
	};

	const _handleMouseMove = (e) => {
		mouse.x = e.pageX;
		mouse.y = e.pageY;
	};

	const _handleMouseUp = () => {
		canvas.removeEventListener(_move, _onPaint, false);
		drawData = canvas.toDataURL();
	};

	const _onPaint = () => {
		const mouseX = canvas.offsetLeft !== 0 ? (mouse.x - canvas.offsetLeft) : mouse.x;
		const mouseY = canvas.offsetTop !== 0 ? (mouse.y - canvas.offsetTop) : mouse.y;
		ctx.lineTo(mouseX, mouseY);
		ctx.stroke();
	};

	const _setCtx = () => {
		ctx.globalCompositeOperation = chose.getOperation();
		ctx.strokeStyle = chose.getColor();
		ctx.lineWidth = (chose.getWeight() * lineScale);
		ctx.lineCap = chose.getCap();

		Pen.setWeight((chose.getWeight() * lineScale));
	};

	const _resizeCanvas = () => {

		setTimeout(() => {

			const canvasW = canvas.width,
			canvasH = canvas.height,
			newW = window.innerWidth,
			newH = window.innerHeight,
			scaleW = (newW / windowW),
			scaleH = (newH / windowH),
			newX = (canvasW * scaleW),
			newY = (canvasH * scaleH);

			canvas.width = newX;
			canvas.height = newY;
			canvasI.width = newX;
			canvasI.height = newY;
			windowW = newW;
			windowH = newH;
			offsetLeft = canvas.offsetLeft;
			offsetTop = canvas.offsetTop;

			if (scaleW >= 1 && scaleH >= 1) {
				lineScale = scaleW > scaleH ? scaleW : scaleH;
			}

			if (scaleW <= 1 && scaleH <= 1) {
				lineScale = scaleW > scaleH ? scaleH : scaleW;
			}

			_setCtx();

			if (drawData) {
				const img = new Image();
				img.onload = () => {
					canvas.getContext('2d').drawImage(img, 0, 0, newX, newY);
				};
				img.src = drawData;
			}

		}, 250);

	};

	window.addEventListener('resize', _resizeCanvas, false);

	return {
		init : (data = { type : 'pen', weight : 1, cap : 'round', color : '#000' }) => {

			switch (data.type) {
			case 'pen':
				Pen.setData(data);
				chose = Pen;
				canvas.style.display = 'block';
				canvasI.style.display = 'none';
				break;
			}

			_setCtx();

			canvas.addEventListener(_start, _handleMouseDown, false);
			canvas.addEventListener(_move, _handleMouseMove, false);
			canvas.addEventListener(_end, _handleMouseUp, false);
			canvas.addEventListener(_out, _handleMouseUp, false);
		}
	};

};<commit_msg>Change order of functions<commit_after>/**
 * painter.js
 */
'use strict';

const _start = 'mousedown',
_move = 'mousemove',
_end = 'mouseup',
_out = 'mouseout';

const Pen = (() => {

	const operation = 'source-over';

	let color,
	weight,
	cap;

	return {
		getOperation : () => {
			return operation;
		},
		getColor : () => {
			return color;
		},
		getWeight : () => {
			return weight;
		},
		getCap : () => {
			return cap;
		},
		setWeight : w => {
			weight = w;
		},
		setData : data => {
			color = data.color;
			weight = data.weight;
			cap = data.cap;
		}
	};

})();

const canvasPainter = (id, interfaceId, canvasW, canvasH) => {

	const canvas = document.getElementById(id),
	canvasI = document.getElementById(interfaceId),
	ctx = canvas.getContext('2d'),
	ctxI = canvasI.getContext('2d');

	canvas.width = canvasW;
	canvas.height = canvasH;
	canvasI.width = canvasW;
	canvasI.height = canvasH;

	let chose,
	drawData,
	lineScale = 1,
	mouse = { x : 0, y : 0 },
	windowW = window.innerWidth,
	windowH = window.innerHeight,
	offsetLeft = canvas.offsetLeft,
	offsetTop = canvas.offsetTop;

	const _onPaint = () => {
		const mouseX = canvas.offsetLeft !== 0 ? (mouse.x - canvas.offsetLeft) : mouse.x;
		const mouseY = canvas.offsetTop !== 0 ? (mouse.y - canvas.offsetTop) : mouse.y;
		ctx.lineTo(mouseX, mouseY);
		ctx.stroke();
	};

	const _handleMouseDown = () => {
		ctx.beginPath();
		const mouseX = canvas.offsetLeft !== 0 ? (mouse.x - canvas.offsetLeft) : mouse.x;
		const mouseY = canvas.offsetTop !== 0 ? (mouse.y - canvas.offsetTop) : mouse.y;
		ctx.moveTo(mouseX, mouseY);
		canvas.addEventListener(_move, _onPaint, false);
	};

	const _handleMouseMove = (e) => {
		mouse.x = e.pageX;
		mouse.y = e.pageY;
	};

	const _handleMouseUp = () => {
		canvas.removeEventListener(_move, _onPaint, false);
		drawData = canvas.toDataURL();
	};

	const _setCtx = () => {
		ctx.globalCompositeOperation = chose.getOperation();
		ctx.strokeStyle = chose.getColor();
		ctx.lineWidth = (chose.getWeight() * lineScale);
		ctx.lineCap = chose.getCap();

		Pen.setWeight((chose.getWeight() * lineScale));
	};

	const _resizeCanvas = () => {

		setTimeout(() => {

			const canvasW = canvas.width,
			canvasH = canvas.height,
			newW = window.innerWidth,
			newH = window.innerHeight,
			scaleW = (newW / windowW),
			scaleH = (newH / windowH),
			newX = (canvasW * scaleW),
			newY = (canvasH * scaleH);

			canvas.width = newX;
			canvas.height = newY;
			canvasI.width = newX;
			canvasI.height = newY;
			windowW = newW;
			windowH = newH;
			offsetLeft = canvas.offsetLeft;
			offsetTop = canvas.offsetTop;

			if (scaleW >= 1 && scaleH >= 1) {
				lineScale = scaleW > scaleH ? scaleW : scaleH;
			}

			if (scaleW <= 1 && scaleH <= 1) {
				lineScale = scaleW > scaleH ? scaleH : scaleW;
			}

			_setCtx();

			if (drawData) {
				const img = new Image();
				img.onload = () => {
					canvas.getContext('2d').drawImage(img, 0, 0, newX, newY);
				};
				img.src = drawData;
			}

		}, 250);

	};

	window.addEventListener('resize', _resizeCanvas, false);

	return {
		init : (data = { type : 'pen', weight : 1, cap : 'round', color : '#000' }) => {

			switch (data.type) {
			case 'pen':
				Pen.setData(data);
				chose = Pen;
				canvas.style.display = 'block';
				canvasI.style.display = 'none';
				break;
			}

			_setCtx();

			canvas.addEventListener(_start, _handleMouseDown, false);
			canvas.addEventListener(_move, _handleMouseMove, false);
			canvas.addEventListener(_end, _handleMouseUp, false);
			canvas.addEventListener(_out, _handleMouseUp, false);
		}
	};

};<|endoftext|>


<commit_before>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

// Workaround for Windows 10 in hosted environment case
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
if (window.cordova && !(window.cordova instanceof HTMLElement)) { // eslint-disable-line no-undef
    throw new Error('cordova already defined');
}

var channel = require('cordova/channel');
var platform = require('cordova/platform');

/**
 * Intercept calls to addEventListener + removeEventListener and handle deviceready,
 * resume, and pause events.
 */
var m_document_addEventListener = document.addEventListener;
var m_document_removeEventListener = document.removeEventListener;
var m_window_addEventListener = window.addEventListener;
var m_window_removeEventListener = window.removeEventListener;

/**
 * Houses custom event handlers to intercept on document + window event listeners.
 */
var documentEventHandlers = {};
var windowEventHandlers = {};

document.addEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    if (typeof documentEventHandlers[e] !== 'undefined') {
        documentEventHandlers[e].subscribe(handler);
    } else {
        m_document_addEventListener.call(document, evt, handler, capture);
    }
};

window.addEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    if (typeof windowEventHandlers[e] !== 'undefined') {
        windowEventHandlers[e].subscribe(handler);
    } else {
        m_window_addEventListener.call(window, evt, handler, capture);
    }
};

document.removeEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    // If unsubscribing from an event that is handled by a plugin
    if (typeof documentEventHandlers[e] !== 'undefined') {
        documentEventHandlers[e].unsubscribe(handler);
    } else {
        m_document_removeEventListener.call(document, evt, handler, capture);
    }
};

window.removeEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    // If unsubscribing from an event that is handled by a plugin
    if (typeof windowEventHandlers[e] !== 'undefined') {
        windowEventHandlers[e].unsubscribe(handler);
    } else {
        m_window_removeEventListener.call(window, evt, handler, capture);
    }
};

function createEvent (type, data) {
    var event = document.createEvent('Events');
    event.initEvent(type, false, false);
    if (data) {
        for (var i in data) {
            if (data.hasOwnProperty(i)) {
                event[i] = data[i];
            }
        }
    }
    return event;
}

/* eslint-disable no-undef */
var cordova = {
    define: define,
    require: require,
    version: PLATFORM_VERSION_BUILD_LABEL,
    platformVersion: PLATFORM_VERSION_BUILD_LABEL,
    platformId: platform.id,

    /* eslint-enable no-undef */

    /**
     * Methods to add/remove your own addEventListener hijacking on document + window.
     */
    addWindowEventHandler: function (event) {
        return (windowEventHandlers[event] = channel.create(event));
    },
    addStickyDocumentEventHandler: function (event) {
        return (documentEventHandlers[event] = channel.createSticky(event));
    },
    addDocumentEventHandler: function (event) {
        return (documentEventHandlers[event] = channel.create(event));
    },
    removeWindowEventHandler: function (event) {
        delete windowEventHandlers[event];
    },
    removeDocumentEventHandler: function (event) {
        delete documentEventHandlers[event];
    },
    /**
     * Retrieve original event handlers that were replaced by Cordova
     *
     * @return object
     */
    getOriginalHandlers: function () {
        return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
            'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
    },
    /**
     * Method to fire event from native code
     * bNoDetach is required for events which cause an exception which needs to be caught in native code
     */
    fireDocumentEvent: function (type, data, bNoDetach) {
        var evt = createEvent(type, data);
        if (typeof documentEventHandlers[type] !== 'undefined') {
            if (bNoDetach) {
                documentEventHandlers[type].fire(evt);
            } else {
                setTimeout(function () {
                    // Fire deviceready on listeners that were registered before cordova.js was loaded.
                    if (type === 'deviceready') {
                        document.dispatchEvent(evt);
                    }
                    documentEventHandlers[type].fire(evt);
                }, 0);
            }
        } else {
            document.dispatchEvent(evt);
        }
    },
    fireWindowEvent: function (type, data) {
        var evt = createEvent(type, data);
        if (typeof windowEventHandlers[type] !== 'undefined') {
            setTimeout(function () {
                windowEventHandlers[type].fire(evt);
            }, 0);
        } else {
            window.dispatchEvent(evt);
        }
    },

    /**
     * Plugin callback mechanism.
     */
    // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
    // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
    callbackId: Math.floor(Math.random() * 2000000000),
    callbacks: {},
    callbackStatus: {
        NO_RESULT: 0,
        OK: 1,
        CLASS_NOT_FOUND_EXCEPTION: 2,
        ILLEGAL_ACCESS_EXCEPTION: 3,
        INSTANTIATION_EXCEPTION: 4,
        MALFORMED_URL_EXCEPTION: 5,
        IO_EXCEPTION: 6,
        INVALID_ACTION: 7,
        JSON_EXCEPTION: 8,
        ERROR: 9
    },

    /**
     * Called by native code when returning successful result from an action.
     */
    callbackSuccess: function (callbackId, args) {
        cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
    },

    /**
     * Called by native code when returning error result from an action.
     */
    callbackError: function (callbackId, args) {
        // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
        // Derive success from status.
        cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
    },

    /**
     * Called by native code when returning the result from an action.
     */
    callbackFromNative: function (callbackId, isSuccess, status, args, keepCallback) {
        try {
            var callback = cordova.callbacks[callbackId];
            if (callback) {
                if (isSuccess && status === cordova.callbackStatus.OK) {
                    callback.success && callback.success.apply(null, args);
                } else if (!isSuccess) {
                    callback.fail && callback.fail.apply(null, args);
                }
                /*
                else
                    Note, this case is intentionally not caught.
                    this can happen if isSuccess is true, but callbackStatus is NO_RESULT
                    which is used to remove a callback from the list without calling the callbacks
                    typically keepCallback is false in this case
                */
                // Clear callback if not expecting any more results
                if (!keepCallback) {
                    delete cordova.callbacks[callbackId];
                }
            }
        } catch (err) {
            var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
            console && console.log && console.log(msg);
            cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg });
            throw err;
        }
    },
    addConstructor: function (func) {
        channel.onCordovaReady.subscribe(function () {
            try {
                func();
            } catch (e) {
                console.log('Failed to run constructor: ' + e);
            }
        });
    }
};

module.exports = cordova;
<commit_msg>CB-9366 Log error.stack ...<commit_after>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

// Workaround for Windows 10 in hosted environment case
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
if (window.cordova && !(window.cordova instanceof HTMLElement)) { // eslint-disable-line no-undef
    throw new Error('cordova already defined');
}

var channel = require('cordova/channel');
var platform = require('cordova/platform');

/**
 * Intercept calls to addEventListener + removeEventListener and handle deviceready,
 * resume, and pause events.
 */
var m_document_addEventListener = document.addEventListener;
var m_document_removeEventListener = document.removeEventListener;
var m_window_addEventListener = window.addEventListener;
var m_window_removeEventListener = window.removeEventListener;

/**
 * Houses custom event handlers to intercept on document + window event listeners.
 */
var documentEventHandlers = {};
var windowEventHandlers = {};

document.addEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    if (typeof documentEventHandlers[e] !== 'undefined') {
        documentEventHandlers[e].subscribe(handler);
    } else {
        m_document_addEventListener.call(document, evt, handler, capture);
    }
};

window.addEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    if (typeof windowEventHandlers[e] !== 'undefined') {
        windowEventHandlers[e].subscribe(handler);
    } else {
        m_window_addEventListener.call(window, evt, handler, capture);
    }
};

document.removeEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    // If unsubscribing from an event that is handled by a plugin
    if (typeof documentEventHandlers[e] !== 'undefined') {
        documentEventHandlers[e].unsubscribe(handler);
    } else {
        m_document_removeEventListener.call(document, evt, handler, capture);
    }
};

window.removeEventListener = function (evt, handler, capture) {
    var e = evt.toLowerCase();
    // If unsubscribing from an event that is handled by a plugin
    if (typeof windowEventHandlers[e] !== 'undefined') {
        windowEventHandlers[e].unsubscribe(handler);
    } else {
        m_window_removeEventListener.call(window, evt, handler, capture);
    }
};

function createEvent (type, data) {
    var event = document.createEvent('Events');
    event.initEvent(type, false, false);
    if (data) {
        for (var i in data) {
            if (data.hasOwnProperty(i)) {
                event[i] = data[i];
            }
        }
    }
    return event;
}

/* eslint-disable no-undef */
var cordova = {
    define: define,
    require: require,
    version: PLATFORM_VERSION_BUILD_LABEL,
    platformVersion: PLATFORM_VERSION_BUILD_LABEL,
    platformId: platform.id,

    /* eslint-enable no-undef */

    /**
     * Methods to add/remove your own addEventListener hijacking on document + window.
     */
    addWindowEventHandler: function (event) {
        return (windowEventHandlers[event] = channel.create(event));
    },
    addStickyDocumentEventHandler: function (event) {
        return (documentEventHandlers[event] = channel.createSticky(event));
    },
    addDocumentEventHandler: function (event) {
        return (documentEventHandlers[event] = channel.create(event));
    },
    removeWindowEventHandler: function (event) {
        delete windowEventHandlers[event];
    },
    removeDocumentEventHandler: function (event) {
        delete documentEventHandlers[event];
    },
    /**
     * Retrieve original event handlers that were replaced by Cordova
     *
     * @return object
     */
    getOriginalHandlers: function () {
        return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
            'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
    },
    /**
     * Method to fire event from native code
     * bNoDetach is required for events which cause an exception which needs to be caught in native code
     */
    fireDocumentEvent: function (type, data, bNoDetach) {
        var evt = createEvent(type, data);
        if (typeof documentEventHandlers[type] !== 'undefined') {
            if (bNoDetach) {
                documentEventHandlers[type].fire(evt);
            } else {
                setTimeout(function () {
                    // Fire deviceready on listeners that were registered before cordova.js was loaded.
                    if (type === 'deviceready') {
                        document.dispatchEvent(evt);
                    }
                    documentEventHandlers[type].fire(evt);
                }, 0);
            }
        } else {
            document.dispatchEvent(evt);
        }
    },
    fireWindowEvent: function (type, data) {
        var evt = createEvent(type, data);
        if (typeof windowEventHandlers[type] !== 'undefined') {
            setTimeout(function () {
                windowEventHandlers[type].fire(evt);
            }, 0);
        } else {
            window.dispatchEvent(evt);
        }
    },

    /**
     * Plugin callback mechanism.
     */
    // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
    // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
    callbackId: Math.floor(Math.random() * 2000000000),
    callbacks: {},
    callbackStatus: {
        NO_RESULT: 0,
        OK: 1,
        CLASS_NOT_FOUND_EXCEPTION: 2,
        ILLEGAL_ACCESS_EXCEPTION: 3,
        INSTANTIATION_EXCEPTION: 4,
        MALFORMED_URL_EXCEPTION: 5,
        IO_EXCEPTION: 6,
        INVALID_ACTION: 7,
        JSON_EXCEPTION: 8,
        ERROR: 9
    },

    /**
     * Called by native code when returning successful result from an action.
     */
    callbackSuccess: function (callbackId, args) {
        cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
    },

    /**
     * Called by native code when returning error result from an action.
     */
    callbackError: function (callbackId, args) {
        // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
        // Derive success from status.
        cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
    },

    /**
     * Called by native code when returning the result from an action.
     */
    callbackFromNative: function (callbackId, isSuccess, status, args, keepCallback) {
        try {
            var callback = cordova.callbacks[callbackId];
            if (callback) {
                if (isSuccess && status === cordova.callbackStatus.OK) {
                    callback.success && callback.success.apply(null, args);
                } else if (!isSuccess) {
                    callback.fail && callback.fail.apply(null, args);
                }
                /*
                else
                    Note, this case is intentionally not caught.
                    this can happen if isSuccess is true, but callbackStatus is NO_RESULT
                    which is used to remove a callback from the list without calling the callbacks
                    typically keepCallback is false in this case
                */
                // Clear callback if not expecting any more results
                if (!keepCallback) {
                    delete cordova.callbacks[callbackId];
                }
            }
        } catch (err) {
            var msg = 'Error in ' + (isSuccess ? 'Success' : 'Error') + ' callbackId: ' + callbackId + ' : ' + err;
            console && console.log && console.log(msg);
            console && console.log && err.stack && console.log(err.stack);
            cordova.fireWindowEvent('cordovacallbackerror', { 'message': msg });
            throw err;
        }
    },
    addConstructor: function (func) {
        channel.onCordovaReady.subscribe(function () {
            try {
                func();
            } catch (e) {
                console.log('Failed to run constructor: ' + e);
            }
        });
    }
};

module.exports = cordova;
<|endoftext|>


<commit_before>document.addEventListener("DOMContentLoaded", function() {
    window.smoothScrollTo = function() {
        var timer, start, factor;
        return function(target, duration) {
            var offset = window.pageYOffset, delta = target - window.pageYOffset;
            // Y-offset difference
            duration = duration || 700;
            // default 1 sec animation
            start = Date.now();
            // get start time
            factor = 0;
            if (timer) {
                clearInterval(timer);
            }
            function step() {
                var y;
                factor = (Date.now() - start) / duration;
                // get interpolation factor
                if (factor >= 1) {
                    clearInterval(timer);
                    // stop animation
                    factor = 1;
                }
                y = factor * delta + offset;
                window.scrollBy(0, y - window.pageYOffset);
            }
            timer = setInterval(step, 10);
            return timer;
        };
    }();
    var title = document.getElementById("title");
    title.addEventListener("click", function() {
        smoothScrollTo(0, 0);
    }, false);
    window.onload = function() {
        smoothScrollTo(0, 0);
    };
});//end of ready function

var app = angular.module("poolApp", []);

app.controller("MainController", function($scope) {
    $scope.poolbase = [ {
        title: "Google",
        tags: "googling tips",
        links: [ {
            name: "Google efficiently",
            href: "http://www.makeuseof.com/tag/google-power-user/"
        } ]
    },{
        title: "Technical Interview Q&A",
        tags: "interviews questions tr technical awesome",
        links: [ {
            name: "Awesome Interviews",
            href: "https://github.com/MaximAbramchuck/awesome-interviews"
        } ]
    }, {
        title: "Html/Html5",
        tags: "markup",
        links: [ {
            name: "Introduction to HTML",
            href: "https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Introduction#History_of_HTML"
        }, {
            name: "Learn HTML",
            href: "http://learn.shayhowe.com/html-css/getting-to-know-html/"
        }, {
            name: "HTML5 in 5 mins",
            href: "https://msdn.microsoft.com/en-us/hh549253.aspx"
        }, {
            name: "HTML5-Canvas tutorial",
            href: "http://www.html5canvastutorials.com/"
        }, {
            name: "HTML5 + your browser compatibility",
            href: "https://html5test.com/"
        } ]
    }, {
        title: "Free Responsive Web Templates",
        tags: "website webpage",
        links: [ {
            name: "HTML5UP",
            href: "http://html5up.net/"
        }, {
            name: "Get Template",
            href: "http://www.gettemplate.com/"
        }, {
            name: "Foundation Templates",
            href: "http://foundation.zurb.com/templates.html"
        }, {
            name: "Bootstrap Templates",
            href: "http://startbootstrap.com/template-categories/all/"
        } ]
    }, {
        title: "Css/Css3",
        tags: "",
        links: [ {
            name: "Learn CSS",
            href: "http://learn.shayhowe.com/html-css/getting-to-know-css/"
        }, {
            name: "Learn Layout",
            href: "http://learnlayout.com/"
        }, {
            name: "CSS Properties",
            href: "http://www.cssportal.com/css-properties/index.php"
        }, {
            name: "30 CSS selectors to remember",
            href: "http://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048"
        }, {
            name: "Game on CSS selectors",
            href: "http://flukeout.github.io/"
        } ]
    }, {
        title: "Choosing color for text",
        tags: "colors",
        links: [ {
            name: "Choose right color",
            href: "http://colorsafe.co/"
        }, {
            name: "Pick color online",
            href: "http://colourco.de/"
        } ]
    }, {
        title: "Css Generators",
        tags: "generator",
        links: [ {
            name: "Online CSS3 generator",
            href: "http://enjoycss.com/"
        }, {
            name: "CSS Matic",
            href: "http://www.cssmatic.com/"
        }, {
            name: "Generate CSS arrow",
            href: "http://cssarrowplease.com/"
        }, {
            name: "CSS Shapes",
            href: "https://css-tricks.com/examples/ShapesOfCSS/"
        }, {
            name: "CSS gradient generator",
            href: "http://www.colorzilla.com/gradient-editor/"
        } ]
    }, {
        title: "Css Frameworks",
        tags: "frameworks",
        links: [ {
            name: "Bootstrap",
            href: "http://getbootstrap.com/"
        }, {
            name: "Foundation",
            href: "http://foundation.zurb.com/"
        }, {
            name: "Metro UI",
            href: "http://metroui.org.ua/"
        }, {
            name: "Furtive-CSS micro framework",
            href: "http://furtive.co/"
        } ]
    }, {
        title: "JavaScript",
        tags: "js",
        links: [ {
            name: "All about JavaScript",
            href: "http://jstherightway.org/"
        }, {
            name: "Interactive way to learn JS",
            href: "http://www.codecademy.com/en/tracks/javascript"
        }, {
            name: "Learn Object oriented JavaScript",
            href: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript"
        }, {
            name: "Javascript Char codes",
            href: "http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes"
        }, {
            name: "jsPerf - compare js snippets ",
            href: "https://jsperf.com/"
        } ]
    }, {
        title: "Javascript Libraries",
        tags: "js jquery",
        links: [ {
            name: "Interactive way to learn jQuery",
            href: "http://try.jquery.com/"
        } ]
    }, {
        title: "Javascript Frameworks",
        tags: "js",
        links: [ {
            name: "AngularJS in 60minutes",
            href: "http://fastandfluid.com/publicdownloads/AngularJSIn60MinutesIsh_DanWahlin_May2013.pdf"
        }, {
            name: "AngularJS examples",
            href: "http://tutorialzine.com/2013/08/learn-angularjs-5-examples/"
        } ]
    }, {
        title: "Regular Expressions",
        tags: "regex",
        links: [ {
            name: "Regexone - learn interactively",
            href: "http://regexone.com/"
        }, {
            name: "Online Regex builder",
            href: "http://regexr.com/"
        } ]
    }, {
        title: "Learn Command Line Interface",
        tags: "cli cmd",
        links: [ {
            name: "Learn CLI the hard way",
            href: "http://cli.learncodethehardway.org/book/"
        } ]
    }, {
        title: "Introduction to programming",
        tags: "beginner coding",
        links: [ {
            name: "Lets Play the game",
            href: "http://learn.code.org/hoc/1"
        } ]
    }, {
        title: "One stop for programming",
        tags: "code learn api",
        links: [ {
            name: "Learn X in Y minutes",
            href: "http://learnxinyminutes.com/"
        }, {
            name: "Api hub",
            href: "http://overapi.com/"
        } ]
    }, {
        title: "C",
        tags: "compiled",
        links: [ {
            name: "Learn C the hard way",
            href: "http://c.learncodethehardway.org/book/"
        }, {
            name: "Basic c programs",
            href: "http://www.programiz.com/c-programming/examples"
        } ]
    }, {
        title: "Python",
        tags: "interpreted",
        links: [ {
            name: "Learn python the hard way",
            href: "http://learnpythonthehardway.org/book/"
        }, {
            name: "Basic python programs",
            href: "http://www.programiz.com/python-programming/examples"
        } ]
    }, {
        title: "Ruby",
        tags: "interpreted",
        links: [ {
            name: "Learn ruby the hard way",
            href: "http://learnrubythehardway.org/book/"
        }, {
            name: "Interactive way to learn ruby",
            href: "http://tryruby.org/levels/1/challenges/0"
        } ]
    }, {
        title: "Git",
        tags: "version control system vcs",
        links: [ {
            name: "Git in 15mins",
            href: "https://try.github.io"
        } ]
    }, {
        title: "Online Tutorials",
        tags: "free online all science technology",
        links: [ {
            name: "Scotch",
            href: "https://scotch.io/"
        }, {
            name: "Codecademy",
            href: "http://codecademy.com/"
        }, {
            name: "khanacademy",
            href: "https://www.khanacademy.org/"
        }, {
            name: "Codeschool",
            href: "https://www.codeschool.com/"
        }, {
            name: "Tutorials point",
            href: "http://tutorialspoint.com/"
        } ]
    }, {
        title: "Magazines for Web-development",
        tags: "web magazines smashing alistapart",
        links: [ {
            name: "Smashing magazine",
            href: "http://www.smashingmagazine.com/"
        }, {
            name: "Alistapart",
            href: "http://alistapart.com/topics"
        } ]
    }, {
        title: "Website Building",
        tags: "websites",
        links: [ {
            name: "Website creation guidelines by Google",
            href: "https://support.google.com/webmasters/answer/6001102"
        } ]
    }, {
        title: "Miscellaneous",
        tags: "grunt",
        links: [ {
            name: "Can I Use",
            href: "http://caniuse.com/"
        },{
            name: "Getting started with Grunt",
            href: "https://scotch.io/tutorials/a-simple-guide-to-getting-started-with-grunt"
        }, {
            name: "Grunt-Smashing Magazine",
            href: "http://www.smashingmagazine.com/2013/10/get-up-running-grunt/"
        }, {
            name: "Free e-books",
            href: "https://www.syncfusion.com/resources/techportal/ebooks"
        } ]
    } ];
    $scope.searchFilter = function(obj) {
        var re = new RegExp($scope.search, "i");
        return !$scope.search || re.test(obj.title) || re.test(obj.tags);
    };
});
<commit_msg>angular links updated<commit_after>document.addEventListener("DOMContentLoaded", function() {
    window.smoothScrollTo = function() {
        var timer, start, factor;
        return function(target, duration) {
            var offset = window.pageYOffset, delta = target - window.pageYOffset;
            // Y-offset difference
            duration = duration || 700;
            // default 1 sec animation
            start = Date.now();
            // get start time
            factor = 0;
            if (timer) {
                clearInterval(timer);
            }
            function step() {
                var y;
                factor = (Date.now() - start) / duration;
                // get interpolation factor
                if (factor >= 1) {
                    clearInterval(timer);
                    // stop animation
                    factor = 1;
                }
                y = factor * delta + offset;
                window.scrollBy(0, y - window.pageYOffset);
            }
            timer = setInterval(step, 10);
            return timer;
        };
    }();
    var title = document.getElementById("title");
    title.addEventListener("click", function() {
        smoothScrollTo(0, 0);
    }, false);
    window.onload = function() {
        smoothScrollTo(0, 0);
    };
});//end of ready function

var app = angular.module("poolApp", []);

app.controller("MainController", function($scope) {
    $scope.poolbase = [ {
        title: "Google",
        tags: "googling tips",
        links: [ {
            name: "Google efficiently",
            href: "http://www.makeuseof.com/tag/google-power-user/"
        } ]
    },{
        title: "Technical Interview Q&A",
        tags: "interviews questions tr technical awesome",
        links: [ {
            name: "Awesome Interviews",
            href: "https://github.com/MaximAbramchuck/awesome-interviews"
        } ]
    }, {
        title: "Html/Html5",
        tags: "markup",
        links: [ {
            name: "Introduction to HTML",
            href: "https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Introduction#History_of_HTML"
        }, {
            name: "Learn HTML",
            href: "http://learn.shayhowe.com/html-css/getting-to-know-html/"
        }, {
            name: "HTML5 in 5 mins",
            href: "https://msdn.microsoft.com/en-us/hh549253.aspx"
        }, {
            name: "HTML5-Canvas tutorial",
            href: "http://www.html5canvastutorials.com/"
        }, {
            name: "HTML5 + your browser compatibility",
            href: "https://html5test.com/"
        } ]
    }, {
        title: "Free Responsive Web Templates",
        tags: "website webpage",
        links: [ {
            name: "HTML5UP",
            href: "http://html5up.net/"
        }, {
            name: "Get Template",
            href: "http://www.gettemplate.com/"
        }, {
            name: "Foundation Templates",
            href: "http://foundation.zurb.com/templates.html"
        }, {
            name: "Bootstrap Templates",
            href: "http://startbootstrap.com/template-categories/all/"
        } ]
    }, {
        title: "Css/Css3",
        tags: "",
        links: [ {
            name: "Learn CSS",
            href: "http://learn.shayhowe.com/html-css/getting-to-know-css/"
        }, {
            name: "Learn Layout",
            href: "http://learnlayout.com/"
        }, {
            name: "CSS Properties",
            href: "http://www.cssportal.com/css-properties/index.php"
        }, {
            name: "30 CSS selectors to remember",
            href: "http://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048"
        }, {
            name: "Game on CSS selectors",
            href: "http://flukeout.github.io/"
        } ]
    }, {
        title: "Choosing color for text",
        tags: "colors",
        links: [ {
            name: "Choose right color",
            href: "http://colorsafe.co/"
        }, {
            name: "Pick color online",
            href: "http://colourco.de/"
        } ]
    }, {
        title: "Css Generators",
        tags: "generator",
        links: [ {
            name: "Online CSS3 generator",
            href: "http://enjoycss.com/"
        }, {
            name: "CSS Matic",
            href: "http://www.cssmatic.com/"
        }, {
            name: "Generate CSS arrow",
            href: "http://cssarrowplease.com/"
        }, {
            name: "CSS Shapes",
            href: "https://css-tricks.com/examples/ShapesOfCSS/"
        }, {
            name: "CSS gradient generator",
            href: "http://www.colorzilla.com/gradient-editor/"
        } ]
    }, {
        title: "Css Frameworks",
        tags: "frameworks",
        links: [ {
            name: "Bootstrap",
            href: "http://getbootstrap.com/"
        }, {
            name: "Foundation",
            href: "http://foundation.zurb.com/"
        }, {
            name: "Metro UI",
            href: "http://metroui.org.ua/"
        }, {
            name: "Furtive-CSS micro framework",
            href: "http://furtive.co/"
        } ]
    }, {
        title: "JavaScript",
        tags: "js",
        links: [ {
            name: "All about JavaScript",
            href: "http://jstherightway.org/"
        }, {
            name: "Interactive way to learn JS",
            href: "http://www.codecademy.com/en/tracks/javascript"
        }, {
            name: "Learn Object oriented JavaScript",
            href: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript"
        }, {
            name: "Javascript Char codes",
            href: "http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes"
        }, {
            name: "jsPerf - compare js snippets ",
            href: "https://jsperf.com/"
        } ]
    }, {
        title: "Javascript Libraries",
        tags: "js jquery",
        links: [ {
            name: "Interactive way to learn jQuery",
            href: "http://try.jquery.com/"
        } ]
    }, {
        title: "Javascript Frameworks",
        tags: "js",
        links: [ {
            name: "AngularJS in 60minutes",
            href: "http://fastandfluid.com/publicdownloads/AngularJSIn60MinutesIsh_DanWahlin_May2013.pdf"
        }, {
            name: "AngularJS examples",
            href: "http://tutorialzine.com/2013/08/learn-angularjs-5-examples/"
        }, {
            name: "Best practices for building an angular app",
            href: "https://github.com/johnpapa/angular-styleguide"
        } ]
    }, {
        title: "Regular Expressions",
        tags: "regex",
        links: [ {
            name: "Regexone - learn interactively",
            href: "http://regexone.com/"
        }, {
            name: "Online Regex builder",
            href: "http://regexr.com/"
        } ]
    }, {
        title: "Learn Command Line Interface",
        tags: "cli cmd",
        links: [ {
            name: "Learn CLI the hard way",
            href: "http://cli.learncodethehardway.org/book/"
        } ]
    }, {
        title: "Introduction to programming",
        tags: "beginner coding",
        links: [ {
            name: "Lets Play the game",
            href: "http://learn.code.org/hoc/1"
        } ]
    }, {
        title: "One stop for programming",
        tags: "code learn api",
        links: [ {
            name: "Learn X in Y minutes",
            href: "http://learnxinyminutes.com/"
        }, {
            name: "Api hub",
            href: "http://overapi.com/"
        } ]
    }, {
        title: "C",
        tags: "compiled",
        links: [ {
            name: "Learn C the hard way",
            href: "http://c.learncodethehardway.org/book/"
        }, {
            name: "Basic c programs",
            href: "http://www.programiz.com/c-programming/examples"
        } ]
    }, {
        title: "Python",
        tags: "interpreted",
        links: [ {
            name: "Learn python the hard way",
            href: "http://learnpythonthehardway.org/book/"
        }, {
            name: "Basic python programs",
            href: "http://www.programiz.com/python-programming/examples"
        } ]
    }, {
        title: "Ruby",
        tags: "interpreted",
        links: [ {
            name: "Learn ruby the hard way",
            href: "http://learnrubythehardway.org/book/"
        }, {
            name: "Interactive way to learn ruby",
            href: "http://tryruby.org/levels/1/challenges/0"
        } ]
    }, {
        title: "Git",
        tags: "version control system vcs",
        links: [ {
            name: "Git in 15mins",
            href: "https://try.github.io"
        } ]
    }, {
        title: "Online Tutorials",
        tags: "free online all science technology",
        links: [ {
            name: "Scotch",
            href: "https://scotch.io/"
        }, {
            name: "Codecademy",
            href: "http://codecademy.com/"
        }, {
            name: "khanacademy",
            href: "https://www.khanacademy.org/"
        }, {
            name: "Codeschool",
            href: "https://www.codeschool.com/"
        }, {
            name: "Tutorials point",
            href: "http://tutorialspoint.com/"
        } ]
    }, {
        title: "Magazines for Web-development",
        tags: "web magazines smashing alistapart",
        links: [ {
            name: "Smashing magazine",
            href: "http://www.smashingmagazine.com/"
        }, {
            name: "Alistapart",
            href: "http://alistapart.com/topics"
        } ]
    }, {
        title: "Website Building",
        tags: "websites",
        links: [ {
            name: "Website creation guidelines by Google",
            href: "https://support.google.com/webmasters/answer/6001102"
        } ]
    }, {
        title: "Miscellaneous",
        tags: "grunt",
        links: [ {
            name: "Can I Use",
            href: "http://caniuse.com/"
        },{
            name: "Getting started with Grunt",
            href: "https://scotch.io/tutorials/a-simple-guide-to-getting-started-with-grunt"
        }, {
            name: "Grunt-Smashing Magazine",
            href: "http://www.smashingmagazine.com/2013/10/get-up-running-grunt/"
        }, {
            name: "Free e-books",
            href: "https://www.syncfusion.com/resources/techportal/ebooks"
        } ]
    } ];
    $scope.searchFilter = function(obj) {
        var re = new RegExp($scope.search, "i");
        return !$scope.search || re.test(obj.title) || re.test(obj.tags);
    };
});
<|endoftext|>


<commit_before>$(document).ready(function(){
  // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
  $('.modal-trigger').leanModal({
    dismissible: true, // Modal can be dismissed by clicking outside of the modal
  });

  $("#add-entry").hide();

  // register user
  $('#register').click(function(){
    var credentials = {
      username: $('#reg-email').val(),
      password: $('#reg-password').val(),
      confirmpassword: $('#reg-confirm').val()
    };
    if (credentials.password !== credentials.confirmpassword) {
      var $toastContent = $('Registration Unsuccessful');
      Materialize.toast($toastContent, 5000);
    } else {
      api.register(credentials, function (err) {
        if (err) { console.error(err); }
      });
    }
  }); // end submit register click handler

  // login user
  $('#login').click(function(){
    var credentials = {
      username: $('#log-email').val(),
      password: $('#log-password').val()
    };
    var loginCb = function(err) {
      if (err){
        console.error(err);
        return;
      }
      $('#current-user').html('Welcome, ' + $('#log-email').val() + '! ');
    };
    api.login(credentials, loginCb);
  }); // end submit login click handler

  // sync openWeather
  $('#openWeather').click(function() {
    api.sync();
  });

  $('#add-entry-button').click(function(){
    // show form
    $("#add-entry").show();
  });

  $('.cancel').click(function(){
    // hide form
    $("#add-entry").hide();
    });

  $('#save-entry-button').click(function(){
    var newEntry = {
      "entry":{
        "pain":$("#pain").val(),
        "mood":$("#mood").val(),
        "note":$("#note").val(),
        "symptoms":$("#symptoms").val(),
        "medication":$("#medication").val(),
      }
    };
    api.createEntry(newEntry,
      function (err) {
        if (err) {
          console.error(err);
        }
      });
    // hide form
    $("#add-entry").hide();
    });

  // list health entry button click handler
  $('#list-entries-button').click(function(){
    api.showList(function (err, data) {
      if (err) {
        console.error(err);
      }});
    });

  // chart.js
  var lineChartData = {
    labels : [],
    datasets : [
      {
        label: "My First dataset",
        fillColor : "rgba(220,220,220,0.2)",
        strokeColor : "rgba(220,220,220,1)",
        pointColor : "rgba(220,220,220,1)",
        pointStrokeColor : "#fff",
        pointHighlightFill : "#fff",
        pointHighlightStroke : "rgba(220,220,220,1)",
        data : []
      }
    ]
  };

  window.onload = function(){
    // var ctx = document.getElementById("canvas").getContext("2d");
    var ctx = $("#canvas").get(0).getContext("2d");

    // pressure data
    api.pressure(function (err, data) {
      if (err) {
        console.error(err);
      } else {
        lineChartData.datasets[0].data = data.pressures;
        lineChartData.labels = data.createdAts;

        window.myLine = new Chart(ctx).Line(lineChartData, {
          responsive: true
        });
      }
    });

  };

  }); // end document ready
<commit_msg>can create new health log entry<commit_after>$(document).ready(function(){
  // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
  $('.modal-trigger').leanModal({
    dismissible: true, // Modal can be dismissed by clicking outside of the modal
  });

  $("#add-entry").hide();

  // register user
  $('#register').click(function(){
    var credentials = {
      username: $('#reg-email').val(),
      password: $('#reg-password').val(),
      confirmpassword: $('#reg-confirm').val()
    };
    if (credentials.password !== credentials.confirmpassword) {
      var $toastContent = $('Registration Unsuccessful');
      Materialize.toast($toastContent, 5000);
    } else {
      api.register(credentials, function (err) {
        if (err) { console.error(err); }
      });
    }
  }); // end submit register click handler

  // login user
  $('#login').click(function(){
    var credentials = {
      username: $('#log-email').val(),
      password: $('#log-password').val()
    };
    var loginCb = function(err) {
      if (err){
        console.error(err);
        return;
      }
      $('#current-user').html('Welcome, ' + $('#log-email').val() + '! ');
    };
    api.login(credentials, loginCb);
  }); // end submit login click handler

  // sync openWeather
  $('#openWeather').click(function() {
    api.sync();
  });

  $('#add-entry-button').click(function(){
    // show form
    $("#add-entry").show();
  });

  $('.cancel').click(function(){
    // hide form
    $("#add-entry").hide();
    });

  $('#save-entry-button').click(function(){
    var newEntry = {
        "pain":$("#pain").val(),
        "mood":$("#mood").val(),
        "note":$("#note").val(),
        "symptoms":$("#symptoms").val(),
        "medication":$("#medication").val(),
    };
    api.createEntry(newEntry,
      function (err) {
        if (err) {
          console.error(err);
        }
      });
    // hide form
    $("#add-entry").hide();
    });

  // list health entry button click handler
  $('#list-entries-button').click(function(){
    api.showList(function (err, data) {
      if (err) {
        console.error(err);
      }});
    });

  // chart.js
  var lineChartData = {
    labels : [],
    datasets : [
      {
        label: "My First dataset",
        fillColor : "rgba(220,220,220,0.2)",
        strokeColor : "rgba(220,220,220,1)",
        pointColor : "rgba(220,220,220,1)",
        pointStrokeColor : "#fff",
        pointHighlightFill : "#fff",
        pointHighlightStroke : "rgba(220,220,220,1)",
        data : []
      }
    ]
  };

  window.onload = function(){
    // var ctx = document.getElementById("canvas").getContext("2d");
    var ctx = $("#canvas").get(0).getContext("2d");

    // pressure data
    api.pressure(function (err, data) {
      if (err) {
        console.error(err);
      } else {
        lineChartData.datasets[0].data = data.pressures;
        lineChartData.labels = data.createdAts;

        window.myLine = new Chart(ctx).Line(lineChartData, {
          responsive: true
        });
      }
    });

  };

  }); // end document ready
<|endoftext|>