<commit_before>$(function() {
  $(".collapse-link").on("click", function(e) {
    e.preventDefault();
    $(this).next(".collapse").toggle(300, function(test) {
      if ($(this).css("display") == "block") {
        $(this).addClass("in");
        $(this).prev(".collapse-link").find(".fa").removeClass("fa-caret-right").addClass("fa-caret-down");
      } else {
        $(this).removeClass("in");
        $(this).prev(".collapse-link").find(".fa").removeClass("fa-caret-down").addClass("fa-caret-right");
      }
    });
  });

  var csrftoken = $('meta[name=csrf-token]').attr('content');

  $.ajaxSetup({
    beforeSend: function(xhr, settings) {
      if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
        xhr.setRequestHeader("X-CSRFToken", csrftoken);
      }
    }
  });

  $(".create-alert .btn").on("click", function(e) {

    var q = $(this).data('q'),
    committee_id = $(this).data('committee') || "",
    content_type = $(this).data('type');

    $.post(
      '/user/saved-search/',
      {
        q: q,
        committee_id: committee_id,
        content_type: content_type
      }
    ).done(function(resp) {
      $('.create-alert').addClass('hidden');
      $('.remove-alert').removeClass('hidden').find('.btn').data('id', resp.id);
      ga('send', 'event', 'user', 'add-search-alert');
    });
  });

  $(".remove-alert .btn").on("click", function(e) {

    var id = $(this).data('id') || "";

    $.post(
      '/user/saved-search/' + id + '/delete'
    ).always(function(resp) {
      $('.remove-alert').addClass('hidden').find('.btn').data('id', '');
      $('.create-alert').removeClass('hidden');
      ga('send', 'event', 'user', 'remove-search-alert');
    });
  });

  $(".chosen").chosen({width: "100%"});
  $('[title]').tooltip();
});

// handle 404 page
$(function() {
  if ($('#page-404').length > 0) {
    ga('send', 'event', '404', document.location.pathname, document.referrer);
  }
});

$(function() {
  // show more buttons on home page
  $('.show-more').on('click', function() {
    var $btn = $(this);
    var $target = $btn.prev();

    if ($target.hasClass('expanded')) {
      $target.removeClass('expanded');
      $btn.removeClass('show-less');
      $btn.text('Show more');
    } else {
      $target.addClass('expanded');
      $btn.addClass('show-less');
      $btn.text('Show less');
      if ($target.hasClass('feature-cards')) {
      	ga('send', 'event', 'featured', 'show-more');
      } else {
      	switch ($target.parent().attr('class').replace('subsection', '').trim()) {
      		case 'committee-meetings':
      			ga('send', 'event', 'committee-meetings', 'show-more');
      			break;
      		case 'bills':
      			ga('send', 'event', 'bills', 'show-more');
      			break;
      		case 'questions':
      			ga('send', 'event', 'questions', 'show-more');
      			break;
      	}
      }
    }
  });
});

// user creation form
$('form[name=register_user_form]').on('submit', function() {
  $(this).find('input[type=submit]').prop('disabled', true);
});

$(function() {
  var initialised = false;
  var initialise = function() {
    SC.initialize({
      client_id: $('#soundcloud-container').data('soundcloud-id')
    });
  };
  var $audioLinks = $('a.audio');

  $audioLinks.each(function(i, a) {
    a = $(a);
    if (a.data('soundcloud-uri')) {
      var uri = a.data('soundcloud-uri');
      console.log('registering click');
      a.on('click', function(e) {
        console.log('clicked');
        if (!initialised) initialise();
        SC.oEmbed(uri, {
          element: document.getElementById('soundcloud-container'),
          maxheight: 166,
          show_comments: false,
          auto_play: false,
        });
        return false;
      });
    }

    // Convert first link to soundcloud embed
    var firstUri = $audioLinks.first().data('soundcloud-uri');

    if(firstUri) {
      SC.oEmbed(firstUri, {
        element: document.getElementById('soundcloud-container'),
        maxheight: 166,
        show_comments: false,
        auto_play: false,
      });
    }
  });
});

$(function() {
  $(".page-share.facebook").on("click", function(e) {
    e.preventDefault();
    window.open("https://www.facebook.com/sharer/sharer.php?u="+window.location.href,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'facebook', 'share', url);
  });

  $(".page-share.twitter").on("click", function(e) {
    e.preventDefault();
    window.open("https://twitter.com/intent/tweet?&url="+window.location.href,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'twitter', 'share', url);
  });

  $(".page-share.linkedin").on("click", function(e) {
    e.preventDefault();
    window.open("https://www.linkedin.com/shareArticle?mini=true&source=PMG&url="+window.location.href,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'linkedin', 'share', url);
  });
});<commit_msg>define url<commit_after>$(function() {
  $(".collapse-link").on("click", function(e) {
    e.preventDefault();
    $(this).next(".collapse").toggle(300, function(test) {
      if ($(this).css("display") == "block") {
        $(this).addClass("in");
        $(this).prev(".collapse-link").find(".fa").removeClass("fa-caret-right").addClass("fa-caret-down");
      } else {
        $(this).removeClass("in");
        $(this).prev(".collapse-link").find(".fa").removeClass("fa-caret-down").addClass("fa-caret-right");
      }
    });
  });

  var csrftoken = $('meta[name=csrf-token]').attr('content');

  $.ajaxSetup({
    beforeSend: function(xhr, settings) {
      if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
        xhr.setRequestHeader("X-CSRFToken", csrftoken);
      }
    }
  });

  $(".create-alert .btn").on("click", function(e) {

    var q = $(this).data('q'),
    committee_id = $(this).data('committee') || "",
    content_type = $(this).data('type');

    $.post(
      '/user/saved-search/',
      {
        q: q,
        committee_id: committee_id,
        content_type: content_type
      }
    ).done(function(resp) {
      $('.create-alert').addClass('hidden');
      $('.remove-alert').removeClass('hidden').find('.btn').data('id', resp.id);
      ga('send', 'event', 'user', 'add-search-alert');
    });
  });

  $(".remove-alert .btn").on("click", function(e) {

    var id = $(this).data('id') || "";

    $.post(
      '/user/saved-search/' + id + '/delete'
    ).always(function(resp) {
      $('.remove-alert').addClass('hidden').find('.btn').data('id', '');
      $('.create-alert').removeClass('hidden');
      ga('send', 'event', 'user', 'remove-search-alert');
    });
  });

  $(".chosen").chosen({width: "100%"});
  $('[title]').tooltip();
});

// handle 404 page
$(function() {
  if ($('#page-404').length > 0) {
    ga('send', 'event', '404', document.location.pathname, document.referrer);
  }
});

$(function() {
  // show more buttons on home page
  $('.show-more').on('click', function() {
    var $btn = $(this);
    var $target = $btn.prev();

    if ($target.hasClass('expanded')) {
      $target.removeClass('expanded');
      $btn.removeClass('show-less');
      $btn.text('Show more');
    } else {
      $target.addClass('expanded');
      $btn.addClass('show-less');
      $btn.text('Show less');
      if ($target.hasClass('feature-cards')) {
      	ga('send', 'event', 'featured', 'show-more');
      } else {
      	switch ($target.parent().attr('class').replace('subsection', '').trim()) {
      		case 'committee-meetings':
      			ga('send', 'event', 'committee-meetings', 'show-more');
      			break;
      		case 'bills':
      			ga('send', 'event', 'bills', 'show-more');
      			break;
      		case 'questions':
      			ga('send', 'event', 'questions', 'show-more');
      			break;
      	}
      }
    }
  });
});

// user creation form
$('form[name=register_user_form]').on('submit', function() {
  $(this).find('input[type=submit]').prop('disabled', true);
});

$(function() {
  var initialised = false;
  var initialise = function() {
    SC.initialize({
      client_id: $('#soundcloud-container').data('soundcloud-id')
    });
  };
  var $audioLinks = $('a.audio');

  $audioLinks.each(function(i, a) {
    a = $(a);
    if (a.data('soundcloud-uri')) {
      var uri = a.data('soundcloud-uri');
      console.log('registering click');
      a.on('click', function(e) {
        console.log('clicked');
        if (!initialised) initialise();
        SC.oEmbed(uri, {
          element: document.getElementById('soundcloud-container'),
          maxheight: 166,
          show_comments: false,
          auto_play: false,
        });
        return false;
      });
    }

    // Convert first link to soundcloud embed
    var firstUri = $audioLinks.first().data('soundcloud-uri');

    if(firstUri) {
      SC.oEmbed(firstUri, {
        element: document.getElementById('soundcloud-container'),
        maxheight: 166,
        show_comments: false,
        auto_play: false,
      });
    }
  });
});

