From 672e1bd9ed21acf6eefb34cfaef1e7c1569af71d Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sat, 7 Feb 2015 07:40:31 -0800 Subject: [PATCH] cleaned up validation shims/modules --- src/UI/Mixins/AsValidatedView.js | 1 - src/UI/Shims/backbone.validation.js | 7 ++- src/UI/jQuery/RouteBinder.js | 79 ++++++++++++++--------------- src/UI/jQuery/jquery.validation.js | 7 ++- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/UI/Mixins/AsValidatedView.js b/src/UI/Mixins/AsValidatedView.js index 24582ad53..b4658e580 100644 --- a/src/UI/Mixins/AsValidatedView.js +++ b/src/UI/Mixins/AsValidatedView.js @@ -1,6 +1,5 @@ var Validation = require('backbone.validation'); var _ = require('underscore'); -require('../jQuery/jquery.validation'); module.exports = (function(){ 'use strict'; diff --git a/src/UI/Shims/backbone.validation.js b/src/UI/Shims/backbone.validation.js index c77f701bb..b617685b9 100644 --- a/src/UI/Shims/backbone.validation.js +++ b/src/UI/Shims/backbone.validation.js @@ -1,8 +1,7 @@ require('backbone'); -require('../jQuery/jquery.validation'); require('../JsLibraries/backbone.validation'); +var $ = require('jquery'); +var jqueryValidation = require('../jQuery/jquery.validation'); +jqueryValidation.call($); -require('backbone'); -require('../jQuery/jquery.validation'); -require('../JsLibraries/backbone.validation'); module.exports = window.Backbone.Validation; \ No newline at end of file diff --git a/src/UI/jQuery/RouteBinder.js b/src/UI/jQuery/RouteBinder.js index 7a9640564..19c2a7d32 100644 --- a/src/UI/jQuery/RouteBinder.js +++ b/src/UI/jQuery/RouteBinder.js @@ -2,50 +2,49 @@ var Backbone = require('backbone'); var $ = require('jquery'); var StatusModel = require('../System/StatusModel'); -module.exports = (function(){ - var routeBinder = { - bind : function(){ - var self = this; - $(document).on('click', 'a[href]', function(event){ - self._handleClick(event); - }); - }, - _handleClick : function(event){ - var $target = $(event.target); - if($target.parents('.nav-tabs').length) { - return; - } - if($target.hasClass('no-router')) { +var routeBinder = { + bind : function(){ + var self = this; + $(document).on('click', 'a[href]', function(event){ + self._handleClick(event); + }); + }, + _handleClick : function(event){ + var $target = $(event.target); + if($target.parents('.nav-tabs').length) { + return; + } + if($target.hasClass('no-router')) { + return; + } + var href = event.target.getAttribute('href'); + if(!href && $target.closest('a') && $target.closest('a')[0]) { + var linkElement = $target.closest('a')[0]; + if($(linkElement).hasClass('no-router')) { return; } - var href = event.target.getAttribute('href'); - if(!href && $target.closest('a') && $target.closest('a')[0]) { - var linkElement = $target.closest('a')[0]; - if($(linkElement).hasClass('no-router')) { - return; - } - href = linkElement.getAttribute('href'); - } - event.preventDefault(); - if(!href) { - throw 'couldn\'t find route target'; - } - if(!href.startsWith('http')) { - if(event.ctrlKey) { - window.open(href, '_blank'); - } - else { - var relativeHref = href.replace(StatusModel.get('urlBase'), ''); - Backbone.history.navigate(relativeHref, {trigger : true}); - } - } - else if(href.contains('#')) { + href = linkElement.getAttribute('href'); + } + event.preventDefault(); + if(!href) { + throw 'couldn\'t find route target'; + } + if(!href.startsWith('http')) { + if(event.ctrlKey) { window.open(href, '_blank'); } else { - window.open('http://www.dereferer.org/?' + encodeURI(href), '_blank'); + var relativeHref = href.replace(StatusModel.get('urlBase'), ''); + Backbone.history.navigate(relativeHref, {trigger : true}); } } - }; - return routeBinder; -}).call(this); \ No newline at end of file + else if(href.contains('#')) { + window.open(href, '_blank'); + } + else { + window.open('http://www.dereferer.org/?' + encodeURI(href), '_blank'); + } + } +}; + +module.exports = routeBinder; diff --git a/src/UI/jQuery/jquery.validation.js b/src/UI/jQuery/jquery.validation.js index 877666fab..910d8488c 100644 --- a/src/UI/jQuery/jquery.validation.js +++ b/src/UI/jQuery/jquery.validation.js @@ -1,7 +1,6 @@ -var $ = require('jquery'); - -module.exports = (function(){ +module.exports = function(){ 'use strict'; + var $ = this; $.fn.processServerError = function(error){ var validationName = error.propertyName.toLowerCase(); var errorMessage = this.formatErrorMessage(error); @@ -72,4 +71,4 @@ module.exports = (function(){ } return errorMessage; }; -}).call(this); \ No newline at end of file +}; \ No newline at end of file