<commit_before>'use strict';

const Path = require('path');
const Webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractSASS = new ExtractTextPlugin('./[name].[hash].css');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const webpack = require('webpack');

const pages = require('./src/pages');
let renderedPages = [];
for (let i = 0; i < pages.length; i++) {
  let page = Object.assign({}, pages[i]);
  renderedPages.push(
    new HtmlWebpackPlugin({
      template: page.template,
      filename: page.output,
      title: page.content.title,
      description: page.content.description
    })
  );
}

module.exports = (options) => {
  const dest = Path.join(__dirname, 'dist');

  let webpackConfig = {
    devtool: options.devtool,
    entry: ['./src/app.js'],
    output: {
      path: dest,
      filename: './assets/scripts/[name].[hash].js'
    },
    plugins: [
      new Webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Tether: 'tether',
        'window.Tether': 'tether',
        Popper: ['popper.js', 'default'],
      }),
      new CopyWebpackPlugin([
        {from: './src/assets/images', to: './assets/images'}
      ]),
      new CopyWebpackPlugin([
        {from: './src/assets/fonts', to: './assets/fonts'}
      ]),
      new Webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development')
        }
      })
    ],
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: "babel-loader"
        },
        {
          test: /\.hbs$/,
          loader: 'handlebars-loader',
          query: {
            helperDirs: [
              Path.join(__dirname, 'src', 'helpers')
            ],
            partialDirs: [
              Path.join(__dirname, 'src', 'layouts'),
              Path.join(__dirname, 'src', 'components'),
              Path.join(__dirname, 'src', 'pages')
            ]
          }
        },
        {
          test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
          use: [{
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
              outputPath: './assets/fonts'
            }
          }]
        },
        {
          test: /\.(gif|jpg|png)$/,
          loader: "file-loader",
        }
      ]
    }
  };

  if (options.isProduction) {
    webpackConfig.entry = ['./src/app.js'];

    webpackConfig.plugins.push(
      ExtractSASS,
      new CleanWebpackPlugin(['dist'], {
        verbose: true,
        dry: false
      })
    );

    webpackConfig.module.rules.push({
      test: /\.scss$/i,
      use: ExtractSASS.extract(['css-loader', 'sass-loader'])
    }, {
      test: /\.css$/i,
      use: ExtractSASS.extract(['css-loader'])
    });

  } else {
    webpackConfig.plugins.push(
      new Webpack.HotModuleReplacementPlugin()
    );

    webpackConfig.module.rules.push({
      test: /\.scss$/i,
      use: ['style-loader?sourceMap', 'css-loader?sourceMap', 'sass-loader?sourceMap']
    }, {
      test: /\.css$/i,
      use: ['style-loader', 'css-loader']
    }, {
      test: /\.js$/,
      use: 'eslint-loader',
      exclude: /node_modules/
    });

    webpackConfig.devServer = {
      port: options.port,
      contentBase: dest,
      historyApiFallback: true,
      compress: options.isProduction,
      inline: !options.isProduction,
      hot: !options.isProduction,
      stats: {
        chunks: false
      }
    };

    webpackConfig.plugins.push(
      new BrowserSyncPlugin({
        host: 'localhost',
        port: 3001,
        proxy: 'http://localhost:8081/',
        files: [{
          match: [
            '**/*.hbs'
          ],
          fn: function (event, file) {
            if (event === "change" || event === "add" || event === "unlink") {
              const bs = require('browser-sync').get('bs-webpack-plugin');
              bs.reload();
            }
          }
        }]
      }, {
        reload: false
      })
    );

  }

  webpackConfig.plugins = webpackConfig.plugins.concat(renderedPages);

  return webpackConfig;

};
<commit_msg>Fix build image dir placement<commit_after>'use strict';

const Path = require('path');
const Webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractSASS = new ExtractTextPlugin('./[name].[hash].css');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const webpack = require('webpack');

const pages = require('./src/pages');
let renderedPages = [];
for (let i = 0; i < pages.length; i++) {
  let page = Object.assign({}, pages[i]);
  renderedPages.push(
    new HtmlWebpackPlugin({
      template: page.template,
      filename: page.output,
      title: page.content.title,
      description: page.content.description
    })
  );
}

module.exports = (options) => {
  const dest = Path.join(__dirname, 'dist');

  let webpackConfig = {
    devtool: options.devtool,
    entry: ['./src/app.js'],
    output: {
      path: dest,
      filename: './assets/scripts/[name].[hash].js'
    },
    plugins: [
      new Webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Tether: 'tether',
        'window.Tether': 'tether',
        Popper: ['popper.js', 'default'],
      }),
      new CopyWebpackPlugin([
        {from: './src/assets/images', to: './assets/images'}
      ]),
      new CopyWebpackPlugin([
        {from: './src/assets/fonts', to: './assets/fonts'}
      ]),
      new Webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development')
        }
      })
    ],
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        },
        {
          test: /\.hbs$/,
          loader: 'handlebars-loader',
          query: {
            helperDirs: [
              Path.join(__dirname, 'src', 'helpers')
            ],
            partialDirs: [
              Path.join(__dirname, 'src', 'layouts'),
              Path.join(__dirname, 'src', 'components'),
              Path.join(__dirname, 'src', 'pages')
            ]
          }
        },
        {
          test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
          use: [{
            loader: 'file-loader',
            options: {
              name: '[name].[ext]',
              outputPath: './assets/fonts'
            }
          }]
        },
        {
          test: /\.(gif|jpg|png)$/,
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: './assets/images'
          }
        }
      ]
    }
  };

  if (options.isProduction) {
    webpackConfig.entry = ['./src/app.js'];

    webpackConfig.plugins.push(
      ExtractSASS,
      new CleanWebpackPlugin(['dist'], {
        verbose: true,
        dry: false
      })
    );

    webpackConfig.module.rules.push({
      test: /\.scss$/i,
      use: ExtractSASS.extract(['css-loader', 'sass-loader'])
    }, {
      test: /\.css$/i,
      use: ExtractSASS.extract(['css-loader'])
    });

  } else {
    webpackConfig.plugins.push(
      new Webpack.HotModuleReplacementPlugin()
    );

    webpackConfig.module.rules.push({
      test: /\.scss$/i,
      use: ['style-loader?sourceMap', 'css-loader?sourceMap', 'sass-loader?sourceMap']
    }, {
      test: /\.css$/i,
      use: ['style-loader', 'css-loader']
    }, {
      test: /\.js$/,
      use: 'eslint-loader',
      exclude: /node_modules/
    });

    webpackConfig.devServer = {
      port: options.port,
      contentBase: dest,
      historyApiFallback: true,
      compress: options.isProduction,
      inline: !options.isProduction,
      hot: !options.isProduction,
      stats: {
        chunks: false
      }
    };

    webpackConfig.plugins.push(
      new BrowserSyncPlugin({
        host: 'localhost',
        port: 3001,
        proxy: 'http://localhost:8081/',
        files: [{
          match: [
            '**/*.hbs'
          ],
          fn: function (event, file) {
            if (event === 'change' || event === 'add' || event === 'unlink') {
              const bs = require('browser-sync').get('bs-webpack-plugin');
              bs.reload();
            }
          }
        }]
      }, {
        reload: false
      })
    );

  }

  webpackConfig.plugins = webpackConfig.plugins.concat(renderedPages);

  return webpackConfig;

};
<|endoftext|>


<commit_before>/*! ============================================================
 * bootstrapSwitch v1.8 by Larentis Mattia @SpiritualGuru
 * http://www.larentis.eu/
 *
 * Enhanced for radiobuttons by Stein, Peter @BdMdesigN
 * http://www.bdmdesign.org/
 *
 * Project site:
 * http://www.larentis.eu/switch/
 * ============================================================
 * Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 * ============================================================ */