$(function() {
  url = window.location.href
  $(".page-share.facebook").on("click", function(e) {
    e.preventDefault();
    window.open("https://www.facebook.com/sharer/sharer.php?u="+url,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'facebook', 'share', url);
  });

  $(".page-share.twitter").on("click", function(e) {
    e.preventDefault();
    window.open("https://twitter.com/intent/tweet?&url="+url,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'twitter', 'share', url);
  });

  $(".page-share.linkedin").on("click", function(e) {
    e.preventDefault();
    window.open("https://www.linkedin.com/shareArticle?mini=true&source=PMG&url="+url,
      "share", "width=600, height=400, scrollbars=no");
      ga('send', 'social', 'linkedin', 'share', url);
  });
});<|endoftext|>


<commit_before>const audioData = require("../audioData");
const audioController = require('../helpers/audioController');
const constants = require('../constants');

module.exports = {
    /*
     *  All Intent Handlers for state : STREAMING
     */
    'AMAZON.NextIntent': function () {
        this.response.speak('This is radio, you have to wait for next track to play.');
        this.emit(':responseReady');
    },
    'AMAZON.PreviousIntent': function () {
        this.response.speak('This is radio, you can not go back in the playlist');
        this.emit(':responseReady');
    },

    'AMAZON.StopIntent': function () { audioController.stop(this) },
    'AMAZON.PauseIntent': function () { this.emit('AMAZON.StopIntent'); },
    'AMAZON.CancelIntent': function () { this.emit('AMAZON.StopIntent'); },

    'AMAZON.ResumeIntent': function () { audioController.play(this, `resuming ${audioData.title}`) },

    'AMAZON.StartOverIntent': function () {
        this.response.speak('This is radio, you can not do that.  You can say stop or pause to stop listening.');
        this.emit(':responseReady');

    },
    'AMAZON.LoopOnIntent': function () { this.emit('AMAZON.StartOverIntent'); },
    'AMAZON.LoopOffIntent': function () { this.emit('AMAZON.StartOverIntent');},
    'AMAZON.ShuffleOnIntent': function () { this.emit('AMAZON.StartOverIntent');},
    'AMAZON.ShuffleOffIntent': function () { this.emit('AMAZON.StartOverIntent');},

    /*
     *  All Requests are received using a Remote Control. Calling corresponding handlers for each of them.
     */
    'PlayCommandIssued': function () { audioController.play(this, 'Playing.') },
    'PauseCommandIssued': function () { audioController.stop(this) },

    /**
     * Unhandled handler - resets the state and stops the session
     *
     * @function
     */
    "Unhandled": function () {
        helpers.logHandler(this.name);

        this.handler.state = constants.states.START_MODE;

        this.emitWithState(this.event.request.intent.name);
    }
};<commit_msg>add PlayAudio to streaming handlers<commit_after>const audioData = require("../audioData");
const audioController = require('../helpers/audioController');
const constants = require('../constants');

module.exports = {
    'PlayAudio' : function () {
        console.log(this.name);
        audioController.play(this, audioData.title);
    },

    /*
     *  All Intent Handlers for state : STREAMING
     */
    'AMAZON.NextIntent': function () {
        this.response.speak('This is radio, you have to wait for next track to play.');
        this.emit(':responseReady');
    },
    'AMAZON.PreviousIntent': function () {
        this.response.speak('This is radio, you can not go back in the playlist');
        this.emit(':responseReady');
    },

    'AMAZON.StopIntent': function () { audioController.stop(this) },
    'AMAZON.PauseIntent': function () { this.emit('AMAZON.StopIntent'); },
    'AMAZON.CancelIntent': function () { this.emit('AMAZON.StopIntent'); },

    'AMAZON.ResumeIntent': function () { audioController.play(this, `resuming ${audioData.title}`) },

    'AMAZON.StartOverIntent': function () {
        this.response.speak('This is radio, you can not do that.  You can say stop or pause to stop listening.');
        this.emit(':responseReady');

    },
    'AMAZON.LoopOnIntent': function () { this.emit('AMAZON.StartOverIntent'); },
    'AMAZON.LoopOffIntent': function () { this.emit('AMAZON.StartOverIntent');},
    'AMAZON.ShuffleOnIntent': function () { this.emit('AMAZON.StartOverIntent');},
    'AMAZON.ShuffleOffIntent': function () { this.emit('AMAZON.StartOverIntent');},

    /*
     *  All Requests are received using a Remote Control. Calling corresponding handlers for each of them.
     */
    'PlayCommandIssued': function () { audioController.play(this, 'Playing.') },
    'PauseCommandIssued': function () { audioController.stop(this) },

    /**
     * Unhandled handler - resets the state and stops the session
     *
     * @function
     */
    "Unhandled": function () {
        helpers.logHandler(this.name);

        this.handler.state = constants.states.START_MODE;

        this.emitWithState(this.event.request.intent.name);
    }
};<|endoftext|>


<commit_before>/*global require, exports*/
var util = require('util'),
    _ = require('underscore'),
    extendWithGettersAndSetters = require('../util/extendWithGettersAndSetters'),
    uglifyAst = require('../util/uglifyAst'),
    Relation = require('./Relation');

function JavaScriptOneGetStaticUrl(config) {
    Relation.call(this, config);
}

util.inherits(JavaScriptOneGetStaticUrl, Relation);

extendWithGettersAndSetters(JavaScriptOneGetStaticUrl.prototype, {
    inline: function () {
        Relation.prototype.inline.call(this);
        this.node[2] = [this.to.toAst()];
        this.from.markDirty();
        return this;
    },

    attach: function (asset, position, adjacentRelation) {
        throw new Error("Not implemented");
    },

    detach: function () {
        throw new Error("Not implemented");
    }
});

module.exports = JavaScriptOneGetStaticUrl;
<commit_msg>relations.JavaScriptOneGetStaticUrl: Added support for omitting the one.getStaticUrl(...) function call itself. It'll save some bytes, but render the relation unrecognizable.<commit_after>/*global require, exports*/
var util = require('util'),
    _ = require('underscore'),
    extendWithGettersAndSetters = require('../util/extendWithGettersAndSetters'),
    uglifyAst = require('../util/uglifyAst'),
    Relation = require('./Relation');

function JavaScriptOneGetStaticUrl(config) {
    Relation.call(this, config);
}

util.inherits(JavaScriptOneGetStaticUrl, Relation);

extendWithGettersAndSetters(JavaScriptOneGetStaticUrl.prototype, {
    inline: function () {
        Relation.prototype.inline.call(this);
        var ast = this.to.toAst();
        if (!this.omitFunctionCall) {
            ast = [
                'call',
                [
                    'dot',
                    [
                        'name',
                        'one'
                    ],
                    'getStaticUrl'
                ],
                [
                    ast
                ]
            ];
        }
        Array.prototype.splice.apply(this.node, [0, this.node.length].concat(ast));
        this.from.markDirty();
        return this;
    },

    attach: function (asset, position, adjacentRelation) {
        throw new Error("Not implemented");
    },

    detach: function () {
        throw new Error("Not implemented");
    }
});

module.exports = JavaScriptOneGetStaticUrl;
<|endoftext|>


<commit_before>/*
 * Jquery Enlargeable plugin - https://github.com/popallo/enlargeable
 * Creation => 16-10-2013
 * Update => 22-10-2013
 * © 2013, Licensed MIT (https://github.com/popallo/enlargeable/blob/master/LICENSE)
 * @author popallo
 * @version 0.9.2
 *
 * DEPENDS : jquery >= 1.10.x, jquery ui >= 1.10.x (optional)
 *
 * HOW TO : $(element).enlargeable({option:value});
 *
 * HTML EXAMPLE 1 :
 *

 *

 *
 * HTML EXAMPLE 2 :
 *

 *

 *

 *
 * TODO make enlargeable fullscreenable... ^^
 * TODO make enlargeable skinnable... ^^
 * TODO make it works for "enlarge" or "reduce" size first
 * TODO make the plugin more flexible
 * TODO more and more and more ...
 *
 */
