aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rw-r--r--js/lib/ajax.js6
-rw-r--r--js/lib/configuration.js2
-rw-r--r--js/lib/elgglib.js115
-rw-r--r--js/lib/hooks.js10
-rw-r--r--js/lib/pageowner.js8
-rw-r--r--js/lib/security.js18
-rw-r--r--js/lib/ui.autocomplete.js (renamed from js/lib/autocomplete.js)0
-rw-r--r--js/lib/ui.avatar_cropper.js (renamed from js/lib/avatar_cropper.js)6
-rw-r--r--js/lib/ui.friends_picker.js (renamed from js/lib/friends_picker.js)0
-rw-r--r--js/lib/ui.js59
-rw-r--r--js/lib/ui.userpicker.js (renamed from js/lib/userpicker.js)10
-rw-r--r--js/lib/ui.widgets.js12
12 files changed, 120 insertions, 126 deletions
diff --git a/js/lib/ajax.js b/js/lib/ajax.js
index 6f6ae052f..b3f39cc42 100644
--- a/js/lib/ajax.js
+++ b/js/lib/ajax.js
@@ -187,7 +187,11 @@ elgg.action = function(action, options) {
options = elgg.ajax.handleOptions(action, options);
- options.data = elgg.security.addToken(options.data);
+ // This is a misuse of elgg.security.addToken() because it is not always a
+ // full query string with a ?. As such we need a special check for the tokens.
+ if (!elgg.isString(options.data) || options.data.indexOf('__elgg_ts') == -1) {
+ options.data = elgg.security.addToken(options.data);
+ }
options.dataType = 'json';
//Always display system messages after actions
diff --git a/js/lib/configuration.js b/js/lib/configuration.js
index f724a2f01..6e221c957 100644
--- a/js/lib/configuration.js
+++ b/js/lib/configuration.js
@@ -7,4 +7,4 @@ elgg.provide('elgg.config');
*/
elgg.get_site_url = function() {
return elgg.config.wwwroot;
-} \ No newline at end of file
+}; \ No newline at end of file
diff --git a/js/lib/elgglib.js b/js/lib/elgglib.js
index 628adccfc..81209ebd0 100644
--- a/js/lib/elgglib.js
+++ b/js/lib/elgglib.js
@@ -224,8 +224,8 @@ elgg.provide = function(pkg, opt_context) {
* child.foo('boo!'); // alert('boo!');
* </pre>
*
- * @param {Function} childCtor Child class.
- * @param {Function} parentCtor Parent class.
+ * @param {Function} Child Child class constructor.
+ * @param {Function} Parent Parent class constructor.
*/
elgg.inherit = function(Child, Parent) {
Child.prototype = new Parent();
@@ -250,8 +250,35 @@ elgg.normalize_url = function(url) {
url = url || '';
elgg.assertTypeOf('string', url);
- // jslint complains if you use /regexp/ shorthand here... ?!?!
- if ((new RegExp("^(https?:)?//", "i")).test(url)) {
+ validated = (function(url) {
+ url = elgg.parse_url(url);
+ if (url.scheme){
+ url.scheme = url.scheme.toLowerCase();
+ }
+ if (url.scheme == 'http' || url.scheme == 'https') {
+ if (!url.host) {
+ return false;
+ }
+ /* hostname labels may contain only alphanumeric characters, dots and hypens. */
+ if (!(new RegExp("^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$", "i")).test(url.host) || url.host.charAt(-1) == '.') {
+ return false;
+ }
+ }
+ /* some schemas allow the host to be empty */
+ if (!url.scheme || !url.host && url.scheme != 'mailto' && url.scheme != 'news' && url.scheme != 'file') {
+ return false;
+ }
+ return true;
+ })(url);
+
+ // all normal URLs including mailto:
+ if (validated) {
+ return url;
+ }
+
+ // '//example.com' (Shortcut for protocol.)
+ // '?query=test', #target
+ else if ((new RegExp("^(\\#|\\?|//)", "i")).test(url)) {
return url;
}
@@ -383,16 +410,6 @@ elgg.parse_url = function(url, component, expand) {
// fragment
+ '(?:#(.*))?)',
keys = {
- 'mailto': {
- 4: "scheme",
- 5: "user",
- 6: "host",
- 9: "path",
- 12: "query",
- 13: "fragment"
- },
-
- 'standard': {
1: "scheme",
4: "user",
5: "pass",
@@ -401,58 +418,28 @@ elgg.parse_url = function(url, component, expand) {
9: "path",
12: "query",
13: "fragment"
- }
},
- results = {},
- match_keys,
- is_mailto = false;
+ results = {};
- var re = new RegExp(re_str);
- var matches = re.exec(url);
-
- // if the scheme field is undefined it means we're using a protocol
- // without :// and an @. Feel free to fix this in the re if you can >:O
- if (matches[1] == undefined) {
- match_keys = keys['mailto'];
- is_mailto = true;
- } else {
- match_keys = keys['standard'];
+ if (url.indexOf('mailto:') === 0) {
+ results['scheme'] = 'mailto';
+ results['path'] = url.replace('mailto:', '');
+ return results;
}
- for (var i in match_keys) {
- if (matches[i]) {
- results[match_keys[i]] = matches[i];
- }
+ if (url.indexOf('javascript:') === 0) {
+ results['scheme'] = 'javascript';
+ results['path'] = url.replace('javascript:', '');
+ return results;
}
- // merge everything to path if not standard
- if (is_mailto) {
- var path = '',
- new_results = {};
-
- if (typeof(results['user']) != 'undefined' && typeof(results['host']) != 'undefined') {
- path = results['user'] + '@' + results['host'];
- delete results['user'];
- delete results['host'];
- } else if (typeof(results['user'])) {
- path = results['user'];
- delete results['user'];
- } else if (typeof(results['host'])) {
- path = results['host'];
- delete results['host'];
- }
-
- if (typeof(results['path']) != 'undefined') {
- results['path'] = path + results['path'];
- } else {
- results['path'] = path;
- }
+ var re = new RegExp(re_str);
+ var matches = re.exec(url);
- for (var prop in results) {
- new_results[prop] = results[prop];
+ for (var i in keys) {
+ if (matches[i]) {
+ results[keys[i]] = matches[i];
}
-
- results = new_results;
}
if (expand && typeof(results['query']) != 'undefined') {
@@ -467,7 +454,7 @@ elgg.parse_url = function(url, component, expand) {
}
}
return results;
-}
+};
/**
* Returns an object with key/values of the parsed query string.
@@ -535,12 +522,12 @@ elgg.push_to_object_array = function(object, parent, value) {
object[parent] = []
}
- if (object[parent].indexOf(value) < 0) {
+ if ($.inArray(value, object[parent]) < 0) {
return object[parent].push(value);
}
return false;
-}
+};
/**
* Tests if object[parent] contains child
@@ -553,8 +540,8 @@ elgg.is_in_object_array = function(object, parent, value) {
elgg.assertTypeOf('object', object);
elgg.assertTypeOf('string', parent);
- return typeof(object[parent]) != 'undefined' && object[parent].indexOf(value) >= 0;
-}
+ return typeof(object[parent]) != 'undefined' && $.inArray(value, object[parent]) >= 0;
+};
/**
* Triggers the init hook when the library is ready
@@ -569,4 +556,4 @@ elgg.initWhenReady = function() {
elgg.trigger_hook('init', 'system');
elgg.trigger_hook('ready', 'system');
}
-} \ No newline at end of file
+};
diff --git a/js/lib/hooks.js b/js/lib/hooks.js
index edfd28f24..5e1808e22 100644
--- a/js/lib/hooks.js
+++ b/js/lib/hooks.js
@@ -115,7 +115,7 @@ elgg.trigger_hook = function(name, type, params, value) {
return true;
});
- return (tempReturnValue !== null) ? tempReturnValue : returnValue;
+ return (tempReturnValue != null) ? tempReturnValue : returnValue;
};
/**
@@ -136,7 +136,7 @@ elgg.register_instant_hook = function(name, type) {
elgg.assertTypeOf('string', type);
return elgg.push_to_object_array(elgg.config.instant_hooks, name, type);
-}
+};
/**
* Is this hook registered as an instant hook?
@@ -146,7 +146,7 @@ elgg.register_instant_hook = function(name, type) {
*/
elgg.is_instant_hook = function(name, type) {
return elgg.is_in_object_array(elgg.config.instant_hooks, name, type);
-}
+};
/**
* Records that a hook has been triggered.
@@ -156,7 +156,7 @@ elgg.is_instant_hook = function(name, type) {
*/
elgg.set_triggered_hook = function(name, type) {
return elgg.push_to_object_array(elgg.config.triggered_hooks, name, type);
-}
+};
/**
* Has this hook been triggered yet?
@@ -166,7 +166,7 @@ elgg.set_triggered_hook = function(name, type) {
*/
elgg.is_triggered_hook = function(name, type) {
return elgg.is_in_object_array(elgg.config.triggered_hooks, name, type);
-}
+};
elgg.register_instant_hook('init', 'system');
elgg.register_instant_hook('ready', 'system');
diff --git a/js/lib/pageowner.js b/js/lib/pageowner.js
index 825898416..c695c41c3 100644
--- a/js/lib/pageowner.js
+++ b/js/lib/pageowner.js
@@ -6,9 +6,13 @@
*/
/**
- * @return {number} The GUID of the logged in user
+ * @return {number} The GUID of the page owner entity or 0 for no owner
*/
elgg.get_page_owner_guid = function() {
- return elgg.page_owner.guid || 0;
+ if (elgg.page_owner !== undefined) {
+ return elgg.page_owner.guid;
+ } else {
+ return 0;
+ }
};
diff --git a/js/lib/security.js b/js/lib/security.js
index 726c6b767..61aa1cfcd 100644
--- a/js/lib/security.js
+++ b/js/lib/security.js
@@ -60,7 +60,7 @@ elgg.security.refreshToken = function() {
/**
- * Add elgg action tokens to an object, URL, or query string.
+ * Add elgg action tokens to an object, URL, or query string (with a ?).
*
* @param {Object|string} data
* @return {Object} The new data object including action tokens
@@ -75,17 +75,17 @@ elgg.security.addToken = function(data) {
args = {},
base = '';
- if (parts['host'] == data) {
- if (data.indexOf('=') > -1) {
+ if (parts['host'] == undefined) {
+ if (data.indexOf('?') === 0) {
// query string
- args = elgg.parse_str(data);
- } else {
- // relative URL
- base = data + '?';
+ base = '?';
+ args = elgg.parse_str(parts['query']);
}
} else {
- // a URL
- if (typeof parts['query'] != 'undefined') {
+ // full or relative URL
+
+ if (parts['query'] != undefined) {
+ // with query string
args = elgg.parse_str(parts['query']);
}
var split = data.split('?');
diff --git a/js/lib/autocomplete.js b/js/lib/ui.autocomplete.js
index 46d72d146..46d72d146 100644
--- a/js/lib/autocomplete.js
+++ b/js/lib/ui.autocomplete.js
diff --git a/js/lib/avatar_cropper.js b/js/lib/ui.avatar_cropper.js
index df6ba7866..fc32a0832 100644
--- a/js/lib/avatar_cropper.js
+++ b/js/lib/ui.avatar_cropper.js
@@ -32,7 +32,7 @@ elgg.avatarCropper.init = function() {
var selection = ias.getSelection();
elgg.avatarCropper.preview($('#user-avatar-cropper'), selection);
}
-}
+};
/**
* Handler for changing select area.
@@ -57,7 +57,7 @@ elgg.avatarCropper.preview = function(img, selection) {
marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
});
-}
+};
/**
* Handler for updating the form inputs after select ends
@@ -71,6 +71,6 @@ elgg.avatarCropper.selectChange = function(img, selection) {
$('input[name=x2]').val(selection.x2);
$('input[name=y1]').val(selection.y1);
$('input[name=y2]').val(selection.y2);
-}
+};
elgg.register_hook_handler('init', 'system', elgg.avatarCropper.init); \ No newline at end of file
diff --git a/js/lib/friends_picker.js b/js/lib/ui.friends_picker.js
index 9257c40fc..9257c40fc 100644
--- a/js/lib/friends_picker.js
+++ b/js/lib/ui.friends_picker.js
diff --git a/js/lib/ui.js b/js/lib/ui.js
index 6cc1bc78a..c26cbe389 100644
--- a/js/lib/ui.js
+++ b/js/lib/ui.js
@@ -14,18 +14,14 @@ elgg.ui.init = function () {
$('[rel=toggle]').live('click', elgg.ui.toggles);
- $('[rel=popup]').live('click', elgg.ui.popsUp);
+ $('[rel=popup]').live('click', elgg.ui.popupOpen);
$('.elgg-menu-page .elgg-menu-parent').live('click', elgg.ui.toggleMenu);
$('.elgg-requires-confirmation').live('click', elgg.ui.requiresConfirmation);
$('.elgg-autofocus').focus();
-
- if ($('.elgg-input-date').length) {
- elgg.ui.initDatePicker();
- }
-}
+};
/**
* Toggles an element based on clicking a separate element
@@ -43,7 +39,7 @@ elgg.ui.toggles = function(event) {
var target = $(this).toggleClass('elgg-state-active').attr('href');
$(target).slideToggle('medium');
-}
+};
/**
* Pops up an element based on clicking a separate element
@@ -63,7 +59,7 @@ elgg.ui.toggles = function(event) {
* @param {Object} event
* @return void
*/
-elgg.ui.popsUp = function(event) {
+elgg.ui.popupOpen = function(event) {
event.preventDefault();
event.stopPropagation();
@@ -105,7 +101,7 @@ elgg.ui.popsUp = function(event) {
$('body')
.die('click', elgg.ui.popupClose)
.live('click', elgg.ui.popupClose);
-}
+};
/**
* Catches clicks that aren't in a popup and closes all popups.
@@ -143,7 +139,7 @@ elgg.ui.popupClose = function(event) {
$('body').die('click', elgg.ui.popClose);
}
-}
+};
/**
* Toggles a child menu when the parent is clicked
@@ -155,7 +151,7 @@ elgg.ui.toggleMenu = function(event) {
$(this).siblings().slideToggle('medium');
$(this).toggleClass('elgg-menu-closed elgg-menu-opened');
event.preventDefault();
-}
+};
/**
* Initialize the hover menu
@@ -183,7 +179,7 @@ elgg.ui.initHoverMenu = function(parent) {
var $hovermenu = $(this).data('hovermenu') || null;
if (!$hovermenu) {
- var $hovermenu = $(this).parent().find(".elgg-menu-hover");
+ $hovermenu = $(this).parent().find(".elgg-menu-hover");
$(this).data('hovermenu', $hovermenu);
}
@@ -215,7 +211,7 @@ elgg.ui.initHoverMenu = function(parent) {
$(".elgg-menu-hover").fadeOut();
}
});
-}
+};
/**
* Calls a confirm() and prevents default if denied.
@@ -240,7 +236,7 @@ elgg.ui.requiresConfirmation = function(e) {
*
* @return {Object}
*/
-elgg.ui.LoginHandler = function(hook, type, params, options) {
+elgg.ui.loginHandler = function(hook, type, params, options) {
if (params.target.attr('id') == 'login-dropdown-box') {
options.my = 'right top';
options.at = 'right bottom';
@@ -261,22 +257,25 @@ elgg.ui.LoginHandler = function(hook, type, params, options) {
* @return void
*/
elgg.ui.initDatePicker = function() {
- $('.elgg-input-date').datepicker({
- // ISO-8601
- dateFormat: 'yy-mm-dd',
- onSelect: function(dateText) {
- if ($(this).is('.elgg-input-timestamp')) {
- // convert to unix timestamp
- var dateParts = dateText.split("-");
- var timestamp = Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2]);
- timestamp = timestamp / 1000;
-
- var id = $(this).attr('id');
- $('input[name="' + id + '"]').val(timestamp);
+ if ($('.elgg-input-date').length) {
+ $('.elgg-input-date').datepicker({
+ // ISO-8601
+ dateFormat: 'yy-mm-dd',
+ onSelect: function(dateText) {
+ if ($(this).is('.elgg-input-timestamp')) {
+ // convert to unix timestamp
+ var dateParts = dateText.split("-");
+ var timestamp = Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2]);
+ timestamp = timestamp / 1000;
+
+ var id = $(this).attr('id');
+ $('input[name="' + id + '"]').val(timestamp);
+ }
}
- }
- });
-}
+ });
+ }
+};
elgg.register_hook_handler('init', 'system', elgg.ui.init);
-elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.LoginHandler); \ No newline at end of file
+elgg.register_hook_handler('init', 'system', elgg.ui.initDatePicker);
+elgg.register_hook_handler('getOptions', 'ui.popup', elgg.ui.loginHandler); \ No newline at end of file
diff --git a/js/lib/userpicker.js b/js/lib/ui.userpicker.js
index ae2add53f..8287ba91c 100644
--- a/js/lib/userpicker.js
+++ b/js/lib/ui.userpicker.js
@@ -34,7 +34,7 @@ elgg.userpicker.init = function() {
});
$('.elgg-userpicker-remove').live('click', elgg.userpicker.removeUser);
-}
+};
/**
* Adds a user to the select user list
@@ -59,7 +59,7 @@ elgg.userpicker.addUser = function(event, ui) {
$(this).val('');
event.preventDefault();
-}
+};
/**
* Remove a user from the selected user list
@@ -75,7 +75,7 @@ elgg.userpicker.removeUser = function(event) {
item.remove();
event.preventDefault();
-}
+};
/**
* Render the list item for insertion into the selected user list
@@ -96,7 +96,7 @@ elgg.userpicker.viewUser = function(info) {
html += "</div";
return html;
-}
+};
/**
* Get the parameters to use for autocomplete
@@ -112,6 +112,6 @@ elgg.userpicker.getSearchParams = function(obj) {
} else {
return {'match_on[]': 'users', 'term' : obj.term};
}
-}
+};
elgg.register_hook_handler('init', 'system', elgg.userpicker.init); \ No newline at end of file
diff --git a/js/lib/ui.widgets.js b/js/lib/ui.widgets.js
index fb256672a..6435d2147 100644
--- a/js/lib/ui.widgets.js
+++ b/js/lib/ui.widgets.js
@@ -65,7 +65,7 @@ elgg.ui.widgets.add = function(event) {
}
});
event.preventDefault();
-}
+};
/**
* Persist the widget's new position
@@ -96,7 +96,7 @@ elgg.ui.widgets.move = function(event, ui) {
// @hack fixes jquery-ui/opera bug where draggable elements jump
ui.item.css('top', 0);
ui.item.css('left', 0);
-}
+};
/**
* Removes a widget from the layout
@@ -134,7 +134,7 @@ elgg.ui.widgets.remove = function(event) {
}
});
event.preventDefault();
-}
+};
/**
* Toggle the collapse state of the widget
@@ -146,7 +146,7 @@ elgg.ui.widgets.collapseToggle = function(event) {
$(this).toggleClass('elgg-widget-collapsed');
$(this).parent().parent().find('.elgg-body').slideToggle('medium');
event.preventDefault();
-}
+};
/**
* Save a widget's settings
@@ -178,7 +178,7 @@ elgg.ui.widgets.saveSettings = function(event) {
}
});
event.preventDefault();
-}
+};
/**
* Make all elements have the same min-height
@@ -197,6 +197,6 @@ elgg.ui.widgets.equalHeight = function(selector) {
}
})
$(selector).css('min-height', maxHeight);
-}
+};
elgg.register_hook_handler('init', 'system', elgg.ui.widgets.init);