!function ($) {
  "use strict";

  $.fn['bootstrapSwitch'] = function (method) {
    var inputSelector = 'input[type!="hidden"]';
    var methods = {
      init: function () {
        return this.each(function () {
            var $element = $(this)
              , $div
              , $switchLeft
              , $switchRight
              , $label
              , $form = $element.closest('form')
              , myClasses = ""
              , classes = $element.attr('class')
              , color
              , moving
              , onLabel = "ON"
              , offLabel = "OFF"
              , icon = false
              , textLabel = false;

            $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
              if (classes.indexOf(el) >= 0)
                myClasses = el;
            });

            $element.addClass('has-switch');

            if ($element.data('on'))
              color = "switch-" + $element.data('on');

            if ($element.data('on-label') !== undefined)
              onLabel = $element.data('on-label');

            if ($element.data('off-label') !== undefined)
              offLabel = $element.data('off-label');

            if ($element.data('label-icon') !== undefined)
              icon = $element.data('label-icon');

            if ($element.data('text-label') !== undefined)
              textLabel = $element.data('text-label');

            $switchLeft = $('')
              .addClass("switch-left")
              .addClass(myClasses)
              .addClass(color)
              .html(onLabel);

            color = '';
            if ($element.data('off'))
              color = "switch-" + $element.data('off');

            $switchRight = $('')
              .addClass("switch-right")
              .addClass(myClasses)
              .addClass(color)
              .html(offLabel);

            $label = $('')
              .html(" ")
              .addClass(myClasses)
              .attr('for', $element.find(inputSelector).attr('id'));

            if (icon) {
              $label.html('');
            }

            if (textLabel) {
              $label.html('' + textLabel + '');
            }

            $div = $element.find(inputSelector).wrap($('
')).parent().data('animated', false);

            if ($element.data('animated') !== false)
              $div.addClass('switch-animate').data('animated', true);

            $div
              .append($switchLeft)
              .append($label)
              .append($switchRight);

            $element.find('>div').addClass(
              $element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off'
            );

            if ($element.find(inputSelector).is(':disabled'))
              $(this).addClass('deactivate');

            var changeStatus = function ($this) {
              if ($element.parent('label').is('.label-change-switch')) {

              } else {
                $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
              }
            };

            $element.on('keydown', function (e) {
              if (e.keyCode === 32) {
                e.stopImmediatePropagation();
                e.preventDefault();
                changeStatus($(e.target).find('span:first'));
              }
            });

            $switchLeft.on('click', function (e) {
              changeStatus($(this));
            });

            $switchRight.on('click', function (e) {
              changeStatus($(this));
            });

            $element.find(inputSelector).on('change', function (e, skipOnChange) {
              var $this = $(this)
                , $element = $this.parent()
                , thisState = $this.is(':checked')
                , state = $element.is('.switch-off');

              e.preventDefault();

              $element.css('left', '');

              if (state === thisState) {

                if (thisState)
                  $element.removeClass('switch-off').addClass('switch-on');
                else $element.removeClass('switch-on').addClass('switch-off');

                if ($element.data('animated') !== false)
                  $element.addClass("switch-animate");

                if (typeof skipOnChange === 'boolean' && skipOnChange)
                  return;

                $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
              }
            });

            $element.find('label').on('mousedown touchstart', function (e) {
              var $this = $(this);
              moving = false;

              e.preventDefault();
              e.stopImmediatePropagation();

              $this.closest('div').removeClass('switch-animate');

              if ($this.closest('.has-switch').is('.deactivate')) {
                $this.unbind('click');
              } else if ($this.closest('.switch-on').parent().is('.radio-no-uncheck')) {
                $this.unbind('click');
              } else {
                $this.on('mousemove touchmove', function (e) {
                  var $element = $(this).closest('.make-switch')
                    , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
                    , percent = (relativeX / $element.width()) * 100
                    , left = 25
                    , right = 75;

                  moving = true;

                  if (percent < left)
                    percent = left;
                  else if (percent > right)
                    percent = right;

                  $element.find('>div').css('left', (percent - right) + "%")
                });

                $this.on('click touchend', function (e) {
                  var $this = $(this)
                    , $target = $(e.target)
                    , $myRadioCheckBox = $target.siblings('input');

                  e.stopImmediatePropagation();
                  e.preventDefault();

                  $this.unbind('mouseleave');

                  if (moving)
                    $myRadioCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
                  else
                    $myRadioCheckBox.prop("checked", !$myRadioCheckBox.is(":checked"));

                  moving = false;
                  $myRadioCheckBox.trigger('change');
                });

                $this.on('mouseleave', function (e) {
                  var $this = $(this)
                    , $myInputBox = $this.siblings('input');

                  e.preventDefault();
                  e.stopImmediatePropagation();

                  $this.unbind('mouseleave');
                  $this.trigger('mouseup');

                  $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
                });

                $this.on('mouseup', function (e) {
                  e.stopImmediatePropagation();
                  e.preventDefault();

                  $(this).unbind('mousemove');
                });
              }
            });

            if ($form.data('bootstrapSwitch') !== 'injected') {
              $form.bind('reset', function () {
                setTimeout(function () {
                  $form.find('.make-switch').each(function () {
                    var $input = $(this).find(inputSelector);

                    $input.prop('checked', $input.is(':checked')).trigger('change');
                  });
                }, 1);
              });
              $form.data('bootstrapSwitch', 'injected');
            }
          }
        );
      },
      toggleActivation: function () {
        var $this = $(this);

        $this.toggleClass('deactivate');
        $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
      },
      isActive: function () {
        return !$(this).hasClass('deactivate');
      },
      setActive: function (active) {
        var $this = $(this);

        if (active) {
          $this.removeClass('deactivate');
          $this.find(inputSelector).removeAttr('disabled');
        }
        else {
          $this.addClass('deactivate');
          $this.find(inputSelector).attr('disabled', 'disabled');
        }
      },
      toggleState: function (skipOnChange) {
        var $input = $(this).find(':checkbox');
        $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
      },
      toggleRadioState: function (skipOnChange) {
        var $radioinput = $(this).find(':radio');
        $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
      },
      toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
        var $radioinput = $(this).find(':radio');
        if (uncheck) {
          $radioinput.not(':checked').trigger('change', skipOnChange);
        }
        else {
          $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
        }
      },
      setState: function (value, skipOnChange) {
        $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
      },
      setOnLabel: function (value) {
        var $switchLeft = $(this).find(".switch-left");
        $switchLeft.html(value);
      },
      setOffLabel: function (value) {
        var $switchRight = $(this).find(".switch-right");
        $switchRight.html(value);
      },
      setOnClass: function (value) {
        var $switchLeft = $(this).find(".switch-left");
        var color = '';
        if (value) {
          // Delete the old color
          if ($(this).attr('data-on') !== undefined) {
            color = "switch-" + $(this).attr('data-on');
          }
          $switchLeft.removeClass(color);
          // Add the new color
          color = "switch-" + value;
          $switchLeft.addClass(color);
        }
      },
      setOffClass: function (value) {
        var $switchRight = $(this).find(".switch-right");
        var color = '';
        if (value) {
          // Delete the old color
          if ($(this).attr('data-off') !== undefined) {
            color = "switch-" + $(this).attr('data-off');
          }
          $switchRight.removeClass(color);
          // Add the new color
          color = "switch-" + value;
          $switchRight.addClass(color);
        }
      },
      setAnimated: function (value) {
        var $element = $(this).find(inputSelector).parent();
        if (value === undefined) value = false;
        $element.data('animated', value);
        $element.attr('data-animated', value);

        if ($element.data('animated') !== false) {
          $element.addClass("switch-animate");
        } else {
          $element.removeClass("switch-animate");
        }
      },
      setSizeClass: function (value) {
        var $element = $(this);
        var $switchLeft = $element.find(".switch-left");
        var $switchRight = $element.find(".switch-right");
        var $label = $element.find("label");
        $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
          if (el !== value) {
            $switchLeft.removeClass(el)
            $switchRight.removeClass(el);
            $label.removeClass(el);
          } else {
            $switchLeft.addClass(el);
            $switchRight.addClass(el);
            $label.addClass(el);
          }
        });
      },
      setTextLabel: function(value) {
        var $label = $(this).find("label");
        $label.html('' + value || '&nbsp' + '');
      },
      setTextIcon: function(value) {
        var $label = $(this).find("label");''
        $label.html(value ? '' : ' ');
      },
      status: function () {
        return $(this).find(inputSelector).is(':checked');
      },
      destroy: function () {
        var $element = $(this)
          , $div = $element.find('div')
          , $form = $element.closest('form')
          , $inputbox;

        $div.find(':not(input)').remove();

        $inputbox = $div.children();
        $inputbox.unwrap().unwrap();

        $inputbox.unbind('change');

        if ($form) {
          $form.unbind('reset');
          $form.removeData('bootstrapSwitch');
        }

        return $inputbox;
      }
    };

    if (methods[method])
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    else if (typeof method === 'object' || !method)
      return methods.init.apply(this, arguments);
    else
      $.error('Method ' + method + ' does not exist!');
  };
}(jQuery);

(function ($) {
  $(function () {
    $('.make-switch')['bootstrapSwitch']();
  });
})(jQuery);
<commit_msg>Add missing semicolon<commit_after>/*! ============================================================
 * bootstrapSwitch v1.8 by Larentis Mattia @SpiritualGuru
 * http://www.larentis.eu/
 *
 * Enhanced for radiobuttons by Stein, Peter @BdMdesigN
 * http://www.bdmdesign.org/
 *
 * Project site:
 * http://www.larentis.eu/switch/
 * ============================================================
 * Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 * ============================================================ */