;(function ( $ ) {
	'use strict';
    var Enlargeable = function( options ) {
    	var $self = this;
        return this.each(function(){
        	var $oSettings = $.extend({}, Enlargeable.settings, options),
				$element = $(this),
        		$enlargeBT = $('
').addClass('enlargeBT').attr('title',''),
        		$tooltipTitle=$oSettings.enlargeTitle,
        		activeClick = true;
        	/* set options */
        	$oSettings.fnInit($oSettings);
        	/* in case of "tooltip" option is true, test if jquery ui is in da place ! */
	        if($oSettings.tooltip && !$.ui){
	        	throw new Error('jquery.enlargeable requires jQuery ui 1.10.x OR make "tooltip" option to FALSE');
	        }
	        /* make the enlarge button */
	        $element.parent().prepend($enlargeBT);
	        /* tooltip init if "tooltip" option is true */
	        $oSettings.tooltip?$('.enlargeBT').tooltip({position: { my: "center bottom-20", at: "right top" }, content: $tooltipTitle }):'';
	        /* click */
			$($enlargeBT,$element.parent()).on('click',function(){
				if(!activeClick){ //flood click protection ^^
					return;
				}
				activeClick = false;
				/* enlarge action */
				if(!$enlargeBT.hasClass('reduce')){
					$enlargeBT.toggleClass('enlargeAction');
					/* enlarge click callback */
					$oSettings.fnEnlargeClick($oSettings);
					/* enlarge function */
					$self.originalSize = Enlargeable.enlarge($oSettings, $element);
					/* redefine tooltip title -> return elements with their original sizes */
					$tooltipTitle=$oSettings.reduceTitle;
				/* reduce action */
				}else{
					$enlargeBT.toggleClass('enlargeAction');
					/* reduce click callback */
					$oSettings.fnReduceClick($oSettings);
					/* reduce function */
					Enlargeable.reduce($oSettings, $self.originalSize);
					/* redefine tooltip title */
					$tooltipTitle=$oSettings.enlargeTitle;
				}
				/* add or remove "reduce" class to the enlarge button */
				$enlargeBT.toggleClass('reduce'); //add or remove .reduce class
				/* set tooltip title */
				$oSettings.tooltip?$enlargeBT.tooltip({position: { my: "center bottom-20", at: "right top" }, content: $tooltipTitle }):'';
				/* reactive "click" when timeout = speed option */
				setTimeout(function() {activeClick = true;}, $oSettings.speed);
			});

		});
    };

    Enlargeable.settings = {
		tooltip:false,
		targetWidth:'958',						//target width
		enlargeTitle:'',						//tooltip title for enlarge action
		reduceTitle:'',							//tooltip title for reduce action
		speed:'500',							//animation speed
		fnInit: function($oSettings){},			//init callback
		fnEnlargeClick: function($oSettings){},	//enlarge click callback
		fnReduceClick: function($oSettings){},	//reduce click callback
		fnEnlarge: function($oSettings){},		//after enlarge callback
		fnReduce: function($oSettings){}		//after reduce callback
    };
    /*
     * Function enlarge
     *
     * @param {obj}        $oSettings, enlargeable settings object
     * @param {jquery obj} $element, the enlargeable element
     *
     */
    Enlargeable.enlarge = function($oSettings, $element) {
		var $oElement = {
				element:$element,
				width:$element.width(),
				height:$element.height()
			},
			$elementMaxHeight = $element.css('max-height').length, //useful if element has a max-height defined
			$parents = $element.parents('.enlargeablePrison'),
			$aParents = [],
			$o = {};
		$parents.each(function(){
			var $this = $(this);
			$aParents.push({
				element:$this,
				width:$this.width(),
				height:$this.height()
			});
			$this.animate({width:$oSettings.enlargeWidth+'px',height:'100%'},$oSettings.speed);
		});
		$element.animate({height:'100%', width:($oSettings.enlargeWidth)+'px'},$oSettings.speed, function(){
			$oSettings.fnEnlarge($oSettings);
		});
		if($elementMaxHeight>0){
			$element.css('max-height','100%');
		}
		return $o = {
			oElement:$oElement,
			aParents:$aParents
		};
    };
    /*
     * Function reduce
     *
     * @param {obj}    $oSettings, enlargeable settings object
     * @param {obj}    $oSize, enlargeable element and enlargeablePrison elements originals sizes
     *
     */
    Enlargeable.reduce = function($oSettings, $oSize) {
    	var $element = $oSize.oElement.element;
    	$.each($oSize.aParents, function(){
			this.element.animate({width:this.width+'px',height:this.height+'px'},$oSettings.speed);
    	});
		$element.animate({width:$oSize.oElement.width+'px',height:$oSize.oElement.height+'px'},$oSettings.speed, function(){
			$oSettings.fnReduce($oSettings);
		});
    };

    /* jQuery aliases */
	$.fn.enlargeable = Enlargeable;
}( $ ));
<commit_msg>v0.9.2<commit_after>/*
 * Jquery Enlargeable plugin - https://github.com/popallo/enlargeable
 * Creation => 16-10-2013
 * Update => 22-10-2013
 * © 2013, Licensed MIT (https://github.com/popallo/enlargeable/blob/master/LICENSE)
 * @author popallo
 * @version 0.9.2
 *
 * DEPENDS : jquery >= 1.10.x, jquery ui >= 1.10.x (optional)
 *
 * HOW TO : $(element).enlargeable({option:value});
 *
 * HTML EXAMPLE 1 :
 *

 *

 *
 * HTML EXAMPLE 2 :
 *

 *

 *

 *
 * TODO make enlargeable fullscreenable... ^^
 * TODO make enlargeable skinnable... ^^
 * TODO make it works for "enlarge" or "reduce" size first
 * TODO make the plugin more flexible
 * TODO more and more and more ...
 *
 */
;(function ( $ ) {
	'use strict';
    var Enlargeable = function( options ) {
    	var $self = this;
        return this.each(function(){
        	var $oSettings = $.extend({}, Enlargeable.settings, options),
				$element = $(this),
        		$enlargeBT = $('
').addClass('enlargeBT').attr('title',''),
        		$tooltipTitle=$oSettings.enlargeTitle,
        		activeClick = true;
        	/* set options */
        	$oSettings.fnInit($oSettings);
        	/* in case of "tooltip" option is true, test if jquery ui is in da place ! */
	        if($oSettings.tooltip && !$.ui){
	        	throw new Error('jquery.enlargeable requires jQuery ui 1.10.x OR make "tooltip" option to FALSE');
	        }
	        /* make the enlarge button */
	        $element.parent().prepend($enlargeBT);
	        /* tooltip init if "tooltip" option is true */
	        $oSettings.tooltip?$('.enlargeBT').tooltip({position: { my: "center bottom-20", at: "right top" }, content: $tooltipTitle }):'';
	        /* click */
			$($enlargeBT,$element.parent()).on('click',function(){
				if(!activeClick){ //flood click protection ^^
					return;
				}
				activeClick = false;
				/* enlarge action */
				if(!$enlargeBT.hasClass('reduce')){
					$enlargeBT.toggleClass('enlargeAction');
					/* enlarge click callback */
					$oSettings.fnEnlargeClick($oSettings);
					/* enlarge function */
					$self.originalSize = Enlargeable.enlarge($oSettings, $element);
					/* redefine tooltip title -> return elements with their original sizes */
					$tooltipTitle=$oSettings.reduceTitle;
				/* reduce action */
				}else{
					$enlargeBT.toggleClass('enlargeAction');
					/* reduce click callback */
					$oSettings.fnReduceClick($oSettings);
					/* reduce function */
					Enlargeable.reduce($oSettings, $self.originalSize);
					/* redefine tooltip title */
					$tooltipTitle=$oSettings.enlargeTitle;
				}
				/* add or remove "reduce" class to the enlarge button */
				$enlargeBT.toggleClass('reduce'); //add or remove .reduce class
				/* set tooltip title */
				$oSettings.tooltip?$enlargeBT.tooltip({position: { my: "center bottom-20", at: "right top" }, content: $tooltipTitle }):'';
				/* reactive "click" when timeout = speed option */
				setTimeout(function() {activeClick = true;}, $oSettings.speed);
			});

		});
    };

    Enlargeable.settings = {
		tooltip:false,
		targetWidth:'958',						//target width
		enlargeTitle:'',						//tooltip title for enlarge action
		reduceTitle:'',							//tooltip title for reduce action
		speed:'500',							//animation speed
		fnInit: function($oSettings){},			//init callback
		fnEnlargeClick: function($oSettings){},	//enlarge click callback
		fnReduceClick: function($oSettings){},	//reduce click callback
		fnEnlarge: function($oSettings){},		//after enlarge callback
		fnReduce: function($oSettings){}		//after reduce callback
    };
    /*
     * Function enlarge
     *
     * @param {obj}        $oSettings, enlargeable settings object
     * @param {jquery obj} $element, the enlargeable element
     *
     */
    Enlargeable.enlarge = function($oSettings, $element) {
		var $oElement = {
				element:$element,
				width:$element.width(),
				height:$element.height()
			},
			$elementMaxHeight = $element.css('max-height').length, //useful if element has a max-height defined
			$parents = $element.parents('.enlargeablePrison'),
			$aParents = [],
			$o = {};
		$parents.each(function(){
			var $this = $(this);
			$aParents.push({
				element:$this,
				width:$this.width(),
				height:$this.height()
			});
			$this.animate({width:$oSettings.enlargeWidth,height:'100%'},$oSettings.speed);
		});
		$element.animate({height:'100%', width:$oSettings.enlargeWidth},$oSettings.speed, function(){
			$oSettings.fnEnlarge($oSettings);
		});
		if($elementMaxHeight>0){
			$element.css('max-height','100%');
		}
		return $o = {
			oElement:$oElement,
			aParents:$aParents
		};
    };
    /*
     * Function reduce
     *
     * @param {obj}    $oSettings, enlargeable settings object
     * @param {obj}    $oSize, enlargeable element and enlargeablePrison elements originals sizes
     *
     */
    Enlargeable.reduce = function($oSettings, $oSize) {
    	var $element = $oSize.oElement.element;
    	$.each($oSize.aParents, function(){
			this.element.animate({width:this.width+'px',height:this.height+'px'},$oSettings.speed);
    	});
		$element.animate({width:$oSize.oElement.width+'px',height:$oSize.oElement.height+'px'},$oSettings.speed, function(){
			$oSettings.fnReduce($oSettings);
		});
    };

    /* jQuery aliases */
	$.fn.enlargeable = Enlargeable;
}( $ ));
<|endoftext|>


<commit_before>/*
 * jQuery Form Example Plugin 1.5
 * Populate form inputs with example text that disappears on focus.
 *
 * e.g.
 *  $('input#name').example('Bob Smith');
 *  $('input[@title]').example(function() {
 *    return $(this).attr('title');
 *  });
 *  $('textarea#message').example('Type your message here', {
 *    className: 'example_text'
 *  });
 *
 * Copyright (c) Paul Mucur (http://mudge.name), 2007-2011.
 * Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
 * licenses.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
(function(a,b){a.fn.example=function(b,c){var d=a.isFunction(b),e=a.extend({},c,{example:b});return this.each(function(){var b=a(this);if(a.metadata)var c=a.extend({},a.fn.example.defaults,b.metadata(),e);else var c=a.extend({},a.fn.example.defaults,e);a.fn.example.boundClassNames[c.className]||(a(window).bind("unload.example",function(){a("."+c.className).val("")}),a("form").bind("submit.example",function(){a(this).find("."+c.className).val("")}),a.fn.example.boundClassNames[c.className]=!0),!b.attr("value")&&(d||b.val()==c.example)&&b.val(""),b.val()==""&&this!=document.activeElement&&(b.addClass(c.className),b.val(d?c.example.call(this):c.example)),b.bind("focus.example",function(){a(this).is("."+c.className)&&(a(this).val(""),a(this).removeClass(c.className))}),b.bind("change.example",function(){a(this).is("."+c.className)&&a(this).removeClass(c.className)}),b.bind("blur.example",function(){a(this).val()==""&&(a(this).addClass(c.className),a(this).val(d?c.example.call(this):c.example))})})},a.fn.example.defaults={className:"example"},a.fn.example.boundClassNames=[]})(jQuery)
<commit_msg>Add a trailing semi-colon to the minimised version.<commit_after>/*
 * jQuery Form Example Plugin 1.5
 * Populate form inputs with example text that disappears on focus.
 *
 * e.g.
 *  $('input#name').example('Bob Smith');
 *  $('input[@title]').example(function() {
 *    return $(this).attr('title');
 *  });
 *  $('textarea#message').example('Type your message here', {
 *    className: 'example_text'
 *  });
 *
 * Copyright (c) Paul Mucur (http://mudge.name), 2007-2011.
 * Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
 * licenses.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
(function(a,b){a.fn.example=function(b,c){var d=a.isFunction(b),e=a.extend({},c,{example:b});return this.each(function(){var b=a(this);if(a.metadata)var c=a.extend({},a.fn.example.defaults,b.metadata(),e);else var c=a.extend({},a.fn.example.defaults,e);a.fn.example.boundClassNames[c.className]||(a(window).bind("unload.example",function(){a("."+c.className).val("")}),a("form").bind("submit.example",function(){a(this).find("."+c.className).val("")}),a.fn.example.boundClassNames[c.className]=!0),!b.attr("value")&&(d||b.val()==c.example)&&b.val(""),b.val()==""&&this!=document.activeElement&&(b.addClass(c.className),b.val(d?c.example.call(this):c.example)),b.bind("focus.example",function(){a(this).is("."+c.className)&&(a(this).val(""),a(this).removeClass(c.className))}),b.bind("change.example",function(){a(this).is("."+c.className)&&a(this).removeClass(c.className)}),b.bind("blur.example",function(){a(this).val()==""&&(a(this).addClass(c.className),a(this).val(d?c.example.call(this):c.example))})})},a.fn.example.defaults={className:"example"},a.fn.example.boundClassNames=[]})(jQuery);
<|endoftext|>


<commit_before>/**
 * Image Slider
 *
 * @category    jQuery Plugin
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
 * @copyright   2014 Daiki Sato
 * @author      Daiki Sato <sato.dik@gmail.com>
 * @link        http://orememo-v2.tumblr.com/
 * @version     1.1.0
 * @since       2014.05.16
 */

;(function($, window, document, undefined) {

	var pluginName = 'imageslider',
			defaults = {
				slideItems: '.is-item',
				slideContainer: '.is-container',
				slideDistance: 1,
				slideDuration: 1,
				slideEasing: 'linear',
				resizable: false,
				reverse: false
			};

	function Plugin(element, options) {
		var self = this;

		self.element = element;
		self.settings = $.extend({}, defaults, options);
		self._defaults = defaults;
		self._name = pluginName;

		$(window).on('load', function() { self.init(); });
		// this.init();
	}

	Plugin.prototype.init = function() {
		var self = this;

		self.$element = $(self.element);
		self.$slideContainer = self.$element.find(self.settings.slideContainer);
		self.$slideItems = self.$element.find(self.settings.slideItems);
		self.elementW = self.$element.width();
		self.slideContainerW = calcContainerSize(self.$slideContainer, self.$slideItems);
		self.slideItemsLength = self.$slideItems.length;

		self.$slideContainer.width(self.slideContainerW);
		self.$element.css('overflow', 'hidden');

		if(self.settings.resizable) {
			$(window).on('resize', function(){ self.resizeContainer(); });
		}

		self.resizeContainer();
		// self.startSlide();
	}
	Plugin.prototype.startSlide = function() {
		var self = this,
				$slideItemFirst = self.$slideContainer.find(self.settings.slideItems).eq(0),
				$slideItemLast = self.$slideContainer.find(self.settings.slideItems).eq(self.slideItemsLength - 1),
				slideItemFirstW = $slideItemFirst.width(),
				slideItemLastW = $slideItemLast.width();

		if($slideItemFirst.is(':animated')) return false;

		if(!self.settings.reverse) {
			// 右->左にスライドする
			$slideItemFirst.animate({
				marginLeft: parseInt($slideItemFirst.css('margin-left'), 10) - self.settings.slideDistance
			}, self.settings.slideDuration, self.settings.slideEasing, function() {
				if(Math.abs(parseInt($slideItemFirst.css('margin-left'), 10)) > slideItemFirstW) {
					$slideItemFirst.appendTo(self.$slideContainer).css('margin-left', 0);
				}
				self.startSlide();
			});
		} else {
			// 左->右にスライドする
			if(parseInt($slideItemFirst.css('margin-left'), 10) >= 0) {
				$slideItemLast.prependTo(self.$slideContainer).css('margin-left', -slideItemLastW);
				self.startSlide();
				return false;
			}

			$slideItemFirst.animate({
				marginLeft: parseInt($slideItemFirst.css('margin-left'), 10) + self.settings.slideDistance
			}, self.settings.slideDuration, self.settings.slideEasing, function() {
				self.startSlide();
			});
		}
	}
	Plugin.prototype.stopSlide = function() {
		var self = this;

		self.$slideItems.stop();
	}
	Plugin.prototype.resizeContainer = function() {
		var self = this,
				elementW = self.$element.width(),
				itemsW = self.slideContainerW;

		// self.$slideContainerの横幅がself.$elementの横幅より小さい時、スライドする要素をコピー
		// if(elementW < self.slideContainerW) return false;

		// スライドを一旦ストップ
		self.stopSlide();

		// self.$elementの横幅を超えるまでスライドする要素をコピーする
		adjustItemsLength(self.$slideContainer, self.$slideItems, elementW, itemsW);

		// 各種要素更新
		self.$slideItems = self.$element.find(self.settings.slideItems);
		self.slideContainerW = calcContainerSize(self.$slideContainer, self.$slideItems);
		self.elementW = elementW;
		self.$slideContainer.width(self.slideContainerW);
		self.slideItemsLength = self.$slideItems.length;

		// スライドを再スタートする
		self.startSlide();
	}

	function adjustItemsLength($container, $items, elementW, itemsW) {
		$items.each(function() {
			if(itemsW > elementW * 2) return false;

			var $clone = $(this).clone().css('margin-left', 0);

			$clone.appendTo($container);
			itemsW += $clone.width();
		});
	} // end of adjustItemsLength

	// 親要素のサイズを設定
	function calcContainerSize($container, $items) {
		var containerW = $container.width(),
				resultW = 0;

		$items.each(function() {
			resultW += $(this).width();
		});

		return resultW;
	} // end of calcContainerSize()

	$.fn[pluginName] = function(options) {
		this.each(function() {
			if(!$.data(this, 'plugin_' + pluginName)) {
				$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
			}
		});

		return this;
	}

})(jQuery, window, document, undefined);<commit_msg>ホバー時にスライドが止まる機能を追加<commit_after>/**
 * Image Slider
 *
 * @category    jQuery Plugin
 * @license     http://www.opensource.org/licenses/mit-license.html  MIT License
 * @copyright   2014 Daiki Sato
 * @author      Daiki Sato <sato.dik@gmail.com>
 * @link        http://orememo-v2.tumblr.com/
 * @version     1.1.0
 * @since       2014.05.16
 */

;(function($, window, document, undefined) {

	var pluginName = 'imageslider',
			defaults = {
				slideItems: '.is-item',
				slideContainer: '.is-container',
				slideDistance: 1,
				slideDuration: 1,
				slideEasing: 'linear',
				resizable: false,
				reverse: false,
				pause: true
			};

	function Plugin(element, options) {
		var self = this;

		self.element = element;
		self.settings = $.extend({}, defaults, options);
		self._defaults = defaults;
		self._name = pluginName;

		$(window).on('load', function() { self.init(); });
		// this.init();
	}

	Plugin.prototype.init = function() {
		var self = this;

		self.$element = $(self.element);
		self.$slideContainer = self.$element.find(self.settings.slideContainer);
		self.$slideItems = self.$element.find(self.settings.slideItems);
		self.elementW = self.$element.width();
		self.slideContainerW = calcContainerSize(self.$slideContainer, self.$slideItems);
		self.slideItemsLength = self.$slideItems.length;

		self.$slideContainer.width(self.slideContainerW);
		self.$element.css('overflow', 'hidden');

		if(self.settings.resizable) {
			$(window).on('resize', function(){ self.resizeContainer(); });
		}
		if(self.settings.pause) {
			self.$slideContainer.hover(
				function() { self.stopSlide(); },
				function() { self.startSlide(); }
			);
		}

		self.resizeContainer();
		// self.startSlide();
	}
	Plugin.prototype.startSlide = function() {
		var self = this,
				$slideItemFirst = self.$slideContainer.find(self.settings.slideItems).eq(0),
				$slideItemLast = self.$slideContainer.find(self.settings.slideItems).eq(self.slideItemsLength - 1),
				slideItemFirstW = $slideItemFirst.width(),
				slideItemLastW = $slideItemLast.width();

		if($slideItemFirst.is(':animated')) return false;

		if(!self.settings.reverse) {
			// 右->左にスライドする
			$slideItemFirst.animate({
				marginLeft: parseInt($slideItemFirst.css('margin-left'), 10) - self.settings.slideDistance
			}, self.settings.slideDuration, self.settings.slideEasing, function() {
				if(Math.abs(parseInt($slideItemFirst.css('margin-left'), 10)) > slideItemFirstW) {
					$slideItemFirst.appendTo(self.$slideContainer).css('margin-left', 0);
				}
				self.startSlide();
			});
		} else {
			// 左->右にスライドする
			if(parseInt($slideItemFirst.css('margin-left'), 10) >= 0) {
				$slideItemLast.prependTo(self.$slideContainer).css('margin-left', -slideItemLastW);
				self.startSlide();
				return false;
			}

			$slideItemFirst.animate({
				marginLeft: parseInt($slideItemFirst.css('margin-left'), 10) + self.settings.slideDistance
			}, self.settings.slideDuration, self.settings.slideEasing, function() {
				self.startSlide();
			});
		}
	}
	Plugin.prototype.stopSlide = function() {
		var self = this;

		self.$slideItems.stop();
	}
	Plugin.prototype.resizeContainer = function() {
		var self = this,
				elementW = self.$element.width(),
				itemsW = self.slideContainerW;

		// self.$slideContainerの横幅がself.$elementの横幅より小さい時、スライドする要素をコピー
		// if(elementW < self.slideContainerW) return false;

		// スライドを一旦ストップ
		self.stopSlide();

		// self.$elementの横幅を超えるまでスライドする要素をコピーする
		adjustItemsLength(self.$slideContainer, self.$slideItems, elementW, itemsW);

		// 各種要素更新
		self.$slideItems = self.$element.find(self.settings.slideItems);
		self.slideContainerW = calcContainerSize(self.$slideContainer, self.$slideItems);
		self.elementW = elementW;
		self.$slideContainer.width(self.slideContainerW);
		self.slideItemsLength = self.$slideItems.length;

		// スライドを再スタートする
		self.startSlide();
	}

	function adjustItemsLength($container, $items, elementW, itemsW) {
		$items.each(function() {
			if(itemsW > elementW * 2) return false;

			var $clone = $(this).clone().css('margin-left', 0);

			$clone.appendTo($container);
			itemsW += $clone.width();
		});
	} // end of adjustItemsLength

	// 親要素のサイズを設定
	function calcContainerSize($container, $items) {
		var containerW = $container.width(),
				resultW = 0;

		$items.each(function() {
			resultW += $(this).width();
		});

		return resultW;
	} // end of calcContainerSize()

	$.fn[pluginName] = function(options) {
		this.each(function() {
			if(!$.data(this, 'plugin_' + pluginName)) {
				$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
			}
		});

		return this;
	}

})(jQuery, window, document, undefined);<|endoftext|>


<commit_before>'use strict';

module.exports = function (app, express, organizationsData, projectsData) {

  let organizationProjectsController;
  const organizationProjectsRouter = new express.Router();
  organizationProjectsRouter
    .get('/:organizationId/projects/create', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.createProjectForm(req, res);
    })
    .post('/:organizationId/projects/create', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.createProject(req, res);
    })
    .get('/:organizationId/projects/:projectId', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.projectDetails(req, res);
    })
    .get('/:organizationId/projects', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.index(req, res);
    });

  app.use('/organizations', organizationProjectsRouter);
};

