summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/lib/utils')
-rw-r--r--app/assets/javascripts/lib/utils/animate.js49
-rw-r--r--app/assets/javascripts/lib/utils/animate.js.coffee39
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js60
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js.coffee68
-rw-r--r--app/assets/javascripts/lib/utils/datetime_utility.js36
-rw-r--r--app/assets/javascripts/lib/utils/datetime_utility.js.coffee28
-rw-r--r--app/assets/javascripts/lib/utils/notify.js41
-rw-r--r--app/assets/javascripts/lib/utils/notify.js.coffee35
-rw-r--r--app/assets/javascripts/lib/utils/text_utility.js112
-rw-r--r--app/assets/javascripts/lib/utils/text_utility.js.coffee105
-rw-r--r--app/assets/javascripts/lib/utils/type_utility.js15
-rw-r--r--app/assets/javascripts/lib/utils/type_utility.js.coffee9
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js64
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js.coffee52
14 files changed, 377 insertions, 336 deletions
diff --git a/app/assets/javascripts/lib/utils/animate.js b/app/assets/javascripts/lib/utils/animate.js
new file mode 100644
index 00000000000..d36efdabc93
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/animate.js
@@ -0,0 +1,49 @@
+(function() {
+ (function(w) {
+ if (w.gl == null) {
+ w.gl = {};
+ }
+ if (gl.animate == null) {
+ gl.animate = {};
+ }
+ gl.animate.animate = function($el, animation, options, done) {
+ if ((options != null ? options.cssStart : void 0) != null) {
+ $el.css(options.cssStart);
+ }
+ $el.removeClass(animation + ' animated').addClass(animation + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
+ $(this).removeClass(animation + ' animated');
+ if (done != null) {
+ done();
+ }
+ if ((options != null ? options.cssEnd : void 0) != null) {
+ $el.css(options.cssEnd);
+ }
+ });
+ };
+ gl.animate.animateEach = function($els, animation, time, options, done) {
+ var dfd;
+ dfd = $.Deferred();
+ if (!$els.length) {
+ dfd.resolve();
+ }
+ $els.each(function(i) {
+ setTimeout((function(_this) {
+ return function() {
+ var $this;
+ $this = $(_this);
+ return gl.animate.animate($this, animation, options, function() {
+ if (i === $els.length - 1) {
+ dfd.resolve();
+ if (done != null) {
+ return done();
+ }
+ }
+ });
+ };
+ })(this), time * i);
+ });
+ return dfd.promise();
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/animate.js.coffee b/app/assets/javascripts/lib/utils/animate.js.coffee
deleted file mode 100644
index ec3b44d6126..00000000000
--- a/app/assets/javascripts/lib/utils/animate.js.coffee
+++ /dev/null
@@ -1,39 +0,0 @@
-((w) ->
- if not w.gl? then w.gl = {}
- if not gl.animate? then gl.animate = {}
-
- gl.animate.animate = ($el, animation, options, done) ->
- if options?.cssStart?
- $el.css(options.cssStart)
- $el
- .removeClass(animation + ' animated')
- .addClass(animation + ' animated')
- .one 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', ->
- $(this).removeClass(animation + ' animated')
- if done?
- done()
- if options?.cssEnd?
- $el.css(options.cssEnd)
- return
- return
-
- gl.animate.animateEach = ($els, animation, time, options, done) ->
- dfd = $.Deferred()
- if not $els.length
- dfd.resolve()
- $els.each((i) ->
- setTimeout(=>
- $this = $(@)
- gl.animate.animate($this, animation, options, =>
- if i is $els.length - 1
- dfd.resolve()
- if done?
- done()
- )
- ,time * i
- )
- return
- )
- return dfd.promise()
- return
-) window \ No newline at end of file
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
new file mode 100644
index 00000000000..9299d0eabd2
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -0,0 +1,60 @@
+(function() {
+ (function(w) {
+ var base;
+ w.gl || (w.gl = {});
+ (base = w.gl).utils || (base.utils = {});
+ w.gl.utils.isInGroupsPage = function() {
+ return gl.utils.getPagePath() === 'groups';
+ };
+ w.gl.utils.isInProjectPage = function() {
+ return gl.utils.getPagePath() === 'projects';
+ };
+ w.gl.utils.getProjectSlug = function() {
+ if (this.isInProjectPage()) {
+ return $('body').data('project');
+ } else {
+ return null;
+ }
+ };
+ w.gl.utils.getGroupSlug = function() {
+ if (this.isInGroupsPage()) {
+ return $('body').data('group');
+ } else {
+ return null;
+ }
+ };
+ gl.utils.updateTooltipTitle = function($tooltipEl, newTitle) {
+ return $tooltipEl.tooltip('destroy').attr('title', newTitle).tooltip('fixTitle');
+ };
+ gl.utils.preventDisabledButtons = function() {
+ return $('.btn').click(function(e) {
+ if ($(this).hasClass('disabled')) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ return false;
+ }
+ });
+ };
+ gl.utils.getPagePath = function() {
+ return $('body').data('page').split(':')[0];
+ };
+ return jQuery.timefor = function(time, suffix, expiredLabel) {
+ var suffixFromNow, timefor;
+ if (!time) {
+ return '';
+ }
+ suffix || (suffix = 'remaining');
+ expiredLabel || (expiredLabel = 'Past due');
+ jQuery.timeago.settings.allowFuture = true;
+ suffixFromNow = jQuery.timeago.settings.strings.suffixFromNow;
+ jQuery.timeago.settings.strings.suffixFromNow = suffix;
+ timefor = $.timeago(time);
+ if (timefor.indexOf('ago') > -1) {
+ timefor = expiredLabel;
+ }
+ jQuery.timeago.settings.strings.suffixFromNow = suffixFromNow;
+ return timefor;
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/common_utils.js.coffee b/app/assets/javascripts/lib/utils/common_utils.js.coffee
deleted file mode 100644
index d4dd3dc329a..00000000000
--- a/app/assets/javascripts/lib/utils/common_utils.js.coffee
+++ /dev/null
@@ -1,68 +0,0 @@
-((w) ->
-
- w.gl or= {}
- w.gl.utils or= {}
-
- w.gl.utils.isInGroupsPage = ->
-
- return gl.utils.getPagePath() is 'groups'
-
-
- w.gl.utils.isInProjectPage = ->
-
- return gl.utils.getPagePath() is 'projects'
-
-
- w.gl.utils.getProjectSlug = ->
-
- return if @isInProjectPage() then $('body').data 'project' else null
-
-
- w.gl.utils.getGroupSlug = ->
-
- return if @isInGroupsPage() then $('body').data 'group' else null
-
-
-
- gl.utils.updateTooltipTitle = ($tooltipEl, newTitle) ->
-
- $tooltipEl
- .tooltip 'destroy'
- .attr 'title', newTitle
- .tooltip 'fixTitle'
-
-
- gl.utils.preventDisabledButtons = ->
-
- $('.btn').click (e) ->
- if $(this).hasClass 'disabled'
- e.preventDefault()
- e.stopImmediatePropagation()
- return false
-
- gl.utils.getPagePath = ->
- return $('body').data('page').split(':')[0]
-
-
- jQuery.timefor = (time, suffix, expiredLabel) ->
-
- return '' unless time
-
- suffix or= 'remaining'
- expiredLabel or= 'Past due'
-
- jQuery.timeago.settings.allowFuture = yes
-
- { suffixFromNow } = jQuery.timeago.settings.strings
- jQuery.timeago.settings.strings.suffixFromNow = suffix
-
- timefor = $.timeago time
-
- if timefor.indexOf('ago') > -1
- timefor = expiredLabel
-
- jQuery.timeago.settings.strings.suffixFromNow = suffixFromNow
-
- return timefor
-
-) window
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js
new file mode 100644
index 00000000000..e817261f210
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/datetime_utility.js
@@ -0,0 +1,36 @@
+(function() {
+ (function(w) {
+ var base;
+ if (w.gl == null) {
+ w.gl = {};
+ }
+ if ((base = w.gl).utils == null) {
+ base.utils = {};
+ }
+ w.gl.utils.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
+ w.gl.utils.formatDate = function(datetime) {
+ return dateFormat(datetime, 'mmm d, yyyy h:MMtt Z');
+ };
+ w.gl.utils.getDayName = function(date) {
+ return this.days[date.getDay()];
+ };
+ return w.gl.utils.localTimeAgo = function($timeagoEls, setTimeago) {
+ if (setTimeago == null) {
+ setTimeago = true;
+ }
+ $timeagoEls.each(function() {
+ var $el;
+ $el = $(this);
+ return $el.attr('title', gl.utils.formatDate($el.attr('datetime')));
+ });
+ if (setTimeago) {
+ $timeagoEls.timeago();
+ $timeagoEls.tooltip('destroy');
+ return $timeagoEls.tooltip({
+ template: '<div class="tooltip local-timeago" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
+ });
+ }
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js.coffee b/app/assets/javascripts/lib/utils/datetime_utility.js.coffee
deleted file mode 100644
index 2371e913844..00000000000
--- a/app/assets/javascripts/lib/utils/datetime_utility.js.coffee
+++ /dev/null
@@ -1,28 +0,0 @@
-((w) ->
-
- w.gl ?= {}
- w.gl.utils ?= {}
- w.gl.utils.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
-
- w.gl.utils.formatDate = (datetime) ->
- dateFormat(datetime, 'mmm d, yyyy h:MMtt Z')
-
- w.gl.utils.getDayName = (date) ->
- this.days[date.getDay()]
-
- w.gl.utils.localTimeAgo = ($timeagoEls, setTimeago = true) ->
- $timeagoEls.each( ->
- $el = $(@)
- $el.attr('title', gl.utils.formatDate($el.attr('datetime')))
- )
-
- if setTimeago
- $timeagoEls.timeago()
- $timeagoEls.tooltip('destroy')
-
- # Recreate with custom template
- $timeagoEls.tooltip(
- template: '<div class="tooltip local-timeago" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
- )
-
-) window
diff --git a/app/assets/javascripts/lib/utils/notify.js b/app/assets/javascripts/lib/utils/notify.js
new file mode 100644
index 00000000000..42b6ac0589e
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/notify.js
@@ -0,0 +1,41 @@
+(function() {
+ (function(w) {
+ var notificationGranted, notifyMe, notifyPermissions;
+ notificationGranted = function(message, opts, onclick) {
+ var notification;
+ notification = new Notification(message, opts);
+ setTimeout(function() {
+ return notification.close();
+ }, 8000);
+ if (onclick) {
+ return notification.onclick = onclick;
+ }
+ };
+ notifyPermissions = function() {
+ if ('Notification' in window) {
+ return Notification.requestPermission();
+ }
+ };
+ notifyMe = function(message, body, icon, onclick) {
+ var opts;
+ opts = {
+ body: body,
+ icon: icon
+ };
+ if (!('Notification' in window)) {
+
+ } else if (Notification.permission === 'granted') {
+ return notificationGranted(message, opts, onclick);
+ } else if (Notification.permission !== 'denied') {
+ return Notification.requestPermission(function(permission) {
+ if (permission === 'granted') {
+ return notificationGranted(message, opts, onclick);
+ }
+ });
+ }
+ };
+ w.notify = notifyMe;
+ return w.notifyPermissions = notifyPermissions;
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/notify.js.coffee b/app/assets/javascripts/lib/utils/notify.js.coffee
deleted file mode 100644
index 9e28353ac34..00000000000
--- a/app/assets/javascripts/lib/utils/notify.js.coffee
+++ /dev/null
@@ -1,35 +0,0 @@
-((w) ->
- notificationGranted = (message, opts, onclick) ->
- notification = new Notification(message, opts)
-
- # Hide the notification after X amount of seconds
- setTimeout ->
- notification.close()
- , 8000
-
- if onclick
- notification.onclick = onclick
-
- notifyPermissions = ->
- if 'Notification' of window
- Notification.requestPermission()
-
- notifyMe = (message, body, icon, onclick) ->
- opts =
- body: body
- icon: icon
- # Let's check if the browser supports notifications
- if !('Notification' of window)
- # do nothing
- else if Notification.permission == 'granted'
- # If it's okay let's create a notification
- notificationGranted message, opts, onclick
- else if Notification.permission != 'denied'
- Notification.requestPermission (permission) ->
- # If the user accepts, let's create a notification
- if permission == 'granted'
- notificationGranted message, opts, onclick
-
- w.notify = notifyMe
- w.notifyPermissions = notifyPermissions
-) window
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js
new file mode 100644
index 00000000000..130479642f3
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/text_utility.js
@@ -0,0 +1,112 @@
+(function() {
+ (function(w) {
+ var base;
+ if (w.gl == null) {
+ w.gl = {};
+ }
+ if ((base = w.gl).text == null) {
+ base.text = {};
+ }
+ gl.text.randomString = function() {
+ return Math.random().toString(36).substring(7);
+ };
+ gl.text.replaceRange = function(s, start, end, substitute) {
+ return s.substring(0, start) + substitute + s.substring(end);
+ };
+ gl.text.selectedText = function(text, textarea) {
+ return text.substring(textarea.selectionStart, textarea.selectionEnd);
+ };
+ gl.text.lineBefore = function(text, textarea) {
+ var split;
+ split = text.substring(0, textarea.selectionStart).trim().split('\n');
+ return split[split.length - 1];
+ };
+ gl.text.lineAfter = function(text, textarea) {
+ return text.substring(textarea.selectionEnd).trim().split('\n')[0];
+ };
+ gl.text.blockTagText = function(text, textArea, blockTag, selected) {
+ var lineAfter, lineBefore;
+ lineBefore = this.lineBefore(text, textArea);
+ lineAfter = this.lineAfter(text, textArea);
+ if (lineBefore === blockTag && lineAfter === blockTag) {
+ if (blockTag != null) {
+ textArea.selectionStart = textArea.selectionStart - (blockTag.length + 1);
+ textArea.selectionEnd = textArea.selectionEnd + (blockTag.length + 1);
+ }
+ return selected;
+ } else {
+ return blockTag + "\n" + selected + "\n" + blockTag;
+ }
+ };
+ gl.text.insertText = function(textArea, text, tag, blockTag, selected, wrap) {
+ var insertText, inserted, selectedSplit, startChar;
+ selectedSplit = selected.split('\n');
+ startChar = !wrap && textArea.selectionStart > 0 ? '\n' : '';
+ if (selectedSplit.length > 1 && (!wrap || (blockTag != null))) {
+ if (blockTag != null) {
+ insertText = this.blockTagText(text, textArea, blockTag, selected);
+ } else {
+ insertText = selectedSplit.map(function(val) {
+ if (val.indexOf(tag) === 0) {
+ return "" + (val.replace(tag, ''));
+ } else {
+ return "" + tag + val;
+ }
+ }).join('\n');
+ }
+ } else {
+ insertText = "" + startChar + tag + selected + (wrap ? tag : ' ');
+ }
+ if (document.queryCommandSupported('insertText')) {
+ inserted = document.execCommand('insertText', false, insertText);
+ }
+ if (!inserted) {
+ try {
+ document.execCommand("ms-beginUndoUnit");
+ } catch (undefined) {}
+ textArea.value = this.replaceRange(text, textArea.selectionStart, textArea.selectionEnd, insertText);
+ try {
+ document.execCommand("ms-endUndoUnit");
+ } catch (undefined) {}
+ }
+ return this.moveCursor(textArea, tag, wrap);
+ };
+ gl.text.moveCursor = function(textArea, tag, wrapped) {
+ var pos;
+ if (!textArea.setSelectionRange) {
+ return;
+ }
+ if (textArea.selectionStart === textArea.selectionEnd) {
+ if (wrapped) {
+ pos = textArea.selectionStart - tag.length;
+ } else {
+ pos = textArea.selectionStart;
+ }
+ return textArea.setSelectionRange(pos, pos);
+ }
+ };
+ gl.text.updateText = function(textArea, tag, blockTag, wrap) {
+ var $textArea, oldVal, selected, text;
+ $textArea = $(textArea);
+ oldVal = $textArea.val();
+ textArea = $textArea.get(0);
+ text = $textArea.val();
+ selected = this.selectedText(text, textArea);
+ $textArea.focus();
+ return this.insertText(textArea, text, tag, blockTag, selected, wrap);
+ };
+ gl.text.init = function(form) {
+ var self;
+ self = this;
+ return $('.js-md', form).off('click').on('click', function() {
+ var $this;
+ $this = $(this);
+ return self.updateText($this.closest('.md-area').find('textarea'), $this.data('md-tag'), $this.data('md-block'), !$this.data('md-prepend'));
+ });
+ };
+ return gl.text.removeListeners = function(form) {
+ return $('.js-md', form).off();
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/text_utility.js.coffee b/app/assets/javascripts/lib/utils/text_utility.js.coffee
deleted file mode 100644
index 2e1407f8738..00000000000
--- a/app/assets/javascripts/lib/utils/text_utility.js.coffee
+++ /dev/null
@@ -1,105 +0,0 @@
-((w) ->
- w.gl ?= {}
- w.gl.text ?= {}
-
- gl.text.randomString = -> Math.random().toString(36).substring(7)
-
- gl.text.replaceRange = (s, start, end, substitute) ->
- s.substring(0, start) + substitute + s.substring(end);
-
- gl.text.selectedText = (text, textarea) ->
- text.substring(textarea.selectionStart, textarea.selectionEnd)
-
- gl.text.lineBefore = (text, textarea) ->
- split = text.substring(0, textarea.selectionStart).trim().split('\n')
- split[split.length - 1]
-
- gl.text.lineAfter = (text, textarea) ->
- text.substring(textarea.selectionEnd).trim().split('\n')[0]
-
- gl.text.blockTagText = (text, textArea, blockTag, selected) ->
- lineBefore = @lineBefore(text, textArea)
- lineAfter = @lineAfter(text, textArea)
-
- if lineBefore is blockTag and lineAfter is blockTag
- # To remove the block tag we have to select the line before & after
- if blockTag?
- textArea.selectionStart = textArea.selectionStart - (blockTag.length + 1)
- textArea.selectionEnd = textArea.selectionEnd + (blockTag.length + 1)
-
- selected
- else
- "#{blockTag}\n#{selected}\n#{blockTag}"
-
- gl.text.insertText = (textArea, text, tag, blockTag, selected, wrap) ->
- selectedSplit = selected.split('\n')
- startChar = if not wrap and textArea.selectionStart > 0 then '\n' else ''
-
- if selectedSplit.length > 1 and (not wrap or blockTag?)
- if blockTag?
- insertText = @blockTagText(text, textArea, blockTag, selected)
- else
- insertText = selectedSplit.map((val) ->
- if val.indexOf(tag) is 0
- "#{val.replace(tag, '')}"
- else
- "#{tag}#{val}"
- ).join('\n')
- else
- insertText = "#{startChar}#{tag}#{selected}#{if wrap then tag else ' '}"
-
- if document.queryCommandSupported('insertText')
- inserted = document.execCommand 'insertText', false, insertText
-
- unless inserted
- try
- document.execCommand("ms-beginUndoUnit")
-
- textArea.value = @replaceRange(
- text,
- textArea.selectionStart,
- textArea.selectionEnd,
- insertText)
- try
- document.execCommand("ms-endUndoUnit")
-
- @moveCursor(textArea, tag, wrap)
-
- gl.text.moveCursor = (textArea, tag, wrapped) ->
- return unless textArea.setSelectionRange
-
- if textArea.selectionStart is textArea.selectionEnd
- if wrapped
- pos = textArea.selectionStart - tag.length
- else
- pos = textArea.selectionStart
-
- textArea.setSelectionRange pos, pos
-
- gl.text.updateText = (textArea, tag, blockTag, wrap) ->
- $textArea = $(textArea)
- oldVal = $textArea.val()
- textArea = $textArea.get(0)
- text = $textArea.val()
- selected = @selectedText(text, textArea)
- $textArea.focus()
-
- @insertText(textArea, text, tag, blockTag, selected, wrap)
-
- gl.text.init = (form) ->
- self = @
- $('.js-md', form)
- .off 'click'
- .on 'click', ->
- $this = $(@)
- self.updateText(
- $this.closest('.md-area').find('textarea'),
- $this.data('md-tag'),
- $this.data('md-block'),
- not $this.data('md-prepend')
- )
-
- gl.text.removeListeners = (form) ->
- $('.js-md', form).off()
-
-) window
diff --git a/app/assets/javascripts/lib/utils/type_utility.js b/app/assets/javascripts/lib/utils/type_utility.js
new file mode 100644
index 00000000000..dc30babd645
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/type_utility.js
@@ -0,0 +1,15 @@
+(function() {
+ (function(w) {
+ var base;
+ if (w.gl == null) {
+ w.gl = {};
+ }
+ if ((base = w.gl).utils == null) {
+ base.utils = {};
+ }
+ return w.gl.utils.isObject = function(obj) {
+ return (obj != null) && (obj.constructor === Object);
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/type_utility.js.coffee b/app/assets/javascripts/lib/utils/type_utility.js.coffee
deleted file mode 100644
index 957f0d86b36..00000000000
--- a/app/assets/javascripts/lib/utils/type_utility.js.coffee
+++ /dev/null
@@ -1,9 +0,0 @@
-((w) ->
-
- w.gl ?= {}
- w.gl.utils ?= {}
-
- w.gl.utils.isObject = (obj) ->
- obj? and (obj.constructor is Object)
-
-) window
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
new file mode 100644
index 00000000000..fffbfd19745
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -0,0 +1,64 @@
+(function() {
+ (function(w) {
+ var base;
+ if (w.gl == null) {
+ w.gl = {};
+ }
+ if ((base = w.gl).utils == null) {
+ base.utils = {};
+ }
+ w.gl.utils.getParameterValues = function(sParam) {
+ var i, sPageURL, sParameterName, sURLVariables, values;
+ sPageURL = decodeURIComponent(window.location.search.substring(1));
+ sURLVariables = sPageURL.split('&');
+ sParameterName = void 0;
+ values = [];
+ i = 0;
+ while (i < sURLVariables.length) {
+ sParameterName = sURLVariables[i].split('=');
+ if (sParameterName[0] === sParam) {
+ values.push(sParameterName[1]);
+ }
+ i++;
+ }
+ return values;
+ };
+ w.gl.utils.mergeUrlParams = function(params, url) {
+ var lastChar, newUrl, paramName, paramValue, pattern;
+ newUrl = decodeURIComponent(url);
+ for (paramName in params) {
+ paramValue = params[paramName];
+ pattern = new RegExp("\\b(" + paramName + "=).*?(&|$)");
+ if (paramValue == null) {
+ newUrl = newUrl.replace(pattern, '');
+ } else if (url.search(pattern) !== -1) {
+ newUrl = newUrl.replace(pattern, "$1" + paramValue + "$2");
+ } else {
+ newUrl = "" + newUrl + (newUrl.indexOf('?') > 0 ? '&' : '?') + paramName + "=" + paramValue;
+ }
+ }
+ lastChar = newUrl[newUrl.length - 1];
+ if (lastChar === '&') {
+ newUrl = newUrl.slice(0, -1);
+ }
+ return newUrl;
+ };
+ return w.gl.utils.removeParamQueryString = function(url, param) {
+ var urlVariables, variables;
+ url = decodeURIComponent(url);
+ urlVariables = url.split('&');
+ return ((function() {
+ var j, len, results;
+ results = [];
+ for (j = 0, len = urlVariables.length; j < len; j++) {
+ variables = urlVariables[j];
+ if (variables.indexOf(param) === -1) {
+ results.push(variables);
+ }
+ }
+ return results;
+ })()).join('&');
+ };
+ })(window);
+
+}).call(this);
diff --git a/app/assets/javascripts/lib/utils/url_utility.js.coffee b/app/assets/javascripts/lib/utils/url_utility.js.coffee
deleted file mode 100644
index e8085e1c2e4..00000000000
--- a/app/assets/javascripts/lib/utils/url_utility.js.coffee
+++ /dev/null
@@ -1,52 +0,0 @@
-((w) ->
-
- w.gl ?= {}
- w.gl.utils ?= {}
-
- # Returns an array containing the value(s) of the
- # of the key passed as an argument
- w.gl.utils.getParameterValues = (sParam) ->
- sPageURL = decodeURIComponent(window.location.search.substring(1))
- sURLVariables = sPageURL.split('&')
- sParameterName = undefined
- values = []
- i = 0
- while i < sURLVariables.length
- sParameterName = sURLVariables[i].split('=')
- if sParameterName[0] is sParam
- values.push(sParameterName[1])
- i++
- values
-
- # #
- # @param {Object} params - url keys and value to merge
- # @param {String} url
- # #
- w.gl.utils.mergeUrlParams = (params, url) ->
- newUrl = decodeURIComponent(url)
- for paramName, paramValue of params
- pattern = new RegExp "\\b(#{paramName}=).*?(&|$)"
- if not paramValue?
- newUrl = newUrl.replace pattern, ''
- else if url.search(pattern) isnt -1
- newUrl = newUrl.replace pattern, "$1#{paramValue}$2"
- else
- newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}"
-
- # Remove a trailing ampersand
- lastChar = newUrl[newUrl.length - 1]
-
- if lastChar is '&'
- newUrl = newUrl.slice 0, -1
-
- newUrl
-
- # removes parameter query string from url. returns the modified url
- w.gl.utils.removeParamQueryString = (url, param) ->
- url = decodeURIComponent(url)
- urlVariables = url.split('&')
- (
- variables for variables in urlVariables when variables.indexOf(param) is -1
- ).join('&')
-
-) window