!function ($) {
  "use strict";

  $.fn['bootstrapSwitch'] = function (method) {
    var inputSelector = 'input[type!="hidden"]';
    var methods = {
      init: function () {
        return this.each(function () {
            var $element = $(this)
              , $div
              , $switchLeft
              , $switchRight
              , $label
              , $form = $element.closest('form')
              , myClasses = ""
              , classes = $element.attr('class')
              , color
              , moving
              , onLabel = "ON"
              , offLabel = "OFF"
              , icon = false
              , textLabel = false;

            $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
              if (classes.indexOf(el) >= 0)
                myClasses = el;
            });

            $element.addClass('has-switch');

            if ($element.data('on'))
              color = "switch-" + $element.data('on');

            if ($element.data('on-label') !== undefined)
              onLabel = $element.data('on-label');

            if ($element.data('off-label') !== undefined)
              offLabel = $element.data('off-label');

            if ($element.data('label-icon') !== undefined)
              icon = $element.data('label-icon');

            if ($element.data('text-label') !== undefined)
              textLabel = $element.data('text-label');

            $switchLeft = $('')
              .addClass("switch-left")
              .addClass(myClasses)
              .addClass(color)
              .html(onLabel);

            color = '';
            if ($element.data('off'))
              color = "switch-" + $element.data('off');

            $switchRight = $('')
              .addClass("switch-right")
              .addClass(myClasses)
              .addClass(color)
              .html(offLabel);

            $label = $('')
              .html(" ")
              .addClass(myClasses)
              .attr('for', $element.find(inputSelector).attr('id'));

            if (icon) {
              $label.html('');
            }

            if (textLabel) {
              $label.html('' + textLabel + '');
            }

            $div = $element.find(inputSelector).wrap($('
')).parent().data('animated', false);

            if ($element.data('animated') !== false)
              $div.addClass('switch-animate').data('animated', true);

            $div
              .append($switchLeft)
              .append($label)
              .append($switchRight);

            $element.find('>div').addClass(
              $element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off'
            );

            if ($element.find(inputSelector).is(':disabled'))
              $(this).addClass('deactivate');

            var changeStatus = function ($this) {
              if ($element.parent('label').is('.label-change-switch')) {

              } else {
                $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
              }
            };

            $element.on('keydown', function (e) {
              if (e.keyCode === 32) {
                e.stopImmediatePropagation();
                e.preventDefault();
                changeStatus($(e.target).find('span:first'));
              }
            });

            $switchLeft.on('click', function (e) {
              changeStatus($(this));
            });

            $switchRight.on('click', function (e) {
              changeStatus($(this));
            });

            $element.find(inputSelector).on('change', function (e, skipOnChange) {
              var $this = $(this)
                , $element = $this.parent()
                , thisState = $this.is(':checked')
                , state = $element.is('.switch-off');

              e.preventDefault();

              $element.css('left', '');

              if (state === thisState) {

                if (thisState)
                  $element.removeClass('switch-off').addClass('switch-on');
                else $element.removeClass('switch-on').addClass('switch-off');

                if ($element.data('animated') !== false)
                  $element.addClass("switch-animate");

                if (typeof skipOnChange === 'boolean' && skipOnChange)
                  return;

                $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
              }
            });

            $element.find('label').on('mousedown touchstart', function (e) {
              var $this = $(this);
              moving = false;

              e.preventDefault();
              e.stopImmediatePropagation();

              $this.closest('div').removeClass('switch-animate');

              if ($this.closest('.has-switch').is('.deactivate')) {
                $this.unbind('click');
              } else if ($this.closest('.switch-on').parent().is('.radio-no-uncheck')) {
                $this.unbind('click');
              } else {
                $this.on('mousemove touchmove', function (e) {
                  var $element = $(this).closest('.make-switch')
                    , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
                    , percent = (relativeX / $element.width()) * 100
                    , left = 25
                    , right = 75;

                  moving = true;

                  if (percent < left)
                    percent = left;
                  else if (percent > right)
                    percent = right;

                  $element.find('>div').css('left', (percent - right) + "%")
                });

                $this.on('click touchend', function (e) {
                  var $this = $(this)
                    , $target = $(e.target)
                    , $myRadioCheckBox = $target.siblings('input');

                  e.stopImmediatePropagation();
                  e.preventDefault();

                  $this.unbind('mouseleave');

                  if (moving)
                    $myRadioCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
                  else
                    $myRadioCheckBox.prop("checked", !$myRadioCheckBox.is(":checked"));

                  moving = false;
                  $myRadioCheckBox.trigger('change');
                });

                $this.on('mouseleave', function (e) {
                  var $this = $(this)
                    , $myInputBox = $this.siblings('input');

                  e.preventDefault();
                  e.stopImmediatePropagation();

                  $this.unbind('mouseleave');
                  $this.trigger('mouseup');

                  $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
                });

                $this.on('mouseup', function (e) {
                  e.stopImmediatePropagation();
                  e.preventDefault();

                  $(this).unbind('mousemove');
                });
              }
            });

            if ($form.data('bootstrapSwitch') !== 'injected') {
              $form.bind('reset', function () {
                setTimeout(function () {
                  $form.find('.make-switch').each(function () {
                    var $input = $(this).find(inputSelector);

                    $input.prop('checked', $input.is(':checked')).trigger('change');
                  });
                }, 1);
              });
              $form.data('bootstrapSwitch', 'injected');
            }
          }
        );
      },
      toggleActivation: function () {
        var $this = $(this);

        $this.toggleClass('deactivate');
        $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
      },
      isActive: function () {
        return !$(this).hasClass('deactivate');
      },
      setActive: function (active) {
        var $this = $(this);

        if (active) {
          $this.removeClass('deactivate');
          $this.find(inputSelector).removeAttr('disabled');
        }
        else {
          $this.addClass('deactivate');
          $this.find(inputSelector).attr('disabled', 'disabled');
        }
      },
      toggleState: function (skipOnChange) {
        var $input = $(this).find(':checkbox');
        $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
      },
      toggleRadioState: function (skipOnChange) {
        var $radioinput = $(this).find(':radio');
        $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
      },
      toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
        var $radioinput = $(this).find(':radio');
        if (uncheck) {
          $radioinput.not(':checked').trigger('change', skipOnChange);
        }
        else {
          $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
        }
      },
      setState: function (value, skipOnChange) {
        $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
      },
      setOnLabel: function (value) {
        var $switchLeft = $(this).find(".switch-left");
        $switchLeft.html(value);
      },
      setOffLabel: function (value) {
        var $switchRight = $(this).find(".switch-right");
        $switchRight.html(value);
      },
      setOnClass: function (value) {
        var $switchLeft = $(this).find(".switch-left");
        var color = '';
        if (value) {
          // Delete the old color
          if ($(this).attr('data-on') !== undefined) {
            color = "switch-" + $(this).attr('data-on');
          }
          $switchLeft.removeClass(color);
          // Add the new color
          color = "switch-" + value;
          $switchLeft.addClass(color);
        }
      },
      setOffClass: function (value) {
        var $switchRight = $(this).find(".switch-right");
        var color = '';
        if (value) {
          // Delete the old color
          if ($(this).attr('data-off') !== undefined) {
            color = "switch-" + $(this).attr('data-off');
          }
          $switchRight.removeClass(color);
          // Add the new color
          color = "switch-" + value;
          $switchRight.addClass(color);
        }
      },
      setAnimated: function (value) {
        var $element = $(this).find(inputSelector).parent();
        if (value === undefined) value = false;
        $element.data('animated', value);
        $element.attr('data-animated', value);

        if ($element.data('animated') !== false) {
          $element.addClass("switch-animate");
        } else {
          $element.removeClass("switch-animate");
        }
      },
      setSizeClass: function (value) {
        var $element = $(this);
        var $switchLeft = $element.find(".switch-left");
        var $switchRight = $element.find(".switch-right");
        var $label = $element.find("label");
        $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
          if (el !== value) {
            $switchLeft.removeClass(el);
            $switchRight.removeClass(el);
            $label.removeClass(el);
          } else {
            $switchLeft.addClass(el);
            $switchRight.addClass(el);
            $label.addClass(el);
          }
        });
      },
      setTextLabel: function(value) {
        var $label = $(this).find("label");
        $label.html('' + value || '&nbsp' + '');
      },
      setTextIcon: function(value) {
        var $label = $(this).find("label");''
        $label.html(value ? '' : ' ');
      },
      status: function () {
        return $(this).find(inputSelector).is(':checked');
      },
      destroy: function () {
        var $element = $(this)
          , $div = $element.find('div')
          , $form = $element.closest('form')
          , $inputbox;

        $div.find(':not(input)').remove();

        $inputbox = $div.children();
        $inputbox.unwrap().unwrap();

        $inputbox.unbind('change');

        if ($form) {
          $form.unbind('reset');
          $form.removeData('bootstrapSwitch');
        }

        return $inputbox;
      }
    };

    if (methods[method])
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    else if (typeof method === 'object' || !method)
      return methods.init.apply(this, arguments);
    else
      $.error('Method ' + method + ' does not exist!');
  };
}(jQuery);

(function ($) {
  $(function () {
    $('.make-switch')['bootstrapSwitch']();
  });
})(jQuery);
<|endoftext|>