function lazyLoadOrganizationProjectsController(organizationsData, projectsData) {
  const organizationProjectsController = require('../controllers/organization-projects-controller')(organizationsData, projectsData);
  return organizationProjectsController;
}<commit_msg>delete project route<commit_after>'use strict';

module.exports = function (app, express, organizationsData, projectsData) {

  let organizationProjectsController;
  const organizationProjectsRouter = new express.Router();
  organizationProjectsRouter
    .get('/:organizationId/projects/delete/:projectId', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.deleteProject(req, res);
    })
    .get('/:organizationId/projects/create', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.createProjectForm(req, res);
    })
    .post('/:organizationId/projects/create', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.createProject(req, res);
    })
    .get('/:organizationId/projects/:projectId', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.projectDetails(req, res);
    })
    .get('/:organizationId/projects', (req, res) => {
      if (!organizationProjectsController) {
        organizationProjectsController = lazyLoadOrganizationProjectsController(organizationsData, projectsData);
      }

      organizationProjectsController.index(req, res);
    });

  app.use('/organizations', organizationProjectsRouter);
};

function lazyLoadOrganizationProjectsController(organizationsData, projectsData) {
  const organizationProjectsController = require('../controllers/organization-projects-controller')(organizationsData, projectsData);
  return organizationProjectsController;
}<|endoftext|>