<commit_before>/*! carousel.js v1.0 | MIT License | https://github.com/oldrivercreative/carousel */
(function($){
	$.fn.carousel = function(options){

		// settings
		var settings = $.extend({}, {
			paging: false,
            navigation: false,
            loop: false,
            autoplay: false,
            delay: 12000,
            buttons: {
                previous: 'Previous',
                next: 'Next',
                navigation: '%i'
            },
			movethreshold: 10,
			swipethreshold: 10,
			oninit: false,
			onupdate: false,
            destroy: false
		}, options);

        // autoplay timer
        var timer = false;

        // transform?
        window.optimusPrime = false;
        if('WebkitTransform' in document.body.style || 'MozTransform' in document.body.style || 'transform' in document.body.style){
            window.optimusPrime = true;
        }

		// carousel
		this.each(function(){

			// get objects
			var carousel = $(this);
			var shaker = carousel.find('ul:eq(0)');

            // destroy?
            if(settings.destroy){
                carousel.trigger('carousel-destroy');
            }

            // create
            else {

                // init
                carousel.on('carousel-init', function(){

                    // data
                    carousel.data('carousel-position', 0);
                    carousel.data('carousel-touch-change', 0);
                    carousel.data('carousel-last-touch', false);
                    carousel.data('carousel-item-count', shaker.children().size());

                    // add classes
                    carousel.addClass('ui-carousel');
                    shaker.addClass('ui-carousel-shaker');

                    // paging?
                    if(settings.paging){

                        // previous
                        var previous = $('<button class="previous">' + settings.buttons.previous + '</button>');
                        previous.on('click', function(e){
                            e.preventDefault();

                            // not a touch gesture
                            carousel.data('carousel-last-touch', false);

                            // retreat
                            carousel.trigger('carousel-retreat');

                        });
                        carousel.append(previous);

                        // next
                        var next = $('<button class="next">' + settings.buttons.next + '</button>');
                        next.on('click', function(e){
                            e.preventDefault();

                            // not a touch gesture
                            carousel.data('carousel-last-touch', false);

                            // advance
                            carousel.trigger('carousel-advance');

                        });
                        carousel.append(next);

                    }

                    // navigation?
                    if(settings.navigation){

                        // nav list
                        var ul = $('
');
                        for(var i = 0; i < carousel.data('carousel-item-count'); i++){

                            // <button>
                            var navlabel = settings.buttons.navigation.replace('%i', (i+1));
                            var button = $('<button>' + navlabel + '</button>');
                            button.data('carousel-item', i);
                            button.on('click', function(e){
                                e.preventDefault();

                                // set new position
                                var p = $(this).data('carousel-item');
                                var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                                p = p * slidewidth * -1;
                                carousel.data('carousel-position', p);

                                // not a touch gesture
                                carousel.data('carousel-last-touch', false);

                                // contain
                                carousel.trigger('carousel-contain');

                                // slide
                                carousel.trigger('carousel-slide');

                            });

                            //

                            var li = $('
');
                            li.append(button);

                            // active?
                            if(i == 0){
                                li.addClass('ui-active');
                            }

                            // add to nav list
                            ul.append(li);

                        }

                        // add
                        carousel.append(ul);

                    }

                    // contain
                    carousel.trigger('carousel-contain');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-queue');
                    }

                    // oninit?
                    if(typeof(settings.oninit) == 'function'){
                        settings.oninit();
                    }

                });

                // touch-down
                carousel.on('carousel-touch-down', function(e, position){

                    // add classes
                    carousel.addClass('ui-touch-threshold');

                    // starting point
                    carousel.data('carousel-touch-start', {
                        x: position.x,
                        y: $(window).scrollTop()
                    });

                    // disable autoplay while swiping
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                    }

                });

                // touch-move
                carousel.on('carousel-touch-move', function(e, position){

                    // threshold?
                    if(carousel.hasClass('ui-touch-threshold')){

                        // get starting position
                        var start = carousel.data('carousel-touch-start');

                        // scrolling?
                        if(Math.abs($(window).scrollTop() - start.y) >= settings.movethreshold){
                            carousel.removeClass('ui-touch-threshold');
                        }

                        // swiping?
                        else if(Math.abs(position.x - start.x) >= settings.movethreshold){
                            carousel.removeClass('ui-touch-threshold').addClass('ui-touch-swiping');
                            $('body').addClass('ui-swiping');
                        }

                    }

                    // swiping?
                    if(carousel.hasClass('ui-touch-swiping')){

                        // position
                        var start = carousel.data('carousel-touch-start');
                        var distance = position.x - start.x;
                        var position = carousel.data('carousel-position');
                        var change = distance / shaker.width() * 100;
                        carousel.data('carousel-touch-change', change);

                        // shake it
                        var p = position + change;
                        if(window.optimusPrime){
                            shaker.css({
                                WebkitTransform: 'translateX(' + p + '%)',
                                MozTransform: 'translateX(' + p + '%)',
                                transform: 'translateX(' + p + '%)'
                            });
                        }
                        else{
                            shaker.css('left', p + '%');
                        }

                        // onupdate?
                        if(typeof(settings.onupdate) == 'function'){
                            settings.onupdate(p);
                        }

                    }

                });

                // touch-up
                carousel.on('carousel-touch-up', function(){

                    // threshold?
                    if(carousel.hasClass('ui-touch-threshold')){

                        // remove classes
                        carousel.removeClass('ui-touch-threshold');

                    }

                    // swiping?
                    else if(carousel.hasClass('ui-touch-swiping')){

                        // remove classes
                        carousel.removeClass('ui-touch-swiping');
                        $('body').removeClass('ui-swiping');

                        // position
                        var position = carousel.data('carousel-position');
                        var change = carousel.data('carousel-touch-change');

                        // swipe?
                        if(change >= settings.swipethreshold){
                            var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                            if(change <= slidewidth){
                                change = slidewidth;
                            }
                        }
                        else if(change <= settings.swipethreshold * -1){
                            var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                            if(change >= slidewidth * -1){
                                change = slidewidth * -1;
                            }
                        }

                        // touch gesture
                        carousel.data('carousel-last-touch', true);

                        // update
                        carousel.data('carousel-position', position + change);

                        // contain
                        carousel.trigger('carousel-contain');

                        // transform
                        carousel.trigger('carousel-slide');

                    }

                    // queue next transition
                    if(settings.autoplay){
                        carousel.trigger('carousel-queue');
                    }

                });

                // queue next transition
                carousel.on('carousel-queue', function(){

                    // set timer
                    timer = setTimeout(function(){
                        carousel.trigger('carousel-advance');
                    }, settings.delay);

                });

                // de-queue transitions
                carousel.on('carousel-dequeue', function(){

                    // unset timer
                    clearTimeout(timer);

                });

                // advance
                carousel.on('carousel-advance', function(){

                    // advance one slide
                    var p = carousel.data('carousel-position');
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    p -= slidewidth;
                    carousel.data('carousel-position', p);

                    // contain
                    carousel.trigger('carousel-contain');

                    // slide
                    carousel.trigger('carousel-slide');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                        carousel.trigger('carousel-queue');
                    }

                });

                // retreat
                carousel.on('carousel-retreat', function(){

                    // retreat one slide
                    var p = carousel.data('carousel-position');
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    p += slidewidth;
                    carousel.data('carousel-position', p);

                    // contain
                    carousel.trigger('carousel-contain');

                    // slide
                    carousel.trigger('carousel-slide');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                        carousel.trigger('carousel-queue');
                    }

                });

                // contain
                carousel.on('carousel-contain', function(){

                    // get slide width
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    var slidesinview = Math.round(100 / slidewidth);
                    var slides = carousel.data('carousel-item-count');

                    // contain
                    var p = carousel.data('carousel-position');
                    p = Math.round(p / slidewidth) * slidewidth;
                    if(p > 0){
                        if(settings.loop && !carousel.data('carousel-last-touch')){
                            p = slidewidth * (slides - slidesinview) * -1;
                        }
                        else{
                            p = 0;
                        }
                    }
                    else if(p < slidewidth * (slides - slidesinview) * -1){
                        if(settings.loop && !carousel.data('carousel-last-touch')){
                            p = 0;
                        }
                        else{
                            p = slidewidth * (slides - slidesinview) * -1;
                        }
                    }

                    // disable paging
                    if(!settings.loop && settings.paging && p >= 0){
                        carousel.children('button.previous').prop('disabled', true);
                    }
                    else if(!settings.loop && settings.paging){
                        carousel.children('button.previous[disabled]').prop('disabled', false);
                    }
                    if(!settings.loop && settings.paging && p <= slidewidth * (slides - slidesinview) * -1){
                        carousel.children('button.next').prop('disabled', true);
                    }
                    else if(!settings.loop && settings.paging){
                        carousel.children('button.next[disabled]').prop('disabled', false);
                    }

                    // update
                    carousel.data('carousel-position', p);

                    // update navigation?
                    if(settings.navigation){
                        var i = Math.round(Math.abs(p) / slidewidth);
                        var navlist = carousel.children('ul.ui-carousel-nav');
                        navlist.children().removeClass('ui-active');
                        navlist.children().eq(i).addClass('ui-active');
                    }

                });

                // slide
                carousel.on('carousel-slide', function(){

                    // shake it
                    var p = carousel.data('carousel-position');
                    if(window.optimusPrime){
                        shaker.css({
                            WebkitTransform: 'translateX(' + p + '%)',
                            MozTransform: 'translateX(' + p + '%)',
                            transform: 'translateX(' + p + '%)'
                        });
                    }
                    else{
                        shaker.animate({
                            left: p + '%'
                        }, 300);
                    }

                    // onupdate?
                    if(settings.onupdate){
                        settings.onupdate(p);
                    }

                });

                // destroy
                carousel.on('carousel-destroy', function(){

                    // remove data
                    carousel.removeData('carousel-position');
                    carousel.removeData('carousel-item-count');

                    // remove events
                    carousel.off('carousel-init carousel-advance carousel-retreat carousel-slide');

                    // remove paging
                    carousel.children('button.previous,button.next').remove();

                    // remove classes
                    carousel.removeClass('ui-carousel');
                    shaker.removeClass('ui-carousel-shaker');
                    if(window.optimusPrime){
                        shaker.css({
                            WebkitTransform: 'translateX(0%)',
                            MozTransform: 'translateX(0%)',
                            transform: 'translateX(0%)'
                        });
                    }
                    else{
                        shaker.css('left', '0%');
                    }

                    // cancel events?
                    if($('.ui-carousel').size() == 0){
                        $(window).off('resize');
                        $(document).off('mousedown touchstart mousemove touchmove mouseup touchend touchleave touchcancel');
                        $('body').removeClass('ui-draggables-listen');
                    }

                });

                // init
                carousel.trigger('carousel-init');

            }

        });

        // listen?
        if(!$('body').hasClass('ui-draggables-listen')){

            // add classes
            $('body').addClass('ui-draggables-listen');

            // resize / orientation
            $(window).on('resize orientationchange', function(e){
                $('.ui-carousel').trigger('carousel-slide');
                $('.ui-carousel').trigger('carousel-contain');
            });

            // touch down
            $(document).on('mousedown touchstart', function(e){
                if(e.pageX || e.originalEvent.touches){

                    // dragging carousel?
                    if($(e.target).is('.ui-carousel,.ui-carousel *:not(.slider-handle,.slider-handle *)') && e.which != 3){

                        // touchdown!
                        var carousel = $(e.target).closest('.ui-carousel');
                        $(carousel).trigger('carousel-touch-down', [
                            {
                                x: e.pageX ? e.pageX : e.originalEvent.touches[0].pageX,
                                y: e.pageY ? e.pageY : e.originalEvent.touches[0].pageY
                            }
                        ]);

                        // prevent cancel in android
                        if(navigator.userAgent.match(/Android/i)){
                            //e.preventDefault();
                        }

                    }

                }
            });

            // touch move
            $(document).on('mousemove touchmove', function(e){
                if(e.pageX || e.originalEvent.touches){

                    if($('body').hasClass('ui-swiping')){
                        e.preventDefault();
                    }

                    // update threshold/swiping carousel
                    $('.ui-carousel.ui-touch-threshold,.ui-carousel.ui-touch-swiping').each(function(){
                        $(this).trigger('carousel-touch-move', [
                            {
                                x: e.pageX ? e.pageX : e.originalEvent.touches[0].pageX,
                                y: e.pageY ? e.pageY : e.originalEvent.touches[0].pageY
                            }
                        ]);
                    });

                }
            });

            // touch up
            $(document).on('mouseup touchend touchleave touchcancel', function(e){

                // end threshold/swiping carousel
                $('.ui-carousel.ui-touch-threshold,.ui-carousel.ui-touch-swiping').each(function(){
                    $(this).trigger('carousel-touch-up');
                });

            });

        }

        // done
		return this;

	};
}(jQuery));
<commit_msg>Tabs to spaces<commit_after>/*! carousel.js v1.0 | MIT License | https://github.com/oldrivercreative/carousel */
(function($){
    $.fn.carousel = function(options){

        // settings
        var settings = $.extend({}, {
            paging: false,
            navigation: false,
            loop: false,
            autoplay: false,
            delay: 12000,
            buttons: {
                previous: 'Previous',
                next: 'Next',
                navigation: '%i'
            },
            movethreshold: 10,
            swipethreshold: 10,
            oninit: false,
            onupdate: false,
            destroy: false
        }, options);

        // autoplay timer
        var timer = false;

        // transform?
        window.optimusPrime = false;
        if('WebkitTransform' in document.body.style || 'MozTransform' in document.body.style || 'transform' in document.body.style){
            window.optimusPrime = true;
        }

        // carousel
        this.each(function(){

            // get objects
            var carousel = $(this);
            var shaker = carousel.find('ul:eq(0)');

            // destroy?
            if(settings.destroy){
                carousel.trigger('carousel-destroy');
            }

            // create
            else {

                // init
                carousel.on('carousel-init', function(){

                    // data
                    carousel.data('carousel-position', 0);
                    carousel.data('carousel-touch-change', 0);
                    carousel.data('carousel-last-touch', false);
                    carousel.data('carousel-item-count', shaker.children().size());

                    // add classes
                    carousel.addClass('ui-carousel');
                    shaker.addClass('ui-carousel-shaker');

                    // paging?
                    if(settings.paging){

                        // previous
                        var previous = $('<button class="previous">' + settings.buttons.previous + '</button>');
                        previous.on('click', function(e){
                            e.preventDefault();

                            // not a touch gesture
                            carousel.data('carousel-last-touch', false);

                            // retreat
                            carousel.trigger('carousel-retreat');

                        });
                        carousel.append(previous);

                        // next
                        var next = $('<button class="next">' + settings.buttons.next + '</button>');
                        next.on('click', function(e){
                            e.preventDefault();

                            // not a touch gesture
                            carousel.data('carousel-last-touch', false);

                            // advance
                            carousel.trigger('carousel-advance');

                        });
                        carousel.append(next);

                    }

                    // navigation?
                    if(settings.navigation){

                        // nav list
                        var ul = $('
');
                        for(var i = 0; i < carousel.data('carousel-item-count'); i++){

                            // <button>
                            var navlabel = settings.buttons.navigation.replace('%i', (i+1));
                            var button = $('<button>' + navlabel + '</button>');
                            button.data('carousel-item', i);
                            button.on('click', function(e){
                                e.preventDefault();

                                // set new position
                                var p = $(this).data('carousel-item');
                                var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                                p = p * slidewidth * -1;
                                carousel.data('carousel-position', p);

                                // not a touch gesture
                                carousel.data('carousel-last-touch', false);

                                // contain
                                carousel.trigger('carousel-contain');

                                // slide
                                carousel.trigger('carousel-slide');

                            });

                            //

                            var li = $('
');
                            li.append(button);

                            // active?
                            if(i == 0){
                                li.addClass('ui-active');
                            }

                            // add to nav list
                            ul.append(li);

                        }

                        // add
                        carousel.append(ul);

                    }

                    // contain
                    carousel.trigger('carousel-contain');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-queue');
                    }

                    // oninit?
                    if(typeof(settings.oninit) == 'function'){
                        settings.oninit();
                    }

                });

                // touch-down
                carousel.on('carousel-touch-down', function(e, position){

                    // add classes
                    carousel.addClass('ui-touch-threshold');

                    // starting point
                    carousel.data('carousel-touch-start', {
                        x: position.x,
                        y: $(window).scrollTop()
                    });

                    // disable autoplay while swiping
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                    }

                });

                // touch-move
                carousel.on('carousel-touch-move', function(e, position){

                    // threshold?
                    if(carousel.hasClass('ui-touch-threshold')){

                        // get starting position
                        var start = carousel.data('carousel-touch-start');

                        // scrolling?
                        if(Math.abs($(window).scrollTop() - start.y) >= settings.movethreshold){
                            carousel.removeClass('ui-touch-threshold');
                        }

                        // swiping?
                        else if(Math.abs(position.x - start.x) >= settings.movethreshold){
                            carousel.removeClass('ui-touch-threshold').addClass('ui-touch-swiping');
                            $('body').addClass('ui-swiping');
                        }

                    }

                    // swiping?
                    if(carousel.hasClass('ui-touch-swiping')){

                        // position
                        var start = carousel.data('carousel-touch-start');
                        var distance = position.x - start.x;
                        var position = carousel.data('carousel-position');
                        var change = distance / shaker.width() * 100;
                        carousel.data('carousel-touch-change', change);

                        // shake it
                        var p = position + change;
                        if(window.optimusPrime){
                            shaker.css({
                                WebkitTransform: 'translateX(' + p + '%)',
                                MozTransform: 'translateX(' + p + '%)',
                                transform: 'translateX(' + p + '%)'
                            });
                        }
                        else{
                            shaker.css('left', p + '%');
                        }

                        // onupdate?
                        if(typeof(settings.onupdate) == 'function'){
                            settings.onupdate(p);
                        }

                    }

                });

                // touch-up
                carousel.on('carousel-touch-up', function(){

                    // threshold?
                    if(carousel.hasClass('ui-touch-threshold')){

                        // remove classes
                        carousel.removeClass('ui-touch-threshold');

                    }

                    // swiping?
                    else if(carousel.hasClass('ui-touch-swiping')){

                        // remove classes
                        carousel.removeClass('ui-touch-swiping');
                        $('body').removeClass('ui-swiping');

                        // position
                        var position = carousel.data('carousel-position');
                        var change = carousel.data('carousel-touch-change');

                        // swipe?
                        if(change >= settings.swipethreshold){
                            var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                            if(change <= slidewidth){
                                change = slidewidth;
                            }
                        }
                        else if(change <= settings.swipethreshold * -1){
                            var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                            if(change >= slidewidth * -1){
                                change = slidewidth * -1;
                            }
                        }

                        // touch gesture
                        carousel.data('carousel-last-touch', true);

                        // update
                        carousel.data('carousel-position', position + change);

                        // contain
                        carousel.trigger('carousel-contain');

                        // transform
                        carousel.trigger('carousel-slide');

                    }

                    // queue next transition
                    if(settings.autoplay){
                        carousel.trigger('carousel-queue');
                    }

                });

                // queue next transition
                carousel.on('carousel-queue', function(){

                    // set timer
                    timer = setTimeout(function(){
                        carousel.trigger('carousel-advance');
                    }, settings.delay);

                });

                // de-queue transitions
                carousel.on('carousel-dequeue', function(){

                    // unset timer
                    clearTimeout(timer);

                });

                // advance
                carousel.on('carousel-advance', function(){

                    // advance one slide
                    var p = carousel.data('carousel-position');
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    p -= slidewidth;
                    carousel.data('carousel-position', p);

                    // contain
                    carousel.trigger('carousel-contain');

                    // slide
                    carousel.trigger('carousel-slide');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                        carousel.trigger('carousel-queue');
                    }

                });

                // retreat
                carousel.on('carousel-retreat', function(){

                    // retreat one slide
                    var p = carousel.data('carousel-position');
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    p += slidewidth;
                    carousel.data('carousel-position', p);

                    // contain
                    carousel.trigger('carousel-contain');

                    // slide
                    carousel.trigger('carousel-slide');

                    // autoplay?
                    if(settings.autoplay){
                        carousel.trigger('carousel-dequeue');
                        carousel.trigger('carousel-queue');
                    }

                });

                // contain
                carousel.on('carousel-contain', function(){

                    // get slide width
                    var slidewidth = shaker.children('li:eq(0)').width() / shaker.width() * 100;
                    var slidesinview = Math.round(100 / slidewidth);
                    var slides = carousel.data('carousel-item-count');

                    // contain
                    var p = carousel.data('carousel-position');
                    p = Math.round(p / slidewidth) * slidewidth;
                    if(p > 0){
                        if(settings.loop && !carousel.data('carousel-last-touch')){
                            p = slidewidth * (slides - slidesinview) * -1;
                        }
                        else{
                            p = 0;
                        }
                    }
                    else if(p < slidewidth * (slides - slidesinview) * -1){
                        if(settings.loop && !carousel.data('carousel-last-touch')){
                            p = 0;
                        }
                        else{
                            p = slidewidth * (slides - slidesinview) * -1;
                        }
                    }

                    // disable paging
                    if(!settings.loop && settings.paging && p >= 0){
                        carousel.children('button.previous').prop('disabled', true);
                    }
                    else if(!settings.loop && settings.paging){
                        carousel.children('button.previous[disabled]').prop('disabled', false);
                    }
                    if(!settings.loop && settings.paging && p <= slidewidth * (slides - slidesinview) * -1){
                        carousel.children('button.next').prop('disabled', true);
                    }
                    else if(!settings.loop && settings.paging){
                        carousel.children('button.next[disabled]').prop('disabled', false);
                    }

                    // update
                    carousel.data('carousel-position', p);

                    // update navigation?
                    if(settings.navigation){
                        var i = Math.round(Math.abs(p) / slidewidth);
                        var navlist = carousel.children('ul.ui-carousel-nav');
                        navlist.children().removeClass('ui-active');
                        navlist.children().eq(i).addClass('ui-active');
                    }

                });

                // slide
                carousel.on('carousel-slide', function(){

                    // shake it
                    var p = carousel.data('carousel-position');
                    if(window.optimusPrime){
                        shaker.css({
                            WebkitTransform: 'translateX(' + p + '%)',
                            MozTransform: 'translateX(' + p + '%)',
                            transform: 'translateX(' + p + '%)'
                        });
                    }
                    else{
                        shaker.animate({
                            left: p + '%'
                        }, 300);
                    }

                    // onupdate?
                    if(settings.onupdate){
                        settings.onupdate(p);
                    }

                });

                // destroy
                carousel.on('carousel-destroy', function(){

                    // remove data
                    carousel.removeData('carousel-position');
                    carousel.removeData('carousel-item-count');

                    // remove events
                    carousel.off('carousel-init carousel-advance carousel-retreat carousel-slide');

                    // remove paging
                    carousel.children('button.previous,button.next').remove();

                    // remove classes
                    carousel.removeClass('ui-carousel');
                    shaker.removeClass('ui-carousel-shaker');
                    if(window.optimusPrime){
                        shaker.css({
                            WebkitTransform: 'translateX(0%)',
                            MozTransform: 'translateX(0%)',
                            transform: 'translateX(0%)'
                        });
                    }
                    else{
                        shaker.css('left', '0%');
                    }

                    // cancel events?
                    if($('.ui-carousel').size() == 0){
                        $(window).off('resize');
                        $(document).off('mousedown touchstart mousemove touchmove mouseup touchend touchleave touchcancel');
                        $('body').removeClass('ui-draggables-listen');
                    }

                });

                // init
                carousel.trigger('carousel-init');

            }

        });

        // listen?
        if(!$('body').hasClass('ui-draggables-listen')){

            // add classes
            $('body').addClass('ui-draggables-listen');

            // resize / orientation
            $(window).on('resize orientationchange', function(e){
                $('.ui-carousel').trigger('carousel-slide');
                $('.ui-carousel').trigger('carousel-contain');
            });

            // touch down
            $(document).on('mousedown touchstart', function(e){
                if(e.pageX || e.originalEvent.touches){

                    // dragging carousel?
                    if($(e.target).is('.ui-carousel,.ui-carousel *:not(.slider-handle,.slider-handle *)') && e.which != 3){

                        // touchdown!
                        var carousel = $(e.target).closest('.ui-carousel');
                        $(carousel).trigger('carousel-touch-down', [
                            {
                                x: e.pageX ? e.pageX : e.originalEvent.touches[0].pageX,
                                y: e.pageY ? e.pageY : e.originalEvent.touches[0].pageY
                            }
                        ]);

                        // prevent cancel in android
                        if(navigator.userAgent.match(/Android/i)){
                            //e.preventDefault();
                        }

                    }

                }
            });

            // touch move
            $(document).on('mousemove touchmove', function(e){
                if(e.pageX || e.originalEvent.touches){

                    if($('body').hasClass('ui-swiping')){
                        e.preventDefault();
                    }

                    // update threshold/swiping carousel
                    $('.ui-carousel.ui-touch-threshold,.ui-carousel.ui-touch-swiping').each(function(){
                        $(this).trigger('carousel-touch-move', [
                            {
                                x: e.pageX ? e.pageX : e.originalEvent.touches[0].pageX,
                                y: e.pageY ? e.pageY : e.originalEvent.touches[0].pageY
                            }
                        ]);
                    });

                }
            });

            // touch up
            $(document).on('mouseup touchend touchleave touchcancel', function(e){

                // end threshold/swiping carousel
                $('.ui-carousel.ui-touch-threshold,.ui-carousel.ui-touch-swiping').each(function(){
                    $(this).trigger('carousel-touch-up');
                });

            });

        }

        // done
        return this;

    };
}(jQuery));
<|endoftext|>


<commit_before>// account.js

var org = {

	// added on script load
	config: {
						endpoint: { hzws: 'http://api.spokanelibrary.org/v2/hzws/' }
					 }

	// added on authentication
	,user: {}

	// called on script load
	,init: function() {
		_self = this;

		// setup variables
		this.user = $('#spl-account-summary').data('account');
		//console.log(this.user);

		// init ui
		this.initMyAccount();

	} // init()

, initMyAccount: function() {

		this.initTabs();

		this.initCko();

		this.initHolds();

		this.initLists();

		this.initProfile();

  } // initMyAccount()

, initTabs: function() {
		// apply hash onload
		if ( window.location.hash ) {
			$('a[href="'+window.location.hash+'"]').tab('show')
		}

		// apply hashchange on tab event
		//$('body').on('click', '[data-toggle="tab"]', function(e) {
		$('[data-toggle="tab"]').click(function(e) {
			window.location.hash = $(this).attr('href');
		});

	} // initTabs()

, initCko: function() {
		var $form = $('#spl-form-cko');

		this.toggleCheckboxGroup('.spl-field-cko-select-all'
														,'.spl-field-cko-select-item');

		$form.on('submit', function(e) {
			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();

				var barcodes = new Array;
				$('.spl-field-cko-select-item:checked').each(function() {
					barcodes.push( $(this).data('barcode') );
				});

				if ( barcodes.length > 0 ) {
					_self.ckoRenew(barcodes);
				} else {
					alert('Please select item(s) to renew.');
				}
			}

		});

	} // initCko()