<commit_before>(function($) {
    $.fn.mnslideshow = function(options) {

        var defaults = {
            transition: 'fade',
            transitionIn: '',
            transitionOut: '',
            options: {},
            optionsIn: {},
            optionsOut: {},
            continuous: true,
            speed: 1000,
            pause: 2000
        };
        var options = $.extend(defaults, options);
        if (options.transitionIn == '') {
            options.transitionIn = options.transition;
        }
        if (options.transitionOut == '') {
            options.transitionOut = options.transition;
        }
        var thisSlide = 0;
        var nextSlide = 1;
        var slides = $(this).find('li');
        $(slides).each(function() {
            $(this).css('display', 'none');
        });
        $(slides[0]).css('display', 'block');
        function animate() {
            if( options.transitionOut == 'fade') {
                $(slides[thisSlide]).fadeOut(
                    options.speed
                );
            } else {
                $(slides[thisSlide]).hide(
                    options.transitionOut,
                    options.optionsOut,
                    options.speed
                );
            }
            if (options.transitionIn == 'fade') {
                $(slides[nextSlide]).fadeIn(
                    options.speed,
                    function() {
                        thisSlide = nextSlide;
                        nextSlide++;
                        if(slides.length <= nextSlide && !options.continuous) {
                            return;
                        } else if (slides.length <= nextSlide) {
                            nextSlide = 0;
                        }
                        timeout = setTimeout(function() {
                            animate();
                        }, options.pause);
                    }
                );
            } else {
                $(slides[nextSlide]).show(
                    options.transitionIn,
                    $.extend(
                        options.optionsIn,
                        {
                            queue: false
                        }
                    ),
                    options.speed,
                    function() {
                        thisSlide = nextSlide;
                        nextSlide++;
                        if (slides.length <= nextSlide) {
                            nextSlide = 0;
                        }
                        timeout = setTimeout(function() {
                            animate();
                        }, options.pause);
                    }
                );
            }
        }
        timeout = setTimeout(function(){
            animate();
        },options.pause);
    };
})(jQuery);<commit_msg>If there is only one slide there is no need to animate it.<commit_after>(function($) {
    $.fn.mnslideshow = function(options) {

        var defaults = {
            transition: 'fade',
            transitionIn: '',
            transitionOut: '',
            options: {},
            optionsIn: {},
            optionsOut: {},
            continuous: true,
            speed: 1000,
            pause: 2000
        };
        var options = $.extend(defaults, options);
        if (options.transitionIn == '') {
            options.transitionIn = options.transition;
        }
        if (options.transitionOut == '') {
            options.transitionOut = options.transition;
        }
        var thisSlide = 0;
        var nextSlide = 1;
        var slides = $(this).find('li');
        if ( slides.length < 2 ) {
            return;
        }
        $(slides).each(function() {
            $(this).css('display', 'none');
        });
        $(slides[0]).css('display', 'block');
        function animate() {
            if( options.transitionOut == 'fade') {
                $(slides[thisSlide]).fadeOut(
                    options.speed
                );
            } else {
                $(slides[thisSlide]).hide(
                    options.transitionOut,
                    options.optionsOut,
                    options.speed
                );
            }
            if (options.transitionIn == 'fade') {
                $(slides[nextSlide]).fadeIn(
                    options.speed,
                    function() {
                        thisSlide = nextSlide;
                        nextSlide++;
                        if(slides.length <= nextSlide && !options.continuous) {
                            return;
                        } else if (slides.length <= nextSlide) {
                            nextSlide = 0;
                        }
                        timeout = setTimeout(function() {
                            animate();
                        }, options.pause);
                    }
                );
            } else {
                $(slides[nextSlide]).show(
                    options.transitionIn,
                    $.extend(
                        options.optionsIn,
                        {
                            queue: false
                        }
                    ),
                    options.speed,
                    function() {
                        thisSlide = nextSlide;
                        nextSlide++;
                        if (slides.length <= nextSlide) {
                            nextSlide = 0;
                        }
                        timeout = setTimeout(function() {
                            animate();
                        }, options.pause);
                    }
                );
            }
        }
        timeout = setTimeout(function(){
            animate();
        },options.pause);
    };
})(jQuery);<|endoftext|>