, ckoRenew: function(barcodes) {
		var $form = $('#spl-form-cko');
		var $submit = $('.spl-submit-cko');
		var $hidden = $('#spl-field-cko-renewal');

		$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'renew' //'renew' //'trace'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	barcodes: barcodes
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			$hidden.val(JSON.stringify(obj));
			$form.data('process', 'http').submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

	} // ckoRenew()

, initHolds: function() {
		this.initHoldsReady();
		this.initHoldsPending();

	} // initHolds()

, initHoldsReady: function() {

		var $cancel = $('.spl-field-cancel-hold-ready');

		$cancel.on('click', function(e) {
			console.log( $(this).data(holdkey) );
		});
}

, cancelHold: function(holdKey) {
		var $form = $('#spl-form-holds-pending');

}

, initHoldsPending: function() {

		this.initHoldsPendingSuspend();

		var $form = $('#spl-form-holds-pending');

		this.toggleCheckboxGroup('.spl-field-holds-pending-select-all'
														,'.spl-field-holds-pending-select-item');

		$('.spl-field-holds-pending-control').click(function(e) {
			$form.data('action', $(this).data('action')).submit();
		});

		$form.on('submit', function(e) {
			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();

				var holdkeys = new Array;
				$('.spl-field-holds-pending-select-item:checked').each(function() {
					holdkeys.push( $(this).data('holdkey') );
				});

				if ( holdkeys.length > 0 ) {
					_self.holdsPendingUpdate($(this).data('action'), holdkeys);
					$(this).data('action', '');
				} else {
					alert('Please select hold requests(s).');
				}

			}

		});

	} // initHoldsPending()

, initHoldsPendingSuspend: function() {
		var $suspend = $('.spl-field-holds-pending-suspend');
		var $date = $('.spl-field-holds-pending-date');
		$date.on('change', function(e) {
			if ( $(this).val().length > 0 ) {
				$suspend.attr('disabled', false);
			} else {
				$suspend.attr('disabled', true);
			}
		});
		// disallow dates in the past
		$date.datepicker({startDate: new Date() });

} // initHoldsPendingSuspend()

, holdsPendingUpdate: function(action, holdkeys) {
		var $form = $('#spl-form-holds-pending');
		var $submit = $('.spl-field-holds-pending-control');
		var $hidden = $('#spl-field-holds-pending-update');

		var $location = $('.spl-field-holds-pending-location');
		var $date = $('.spl-field-holds-pending-date');

		$submit.button('loading'); //$submit.button('reset');

		var data = { params: {sessionToken: this.user.sessionToken
	    									,	holdKeys: holdkeys
	    									}
	    					}

		var endpoint;

		switch ( action ) {
			case 'cancel':
				endpoint = 'cancel';
				break;
			case 'pickup':
				endpoint = 'pickup';
				data.params.newLocation = $location.val();
				break;
			case 'suspend':
				endpoint = 'suspend';
				data.params.suspendEndDate = $date.val();
				break;
			case 'resume':
				endpoint = 'resume';
				break;
			default:
				endpoint = null;
				break;
		}

		if ( null != typeof(endpoint) ) {
			$.ajax({
		    url: this.config.endpoint.hzws+endpoint
	    , data: data
		  })
		  .done(function(obj) {
		  	// pass results through
				$hidden.val(JSON.stringify(obj));
				//console.log(obj);
				//$submit.button('reset');
				$form.data('process', 'http').submit();
		  })
		  .fail(function() {
		  })
		  .always(function() {
		  });
		}

	} // holdsPendingUpdate()

, initLists: function() {
		this.initListCreate();
		this.initListRemove();
		this.initListMove();

	} // initLists()

, initListMove: function() {
		var $move = $('.spl-field-list-move-control');

		$move.on('click', function(e) {
			e.preventDefault();
			//$move.button('loading');

			var from =  $(this).data('list');
			if ( from ) {

				var titlekeys = new Array;
				$('.spl-field-list-select-item:checked', '#spl-form-list-control-'+from).each(function() {
					titlekeys.push( $(this).data('titlekey') );
				});

				if ( titlekeys.length > 0 ) {
					//_self.holdsPendingUpdate($(this).data('action'), holdkeys);
					//$(this).data('action', '');
					var $to = $('#spl-field-list-move-to-'+from);
					var to = $to.val();
					_self.moveList(from, to, titlekeys);
				} else {
					alert('Please select list item(s).');
				}
			}

		});
} // initListMove()

, moveList: function(from, to, titleKeys) {

		$form = $('#spl-form-list-control-'+from);
		//$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'move'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	listKeyFrom: from
    									, listKeyTo: to
    									, titleKeys: titleKeys
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			console.log(obj);
			//$submit.button('reset');
			//$form.data('process', 'http').submit();
			//$form.submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} // moveList()

, initListRemove: function() {

		var $remove = $('.spl-field-list-remove-control');

		$remove.on('click', function(e) {
			e.preventDefault();
			$remove.button('loading');

			var list =  $(this).data('list');
			if ( list ) {
				_self.removeList(list);
			}

		});

	} // initListRemove()

, removeList: function(list) {
		//console.log( list );
		$form = $('#spl-form-list-control-'+list);
		//$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'remove'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	listKey: list
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			console.log(obj);
			//$submit.button('reset');
			//$form.data('process', 'http').submit();
			$form.submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} // removeList()

, initListCreate: function() {
		var $form = $('#spl-form-list-create');

		var $label = $('#spl-field-list-create-label');

		$form.on('submit', function(e) {

			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();
				var label = $label.val();
				if ( label.length > 0 ) {
					_self.createList(label);
				} else {
					alert('Please add a List Name');
				}
			}

		});

	} //initListCreate

, createList: function(label) {
		var $form = $('#spl-form-list-create');
		var $submit = $('.spl-submit-list-create');
		var $hidden = $('#spl-field-list-create');

		$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'list'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	description: label
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			//console.log(obj);
			//$submit.button('reset');
			$form.data('process', 'http').submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} //createList()

, initProfile: function() {
		this.initProfileEmail();
		this.initProfilePin();

	} // initProfile()

, initProfileEmail: function() {
		// it turns out hzws has no methods for updating email
		// will need addres ord? or maybe just select on old address?
		var $form = $('#spl-form-profile-email');
		var $email = $('#spl-field-profile-email');
		var $submit = $('#spl-submit-profile-email');

		$form.validate();

		$form.on('submit', function(e) {
			e.preventDefault();
			if ( $form.valid() ) {
				/*
				console.log( _self.user.borrower );
				console.log( _self.user.sessionToken );
				console.log( $email.val() );
				$submit.button('loading');
				*/
			}
		});

	} // initProfileEmail()

, initProfilePin: function() {
	// note: we will need a new session token here (loginUserResetMyPin)
	var $form = $('#spl-form-profile-pin');

	var $submit = $('#spl-submit-profile-pin');

	$form.validate({
		rules: {
			pinConfirm: {
	      equalTo: "#spl-field-profile-pin-new"
	    }
  	}
	});

		$form.on('submit', function(e) {
			e.preventDefault();
			if ( $form.valid() ) {
				/*
				console.log( _self.user.borrower );
				console.log( _self.user.sessionToken );
				console.log( $email.val() );
				$submit.button('loading');
				*/
			}
		});

} // initProfilePin()

, toggleCheckboxGroup: function(all, item) {
		var $selectAll = $(all);
		var $selectItem = $(item);

		$selectAll.on('change', function(e) {
			if ( $(this).is(':checked') ) {
				$selectAll.prop('checked', true);
				$selectItem.prop('checked', true);
			} else {
				$selectAll.prop('checked', false);
				$selectItem.prop('checked', false);
			}
		});
	}

};
<commit_msg>cancel hold<commit_after>// account.js