<commit_before>/**
 * jQuery mouseCenter v1.0.0
 *
 * Author: Adrien Gibrat <adrien.gibrat@gmail.com>
 *
 * Trigger special events when mouse enter / leave element center area.
 *
 * You can specify a distance that define the center area, it can be an integer or
 * a function taking cursor coordinates x,y relative to center as arguments and returning a boolean.
 * The distance is passed in or as data argument when you bind your function.
 *
 * Usage exemples:
$( 'selector' )

	// Default distance is 50 pixels, center area is a 50px radius circle.
	.mousecenterenter( function () {
		... your code ...
	} )

	// Distance integer as data argument, center area is a 20px radius circle.
	.mousecenterleave( 20, function () {
		... your code ...
	} )

	// Distance in data argument, center area is a 20px radius circle.
	.mousecenterenter( { distance: 20, customdata: 'foo' }, function () {
		... your code ...
	} )
	;
var square40 = function ( x, y ) {
	return 20 >= Math.abs( x ) && 20 >= Math.abs( y );
};
$( 'selector' )
	// Distance function as data, center area is a 2 * 20px side square.
	// You can pass function in data argument as well.
	.mousecenterleave( square40, function () {
		... your code ...
	} )
	;
// For example clarity sake, i used the square40 plain function
// But you can use $.mousecenter( 'square', size ) to easily create function for various "square size",
// In this exemple: square40 === $.mousecenter( 'square', 20 )
// You can extend $.mousecenter to create new resizable shapes (@see end of jquery.mousecenter.js)

 */
( function ( $ ) {
	/**
	 * Add function binding to JavaScript prior 1.8.5
	 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
	 */
	if ( ! Function.prototype.bind ) {
		Function.prototype.bind = function ( context ) {
			var args  = Array.prototype.slice.call( arguments, 1 ),
				bind  = this,
				nop   = function () {},
				bound = function () {
					return bind.apply(
						this instanceof nop ? this : context || window,
						args.concat( Array.prototype.slice.call( arguments ) )
					);
				};
			nop.prototype   = this.prototype;
			bound.prototype = new nop();
			return bound;
		};
	}
	var
		namespace = 'mousecenter'
		/**
		 * Call event type handler when cursor enter/leave element center area
		 * @param type string, type of event (enter or leave)
		 * @param distance int|function, distance in pixel or function returning if given point (x, y) is within an area
		 * @param handleObj object, original event handle
		 * @param event object, jQuery event
		 * @return mixed
		 */
		, handler = function ( type, distance, handleObj, event ) {
			var self     = $( this )
				// All states of binded events
				, state  = self.data( namespace )
				// Previous state
				, inside = state[ handleObj.guid ]
				// Default center area is a circle
				, within = $.isFunction( distance ) ? distance : $.mousecenter( 'circle', distance )
				, offset = self.offset()
			;
			// Is within area relative to center
			if ( within( event.pageX - offset.left - self.width() / 2, event.pageY - offset.top - self.height() / 2 ) ) {
				if ( ! inside ) {
					// Store new state
					state[ handleObj.guid ] = true;
					if ( 'enter' === type ) {
						event.type = namespace + type;
						return handleObj.handler.call( this, event );
					}
				}
			} else {
				if ( inside ) {
					// Store new state
					state[ handleObj.guid ] = false;
					if ( 'leave' === type ) {
						event.type = namespace + type;
						return handleObj.handler.call( this, event );
					}
				}
			}
		};
	/**
	 * Add events to jQuery
	 */
	$.each( [ 'enter', 'leave' ], function ( i, type ) {
		var name = namespace + type;
		// Add special event methods
		$.event.special[ name ] = {
			// Add data to store state
			setup      : function () {
				$( this )
					.data( namespace, {} )
				;
			}
			// Bind special handler and init state
			, add      : function ( handleObj ) {
				var distance = ( $.isPlainObject( handleObj.data ) ? handleObj.data.distance : handleObj.data ) || 50;
				$( this )
					.bind( 'mousemove.' + namespace + handleObj.guid, handler.bind( this, type, distance, handleObj ) )
					.data( namespace )[ handleObj.guid ] = false
				;
			}
			// Unbind special handler and delete state from data
			, remove   : function ( handleObj ) {
				delete $( this )
					.unbind( 'mousemove.' + namespace + handleObj.guid )
					.data( namespace )[ handleObj.guid ]
				;
			}
			// Clean up data if state hash is empty
			, teardown : function () {
				var self = $( this );
				$.isEmptyObject( self.data( namespace ) ) && self.removeData( namespace );
			}
		};
		// Add event binding / triggering methods
		$.fn[ name ]            = function( data, fn ) {
			if ( ! fn ) {
				fn   = data;
				data = null;
			}
			return arguments.length ? this.on( name, null, data, fn ) : this.trigger( name );
		};
		// Allow binding for the $( html, props ) case
		$.attrFn[ name ]        = true;
	} );
	/**
	 * Add helper to jQuery
	 */
	$[ namespace ] = $.extend(
		/**
		 * Create function that check if a point inside a shape
		 * @param shape string, name of the shape to create (must be a helper name)
		 * @param size int, size of the shape
		 * @return function, that take point coordinates to check if it's inside the shape
		 */
		function ( shape, size ) {
			shape = arguments.callee[ shape ];
			return shape && shape.bind( size );
		}
		, {
			/**
			 * Helper function to check if a point inside a square (side = 2 * this)
			 * @param x int, x coordinate of point relative to center
			 * @param y int, y coordinate of point relative to center
			 * @return boolean, is point inside square
			 */
			square   : function ( x, y ) {
				return this >= Math.abs( x ) && this >= Math.abs( y );
			}
			/**
			 * Helper function to check if a point inside a circle (radius = 2 * this)
			 * @param x int, x coordinate of point relative to center
			 * @param y int, y coordinate of point relative to center
			 * @return boolean, is point inside circle
			 */
			, circle : function ( x, y ) {
				return this >= Math.sqrt( Math.pow( x, 2 ) + Math.pow( y, 2 ) );
			}
			// now, you can extend $.mousecenter with you own shapes !
		}
	);
} )( jQuery );
<commit_msg>adding demo page<commit_after>/**
 * jQuery mouseCenter v1.0.0
 *
 * Author: Adrien Gibrat <adrien.gibrat@gmail.com>
 *
 * Trigger special events when mouse enter / leave element center area.
 *
 * You can specify a distance that define the center area, it can be an integer or
 * a function taking cursor coordinates x,y relative to center as arguments and returning a boolean.
 * The distance is passed in or as data argument when you bind your function.
 *
 * Usage exemples:
$( 'selector' )

	// Default distance is 50 pixels, center area is a 50px radius circle.
	.mousecenterenter( function () {
		... your code ...
	} )

	// Distance integer as data argument, center area is a 20px radius circle.
	.mousecenterleave( 20, function () {
		... your code ...
	} )

	// Distance in data argument, center area is a 20px radius circle.
	.mousecenterenter( { distance: 20, customdata: 'foo' }, function () {
		... your code ...
	} )
	;
var square40 = function ( x, y ) {
	return 20 >= Math.abs( x ) && 20 >= Math.abs( y );
};
$( 'selector' )
	// Distance function as data, center area is a 2 * 20px side square.
	// You can pass function in data argument as well.
	.mousecenterleave( square40, function () {
		... your code ...
	} )
	;
// For example clarity sake, i used the square40 plain function
// But you can use $.mousecenter( 'square', size ) to easily create function for various "square size",
// In this exemple: square40 === $.mousecenter( 'square', 20 )
// You can extend $.mousecenter to create new resizable shapes (@see end of jquery.mousecenter.js)

 */