var org = {

	// added on script load
	config: {
						endpoint: { hzws: 'http://api.spokanelibrary.org/v2/hzws/' }
					 }

	// added on authentication
	,user: {}

	// called on script load
	,init: function() {
		_self = this;

		// setup variables
		this.user = $('#spl-account-summary').data('account');
		//console.log(this.user);

		// init ui
		this.initMyAccount();

	} // init()

, initMyAccount: function() {

		this.initTabs();

		this.initCko();

		this.initHolds();

		this.initLists();

		this.initProfile();

  } // initMyAccount()

, initTabs: function() {
		// apply hash onload
		if ( window.location.hash ) {
			$('a[href="'+window.location.hash+'"]').tab('show')
		}

		// apply hashchange on tab event
		//$('body').on('click', '[data-toggle="tab"]', function(e) {
		$('[data-toggle="tab"]').click(function(e) {
			window.location.hash = $(this).attr('href');
		});

	} // initTabs()

, initCko: function() {
		var $form = $('#spl-form-cko');

		this.toggleCheckboxGroup('.spl-field-cko-select-all'
														,'.spl-field-cko-select-item');

		$form.on('submit', function(e) {
			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();

				var barcodes = new Array;
				$('.spl-field-cko-select-item:checked').each(function() {
					barcodes.push( $(this).data('barcode') );
				});

				if ( barcodes.length > 0 ) {
					_self.ckoRenew(barcodes);
				} else {
					alert('Please select item(s) to renew.');
				}
			}

		});

	} // initCko()

, ckoRenew: function(barcodes) {
		var $form = $('#spl-form-cko');
		var $submit = $('.spl-submit-cko');
		var $hidden = $('#spl-field-cko-renewal');

		$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'renew' //'renew' //'trace'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	barcodes: barcodes
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			$hidden.val(JSON.stringify(obj));
			$form.data('process', 'http').submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

	} // ckoRenew()

, initHolds: function() {
		this.initHoldsReady();
		this.initHoldsPending();

	} // initHolds()

, initHoldsReady: function() {

		var $cancel = $('.spl-field-cancel-hold-ready');

		$cancel.on('click', function(e) {
			console.log( $(this).data('holdkey') );
		});
}

, cancelHold: function(holdKey) {
		var $form = $('#spl-form-holds-pending');

}

, initHoldsPending: function() {

		this.initHoldsPendingSuspend();

		var $form = $('#spl-form-holds-pending');

		this.toggleCheckboxGroup('.spl-field-holds-pending-select-all'
														,'.spl-field-holds-pending-select-item');

		$('.spl-field-holds-pending-control').click(function(e) {
			$form.data('action', $(this).data('action')).submit();
		});

		$form.on('submit', function(e) {
			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();

				var holdkeys = new Array;
				$('.spl-field-holds-pending-select-item:checked').each(function() {
					holdkeys.push( $(this).data('holdkey') );
				});

				if ( holdkeys.length > 0 ) {
					_self.holdsPendingUpdate($(this).data('action'), holdkeys);
					$(this).data('action', '');
				} else {
					alert('Please select hold requests(s).');
				}

			}

		});

	} // initHoldsPending()

, initHoldsPendingSuspend: function() {
		var $suspend = $('.spl-field-holds-pending-suspend');
		var $date = $('.spl-field-holds-pending-date');
		$date.on('change', function(e) {
			if ( $(this).val().length > 0 ) {
				$suspend.attr('disabled', false);
			} else {
				$suspend.attr('disabled', true);
			}
		});
		// disallow dates in the past
		$date.datepicker({startDate: new Date() });

} // initHoldsPendingSuspend()

, holdsPendingUpdate: function(action, holdkeys) {
		var $form = $('#spl-form-holds-pending');
		var $submit = $('.spl-field-holds-pending-control');
		var $hidden = $('#spl-field-holds-pending-update');

		var $location = $('.spl-field-holds-pending-location');
		var $date = $('.spl-field-holds-pending-date');

		$submit.button('loading'); //$submit.button('reset');

		var data = { params: {sessionToken: this.user.sessionToken
	    									,	holdKeys: holdkeys
	    									}
	    					}

		var endpoint;

		switch ( action ) {
			case 'cancel':
				endpoint = 'cancel';
				break;
			case 'pickup':
				endpoint = 'pickup';
				data.params.newLocation = $location.val();
				break;
			case 'suspend':
				endpoint = 'suspend';
				data.params.suspendEndDate = $date.val();
				break;
			case 'resume':
				endpoint = 'resume';
				break;
			default:
				endpoint = null;
				break;
		}

		if ( null != typeof(endpoint) ) {
			$.ajax({
		    url: this.config.endpoint.hzws+endpoint
	    , data: data
		  })
		  .done(function(obj) {
		  	// pass results through
				$hidden.val(JSON.stringify(obj));
				//console.log(obj);
				//$submit.button('reset');
				$form.data('process', 'http').submit();
		  })
		  .fail(function() {
		  })
		  .always(function() {
		  });
		}

	} // holdsPendingUpdate()

, initLists: function() {
		this.initListCreate();
		this.initListRemove();
		this.initListMove();

	} // initLists()

, initListMove: function() {
		var $move = $('.spl-field-list-move-control');

		$move.on('click', function(e) {
			e.preventDefault();
			//$move.button('loading');

			var from =  $(this).data('list');
			if ( from ) {

				var titlekeys = new Array;
				$('.spl-field-list-select-item:checked', '#spl-form-list-control-'+from).each(function() {
					titlekeys.push( $(this).data('titlekey') );
				});

				if ( titlekeys.length > 0 ) {
					//_self.holdsPendingUpdate($(this).data('action'), holdkeys);
					//$(this).data('action', '');
					var $to = $('#spl-field-list-move-to-'+from);
					var to = $to.val();
					_self.moveList(from, to, titlekeys);
				} else {
					alert('Please select list item(s).');
				}
			}

		});
} // initListMove()

, moveList: function(from, to, titleKeys) {

		$form = $('#spl-form-list-control-'+from);
		//$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'move'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	listKeyFrom: from
    									, listKeyTo: to
    									, titleKeys: titleKeys
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			console.log(obj);
			//$submit.button('reset');
			//$form.data('process', 'http').submit();
			//$form.submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} // moveList()

, initListRemove: function() {

		var $remove = $('.spl-field-list-remove-control');

		$remove.on('click', function(e) {
			e.preventDefault();
			$remove.button('loading');

			var list =  $(this).data('list');
			if ( list ) {
				_self.removeList(list);
			}

		});

	} // initListRemove()

, removeList: function(list) {
		//console.log( list );
		$form = $('#spl-form-list-control-'+list);
		//$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'remove'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	listKey: list
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			console.log(obj);
			//$submit.button('reset');
			//$form.data('process', 'http').submit();
			$form.submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} // removeList()

, initListCreate: function() {
		var $form = $('#spl-form-list-create');

		var $label = $('#spl-field-list-create-label');

		$form.on('submit', function(e) {

			if ( 'ajax' == $(this).data('process') ) {
				e.preventDefault();
				var label = $label.val();
				if ( label.length > 0 ) {
					_self.createList(label);
				} else {
					alert('Please add a List Name');
				}
			}

		});

	} //initListCreate

, createList: function(label) {
		var $form = $('#spl-form-list-create');
		var $submit = $('.spl-submit-list-create');
		var $hidden = $('#spl-field-list-create');

		$submit.button('loading'); //$submit.button('reset');
		$.ajax({
	    url: this.config.endpoint.hzws+'list'
    , data: { params: { sessionToken: this.user.sessionToken
    									,	description: label
    									}
    				}
	  })
	  .done(function(obj) {
	  	// pass results through
			//$hidden.val(JSON.stringify(obj));
			//console.log(obj);
			//$submit.button('reset');
			$form.data('process', 'http').submit();
	  })
	  .fail(function() {
	  })
	  .always(function() {
	  });

} //createList()

, initProfile: function() {
		this.initProfileEmail();
		this.initProfilePin();

	} // initProfile()

, initProfileEmail: function() {
		// it turns out hzws has no methods for updating email
		// will need addres ord? or maybe just select on old address?
		var $form = $('#spl-form-profile-email');
		var $email = $('#spl-field-profile-email');
		var $submit = $('#spl-submit-profile-email');

		$form.validate();

		$form.on('submit', function(e) {
			e.preventDefault();
			if ( $form.valid() ) {
				/*
				console.log( _self.user.borrower );
				console.log( _self.user.sessionToken );
				console.log( $email.val() );
				$submit.button('loading');
				*/
			}
		});

	} // initProfileEmail()

, initProfilePin: function() {
	// note: we will need a new session token here (loginUserResetMyPin)
	var $form = $('#spl-form-profile-pin');

	var $submit = $('#spl-submit-profile-pin');

	$form.validate({
		rules: {
			pinConfirm: {
	      equalTo: "#spl-field-profile-pin-new"
	    }
  	}
	});

		$form.on('submit', function(e) {
			e.preventDefault();
			if ( $form.valid() ) {
				/*
				console.log( _self.user.borrower );
				console.log( _self.user.sessionToken );
				console.log( $email.val() );
				$submit.button('loading');
				*/
			}
		});

} // initProfilePin()

, toggleCheckboxGroup: function(all, item) {
		var $selectAll = $(all);
		var $selectItem = $(item);

		$selectAll.on('change', function(e) {
			if ( $(this).is(':checked') ) {
				$selectAll.prop('checked', true);
				$selectItem.prop('checked', true);
			} else {
				$selectAll.prop('checked', false);
				$selectItem.prop('checked', false);
			}
		});
	}

};
<|endoftext|>