( function ( $ ) {
	/**
	 * Add function binding to JavaScript prior 1.8.5
	 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
	 */
	if ( ! Function.prototype.bind ) {
		Function.prototype.bind = function ( context ) {
			var args  = Array.prototype.slice.call( arguments, 1 ),
				bind  = this,
				nop   = function () {},
				bound = function () {
					return bind.apply(
						this instanceof nop ? this : context || window,
						args.concat( Array.prototype.slice.call( arguments ) )
					);
				};
			nop.prototype   = this.prototype;
			bound.prototype = new nop();
			return bound;
		};
	}
	var
		namespace = 'mousecenter'
		/**
		 * Call event type handler when cursor enter/leave element center area
		 * @param type string, type of event (enter or leave)
		 * @param distance int|function, distance in pixel or function returning if given point (x, y) is within an area
		 * @param handleObj object, original event handle
		 * @param event object, jQuery event
		 * @return mixed
		 */
		, handler = function ( type, distance, handleObj, event ) {
			var self     = $( this )
				// All states of binded events
				, state  = self.data( namespace )
				// Previous state
				, inside = state[ handleObj.guid ]
				// Default center area is a circle
				, within = $.isFunction( distance ) ? distance : $.mousecenter( 'circle', distance )
				, offset = self.offset()
			;
			// Is within area relative to center
			if ( within( event.pageX - offset.left - self.width() / 2, event.pageY - offset.top - self.height() / 2 ) ) {
				if ( ! inside ) {
					// Store new state
					state[ handleObj.guid ] = true;
					if ( 'enter' === type ) {
						event.type = namespace + type;
						return handleObj.handler.call( this, event );
					}
				}
			} else {
				if ( inside ) {
					// Store new state
					state[ handleObj.guid ] = false;
					if ( 'leave' === type ) {
						event.type = namespace + type;
						return handleObj.handler.call( this, event );
					}
				}
			}
		};
	/**
	 * Add events to jQuery
	 */
	$.each( [ 'enter', 'leave' ], function ( i, type ) {
		var name = namespace + type;
		// Add special event methods
		$.event.special[ name ] = {
			// Add data to store state
			setup      : function () {
				$( this )
					.data( namespace, {} )
				;
			}
			// Bind special handler and init state
			, add      : function ( handleObj ) {
				var distance = ( $.isPlainObject( handleObj.data ) ? handleObj.data.distance : handleObj.data ) || 50;
				$( this )
					.bind( 'mousemove.' + namespace + handleObj.guid, handler.bind( this, type, distance, handleObj ) )
					.data( namespace )[ handleObj.guid ] = false
				;
			}
			// Unbind special handler and delete state from data
			, remove   : function ( handleObj ) {
				delete $( this )
					.unbind( 'mousemove.' + namespace + handleObj.guid )
					.data( namespace )[ handleObj.guid ]
				;
			}
			// Clean up data if state hash is empty
			, teardown : function () {
				var self = $( this );
				$.isEmptyObject( self.data( namespace ) ) && self.removeData( namespace );
			}
		};
		// Add event binding / triggering methods
		$.fn[ name ]            = function( data, fn ) {
			if ( ! fn ) {
				fn   = data;
				data = null;
			}
			return arguments.length ? this.on( name, null, data, fn ) : this.trigger( name );
		};
		// Allow binding for the $( html, props ) case
		$.attrFn[ name ]        = true;
	} );
	/**
	 * Add helper to jQuery
	 */
	$[ namespace ] = $.extend(
		/**
		 * Create function that check if a point inside a shape
		 * @param shape string, name of the shape to create (must be a helper name)
		 * @param size int, size of the shape ( but you could pass any object for your custom shape helper)
		 * @return function, that take point coordinates to check if it's inside the shape
		 */
		function ( shape, size ) {
			return ( shape = $[ namespace ][ shape ] ) && shape.bind( size );
		}
		, {
			/**
			 * Helper function to check if a point inside a square (side = 2 * this)
			 * @param x int, x coordinate of point relative to center
			 * @param y int, y coordinate of point relative to center
			 * @return boolean, is point inside square
			 */
			square   : function ( x, y ) {
				return this >= Math.abs( x ) && this >= Math.abs( y );
			}
			/**
			 * Helper function to check if a point inside a circle (radius = 2 * this)
			 * @param x int, x coordinate of point relative to center
			 * @param y int, y coordinate of point relative to center
			 * @return boolean, is point inside circle
			 */
			, circle : function ( x, y ) {
				return this >= Math.sqrt( Math.pow( x, 2 ) + Math.pow( y, 2 ) );
			}
			// now, you can extend $.mousecenter with you own shapes !
		}
	);
} )( jQuery );
<|endoftext|>


<commit_before>/*!
 * jQuery tableSelect plugin 1.3.0
 *
 * Copyright (c) 2010, 2014 Kjel Delaey
 * Released under the MIT license
 * https://raw.github.com/trimentor/jquery-tableSelect/master/LICENSE
*/

(function($) {
    $.extend($.fn, {
        tableSelect: function(options) {
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.extend($.fn, {
        tableSelectOne: function(options) {
            var options   = $.extend({multiSelect: false}, options);
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.extend($.fn, {
        tableSelectMany: function(options) {
            var options   = $.extend({multiSelect: true}, options);
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.tableSelector = function(options, table) {
        this.options      = $.extend({}, $.tableSelector.defaults, options);
        this.currentTable = table;
        this.init();
    };

    $.extend($.tableSelector, {
        defaults: {
            tableClass:     "tableselect",
            rowSelectClass: "selected",
            multiSelect:    false
        },

        prototype: {
            init: function() {
                this.selections = [];
                this.listeners  = this.options.listeners || {};
                this.collectRows();
                this.initRowEvents();

                $(this.currentTable).addClass(this.options.tableClass);
            },

            allSelected: function() {
                return (this.selections.length == this.rows.length);
            },

            getSelections: function() {
                return this.selections;
            },

            getFocusedRow: function() {
                return this.rows[this.lastActiveRow];
            },

            isSelected: function(row) {
                var bool = false;
                for(var i=0; i<this.selections.length; i++) {
                    if(this.selections[i] == row) {
                        bool = true;
                        break;
                    }
                }
                return bool;
            },

            collectRows: function() {
                var table = this;
                this.rows = this.currentTable[0].tBodies[0].rows;
                $(this.rows).each(function() {
                    this.parentThis = table;
                });
            },

            initRowEvents: function() {
                var table = this;
                $(this.rows).each(function() {
                    $(this).bind('click', table.handleMouseDown);
                    $(this).bind('rowselect', table.rowSelectClass);
                    $(this).bind('rowdeselect', table.rowSelectClass);
                    table.initListeners(table, this);
                });
            },

            initListeners: function(table, row) {
                if(table.listeners) {
                    var listeners = table.listeners;
                    if(listeners.beforerowselect)   $(row).bind('beforerowselect',   listeners.beforerowselect);
                    if(listeners.afterrowselect)    $(row).bind('afterrowselect',    listeners.afterrowselect);
                    if(listeners.beforerowdeselect) $(row).bind('beforerowdeselect', listeners.beforerowdeselect);
                    if(listeners.afterrowdeselect)  $(row).bind('afterrowdeselect',  listeners.afterrowdeselect);
                }
            },

            handleMouseDown: function(event) {
                var table = this.parentThis;
                table.storeEventTarget(event, this);

                if(table.options.multiSelect) {
                    table.handleKeyDown(event, this);
                }
                else {
                    table.handleSingleSelect(this);
                }

                table.resetEventTarget(this);
            },

            handleKeyDown: function(event, row) {
                var rowIndex = row.sectionRowIndex;

                if(event.shiftKey) {
                    if(typeof(this.lastActiveRow) == "undefined") this.focusRow(rowIndex);
                    this.lockedRow = this.lastActiveRow;
                    if(event.ctrlKey) {
                        this.selectRange(this.lastActiveRow, rowIndex, true);
                    }
                    else {
                        this.selectRange(this.lockedRow, rowIndex, false);
                        this.focusRow(this.lockedRow);
                    }
                }
                else {
                    this.handleSingleSelect(row);
                }
            },

            storeEventTarget: function(event, row) {
                var target = event.target && event.target.nodeName;
                row.target = target ? target.toLowerCase() : null;
            },

            resetEventTarget: function(row) {
                row.target = undefined;
            },

            handleSingleSelect: function(row) {
                var rowIndex = row.sectionRowIndex;

                if(this.isSelected(row)) {
                    this.deselectRow(rowIndex);
                }
                else {
                    this.selectRow(rowIndex, this.options.multiSelect);
                }
            },

            selectRow: function(rowIndex, keepSelections) {
                var row = this.rows[rowIndex];

                if(keepSelections == false) this.clearSelections();
                if(row && this.isSelected(row) == false && $(row).trigger('beforerowselect') !== false) {
                    if(row.preventChange !== true) {
                        this.selections.push(row);
                        this.focusRow(rowIndex);
                        $(row).trigger('rowselect');
                        $(row).trigger('afterrowselect');
                        $(document).trigger('rowchange', this);
                    }
                    row.preventChange = undefined;
                }
            },

            deselectRow: function(rowIndex) {
                var row = this.rows[rowIndex];

                if(row && this.isSelected(row) && $(row).trigger('beforerowdeselect') !== false) {
                    if(row.preventChange !== true) {
                        var index = $.inArray(row, this.selections);
                        if(-1 != index) {
                            this.selections.splice(index, 1);
                            this.focusRow(rowIndex);
                            $(row).trigger('rowdeselect');
                            $(row).trigger('afterrowdeselect');
                            $(document).trigger('rowchange', this);
                        }
                    }
                    row.preventChange = undefined;
                }
            },

            focusRow: function(rowIndex) {
                this.lastActiveRow = rowIndex;
            },

            rowSelectClass: function(event) {
                switch(event.type) {
                    case 'rowselect':
                        $(this).addClass(this.parentThis.options.rowSelectClass);
                        break;
                    case 'rowdeselect':
                        $(this).removeClass(this.parentThis.options.rowSelectClass);
                        break;
                    default: break;
                }
            },

            selectAll: function() {
                if(this.options.multiSelect) {
                    this.clearSelections();
                    $(this.rows).each(function() {
                        this.parentThis.selectRow(this.sectionRowIndex, true);
                    });
                }
            },

            clearSelections: function() {
                $(this.rows).each(function() {
                    this.parentThis.deselectRow(this.sectionRowIndex);
                });
            },

            selectRange: function(startIndex, endIndex, keepSelections) {
                if(keepSelections == false) this.clearSelections();
                if(startIndex <= endIndex) {
                    for(var i=startIndex; i<=endIndex; i++) {
                        this.selectRow(i, true);
                    }
                }
                else {
                    for(var i=startIndex; i>=endIndex; i--) {
                        this.selectRow(i, true);
                    }
                }
            }
        }
    });
})(jQuery);
<commit_msg>Use '===' to compare with 'false'<commit_after>/*!
 * jQuery tableSelect plugin 1.3.0
 *
 * Copyright (c) 2010, 2014 Kjel Delaey
 * Released under the MIT license
 * https://raw.github.com/trimentor/jquery-tableSelect/master/LICENSE
*/

(function($) {
    $.extend($.fn, {
        tableSelect: function(options) {
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.extend($.fn, {
        tableSelectOne: function(options) {
            var options   = $.extend({multiSelect: false}, options);
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.extend($.fn, {
        tableSelectMany: function(options) {
            var options   = $.extend({multiSelect: true}, options);
            tableSelector = new $.tableSelector(options, this);
            return tableSelector;
        }
    });

    $.tableSelector = function(options, table) {
        this.options      = $.extend({}, $.tableSelector.defaults, options);
        this.currentTable = table;
        this.init();
    };

    $.extend($.tableSelector, {
        defaults: {
            tableClass:     "tableselect",
            rowSelectClass: "selected",
            multiSelect:    false
        },

        prototype: {
            init: function() {
                this.selections = [];
                this.listeners  = this.options.listeners || {};
                this.collectRows();
                this.initRowEvents();

                $(this.currentTable).addClass(this.options.tableClass);
            },

            allSelected: function() {
                return (this.selections.length == this.rows.length);
            },

            getSelections: function() {
                return this.selections;
            },

            getFocusedRow: function() {
                return this.rows[this.lastActiveRow];
            },

            isSelected: function(row) {
                var bool = false;
                for(var i=0; i<this.selections.length; i++) {
                    if(this.selections[i] == row) {
                        bool = true;
                        break;
                    }
                }
                return bool;
            },

            collectRows: function() {
                var table = this;
                this.rows = this.currentTable[0].tBodies[0].rows;
                $(this.rows).each(function() {
                    this.parentThis = table;
                });
            },

            initRowEvents: function() {
                var table = this;
                $(this.rows).each(function() {
                    $(this).bind('click', table.handleMouseDown);
                    $(this).bind('rowselect', table.rowSelectClass);
                    $(this).bind('rowdeselect', table.rowSelectClass);
                    table.initListeners(table, this);
                });
            },

            initListeners: function(table, row) {
                if(table.listeners) {
                    var listeners = table.listeners;
                    if(listeners.beforerowselect)   $(row).bind('beforerowselect',   listeners.beforerowselect);
                    if(listeners.afterrowselect)    $(row).bind('afterrowselect',    listeners.afterrowselect);
                    if(listeners.beforerowdeselect) $(row).bind('beforerowdeselect', listeners.beforerowdeselect);
                    if(listeners.afterrowdeselect)  $(row).bind('afterrowdeselect',  listeners.afterrowdeselect);
                }
            },

            handleMouseDown: function(event) {
                var table = this.parentThis;
                table.storeEventTarget(event, this);

                if(table.options.multiSelect) {
                    table.handleKeyDown(event, this);
                }
                else {
                    table.handleSingleSelect(this);
                }

                table.resetEventTarget(this);
            },

            handleKeyDown: function(event, row) {
                var rowIndex = row.sectionRowIndex;

                if(event.shiftKey) {
                    if(typeof(this.lastActiveRow) == "undefined") this.focusRow(rowIndex);
                    this.lockedRow = this.lastActiveRow;
                    if(event.ctrlKey) {
                        this.selectRange(this.lastActiveRow, rowIndex, true);
                    }
                    else {
                        this.selectRange(this.lockedRow, rowIndex, false);
                        this.focusRow(this.lockedRow);
                    }
                }
                else {
                    this.handleSingleSelect(row);
                }
            },

            storeEventTarget: function(event, row) {
                var target = event.target && event.target.nodeName;
                row.target = target ? target.toLowerCase() : null;
            },

            resetEventTarget: function(row) {
                row.target = undefined;
            },

            handleSingleSelect: function(row) {
                var rowIndex = row.sectionRowIndex;

                if(this.isSelected(row)) {
                    this.deselectRow(rowIndex);
                }
                else {
                    this.selectRow(rowIndex, this.options.multiSelect);
                }
            },

            selectRow: function(rowIndex, keepSelections) {
                var row = this.rows[rowIndex];

                if(keepSelections === false) this.clearSelections();
                if(row && this.isSelected(row) === false && $(row).trigger('beforerowselect') !== false) {
                    if(row.preventChange !== true) {
                        this.selections.push(row);
                        this.focusRow(rowIndex);
                        $(row).trigger('rowselect');
                        $(row).trigger('afterrowselect');
                        $(document).trigger('rowchange', this);
                    }
                    row.preventChange = undefined;
                }
            },

            deselectRow: function(rowIndex) {
                var row = this.rows[rowIndex];

                if(row && this.isSelected(row) && $(row).trigger('beforerowdeselect') !== false) {
                    if(row.preventChange !== true) {
                        var index = $.inArray(row, this.selections);
                        if(-1 != index) {
                            this.selections.splice(index, 1);
                            this.focusRow(rowIndex);
                            $(row).trigger('rowdeselect');
                            $(row).trigger('afterrowdeselect');
                            $(document).trigger('rowchange', this);
                        }
                    }
                    row.preventChange = undefined;
                }
            },

            focusRow: function(rowIndex) {
                this.lastActiveRow = rowIndex;
            },

            rowSelectClass: function(event) {
                switch(event.type) {
                    case 'rowselect':
                        $(this).addClass(this.parentThis.options.rowSelectClass);
                        break;
                    case 'rowdeselect':
                        $(this).removeClass(this.parentThis.options.rowSelectClass);
                        break;
                    default: break;
                }
            },

            selectAll: function() {
                if(this.options.multiSelect) {
                    this.clearSelections();
                    $(this.rows).each(function() {
                        this.parentThis.selectRow(this.sectionRowIndex, true);
                    });
                }
            },

            clearSelections: function() {
                $(this.rows).each(function() {
                    this.parentThis.deselectRow(this.sectionRowIndex);
                });
            },

            selectRange: function(startIndex, endIndex, keepSelections) {
                if(keepSelections === false) this.clearSelections();
                if(startIndex <= endIndex) {
                    for(var i=startIndex; i<=endIndex; i++) {
                        this.selectRow(i, true);
                    }
                }
                else {
                    for(var i=startIndex; i>=endIndex; i--) {
                        this.selectRow(i, true);
                    }
                }
            }
        }
    });
})(jQuery);
<|endoftext|>