diff options
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/avatar.js | 11 | ||||
-rw-r--r-- | core/js/jquery.avatar.js | 83 | ||||
-rw-r--r-- | core/js/jquery.ocdialog.js | 16 | ||||
-rw-r--r-- | core/js/js.js | 43 | ||||
-rw-r--r-- | core/js/oc-dialogs.js | 41 | ||||
-rw-r--r-- | core/js/share.js | 6 |
6 files changed, 177 insertions, 23 deletions
diff --git a/core/js/avatar.js b/core/js/avatar.js new file mode 100644 index 00000000000..57e6daa0930 --- /dev/null +++ b/core/js/avatar.js @@ -0,0 +1,11 @@ +$(document).ready(function(){ + if (OC.currentUser) { + $('#header .avatardiv').avatar(OC.currentUser, 32); + // Personal settings + $('#avatar .avatardiv').avatar(OC.currentUser, 128); + } + // User settings + $.each($('td.avatar .avatardiv'), function(i, element) { + $(element).avatar($(element).parent().parent().data('uid'), 32); + }); +}); diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js new file mode 100644 index 00000000000..f1382fd7d2d --- /dev/null +++ b/core/js/jquery.avatar.js @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * This plugin inserts the right avatar for the user, depending on, whether a + * custom avatar is uploaded - which it uses then - or not, and display a + * placeholder with the first letter of the users name instead. + * For this it queries the core_avatar_get route, thus this plugin is fit very + * tightly for owncloud, and it may not work anywhere else. + * + * You may use this on any <div></div> + * Here I'm using <div class="avatardiv"></div> as an example. + * + * There are 4 ways to call this: + * + * 1. $('.avatardiv').avatar('jdoe', 128); + * This will make the div to jdoe's fitting avatar, with a size of 128px. + * + * 2. $('.avatardiv').avatar('jdoe'); + * This will make the div to jdoe's fitting avatar. If the div aready has a + * height, it will be used for the avatars size. Otherwise this plugin will + * search for 'size' DOM data, to use for avatar size. If neither are available + * it will default to 64px. + * + * 3. $('.avatardiv').avatar(); + * This will search the DOM for 'user' data, to use as the username. If there + * is no username available it will default to a placeholder with the value of + * "x". The size will be determined the same way, as the second example. + * + * 4. $('.avatardiv').avatar('jdoe', 128, true); + * This will behave like the first example, except it will also append random + * hashes to the custom avatar images, to force image reloading in IE8. + */ + +(function ($) { + $.fn.avatar = function(user, size, ie8fix) { + if (typeof(size) === 'undefined') { + if (this.height() > 0) { + size = this.height(); + } else if (this.data('size') > 0) { + size = this.data('size'); + } else { + size = 64; + } + } + + this.height(size); + this.width(size); + + if (typeof(user) === 'undefined') { + if (typeof(this.data('user')) !== 'undefined') { + user = this.data('user'); + } else { + this.placeholder('x'); + return; + } + } + + // sanitize + user = user.replace(/\//g,''); + + var $div = this; + + OC.Router.registerLoadedCallback(function() { + var url = OC.Router.generate('core_avatar_get', {user: user, size: size})+'?requesttoken='+oc_requesttoken; + $.get(url, function(result) { + if (typeof(result) === 'object') { + $div.placeholder(user); + } else { + if (ie8fix === true) { + $div.html('<img src="'+url+'#'+Math.floor(Math.random()*1000)+'">'); + } else { + $div.html('<img src="'+url+'">'); + } + } + }); + }); + }; +}(jQuery)); diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js index bafbd0e0e9f..f1836fd4727 100644 --- a/core/js/jquery.ocdialog.js +++ b/core/js/jquery.ocdialog.js @@ -39,7 +39,8 @@ return; } // Escape - if(event.keyCode === 27 && self.options.closeOnEscape) { + if(event.keyCode === 27 && event.type === 'keydown' && self.options.closeOnEscape) { + event.stopImmediatePropagation(); self.close(); return false; } @@ -83,20 +84,21 @@ var self = this; switch(key) { case 'title': - var $title = $('<h3 class="oc-dialog-title">' + this.options.title - + '</h3>'); //<hr class="oc-dialog-separator" />'); if(this.$title) { - this.$title.replaceWith($title); + this.$title.text(value); } else { + var $title = $('<h3 class="oc-dialog-title">' + + value + + '</h3>'); this.$title = $title.prependTo(this.$dialog); } this._setSizes(); break; case 'buttons': - var $buttonrow = $('<div class="oc-dialog-buttonrow" />'); if(this.$buttonrow) { - this.$buttonrow.replaceWith($buttonrow); + this.$buttonrow.empty(); } else { + var $buttonrow = $('<div class="oc-dialog-buttonrow" />'); this.$buttonrow = $buttonrow.appendTo(this.$dialog); } $.each(value, function(idx, val) { @@ -124,6 +126,8 @@ $closeButton.on('click', function() { self.close(); }); + } else { + this.$dialog.find('.oc-dialog-close').remove(); } break; case 'width': diff --git a/core/js/js.js b/core/js/js.js index 1999ff73d23..cb7287c02ae 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -322,6 +322,38 @@ var OC={ return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes(); }, /** + * Parses a URL query string into a JS map + * @param queryString query string in the format param1=1234¶m2=abcde¶m3=xyz + * @return map containing key/values matching the URL parameters + */ + parseQueryString:function(queryString){ + var parts, + components, + result = {}, + key, + value; + if (!queryString){ + return null; + } + if (queryString[0] === '?'){ + queryString = queryString.substr(1); + } + parts = queryString.split('&'); + for (var i = 0; i < parts.length; i++){ + components = parts[i].split('='); + if (!components.length){ + continue; + } + key = decodeURIComponent(components[0]); + if (!key){ + continue; + } + value = components[1]; + result[key] = value && decodeURIComponent(value); + } + return result; + }, + /** * Opens a popup with the setting for an app. * @param appid String. The ID of the app e.g. 'calendar', 'contacts' or 'files'. * @param loadJS boolean or String. If true 'js/settings.js' is loaded. If it's a string @@ -874,7 +906,7 @@ OC.set=function(name, value) { * @param {type} start * @param {type} end */ -$.fn.selectRange = function(start, end) { +jQuery.fn.selectRange = function(start, end) { return this.each(function() { if (this.setSelectionRange) { this.focus(); @@ -890,6 +922,15 @@ $.fn.selectRange = function(start, end) { }; /** + * check if an element exists. + * allows you to write if ($('#myid').exists()) to increase readability + * @link http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery + */ +jQuery.fn.exists = function(){ + return this.length > 0; +} + +/** * Calls the server periodically every 15 mins to ensure that session doesnt * time out */ diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f184a1022bc..8e8a477772b 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -139,8 +139,12 @@ var OCdialogs = { } }); }) - .fail(function() { - alert(t('core', 'Error loading file picker template')); + .fail(function(status, error) { + // If the method is called while navigating away + // from the page, it is probably not needed ;) + if(status !== 0) { + alert(t('core', 'Error loading file picker template: {error}', {error: error})); + } }); }, /** @@ -206,8 +210,14 @@ var OCdialogs = { }); OCdialogs.dialogs_counter++; }) - .fail(function() { - alert(t('core', 'Error loading file picker template')); + .fail(function(status, error) { + // If the method is called while navigating away from + // the page, we still want to deliver the message. + if(status === 0) { + alert(title + ': ' + content); + } else { + alert(t('core', 'Error loading message template: {error}', {error: error})); + } }); }, _getFilePickerTemplate: function() { @@ -219,8 +229,8 @@ var OCdialogs = { self.$listTmpl = self.$filePickerTemplate.find('.filelist li:first-child').detach(); defer.resolve(self.$filePickerTemplate); }) - .fail(function() { - defer.reject(); + .fail(function(jqXHR, textStatus, errorThrown) { + defer.reject(jqXHR.status, errorThrown); }); } else { defer.resolve(this.$filePickerTemplate); @@ -235,8 +245,8 @@ var OCdialogs = { self.$messageTemplate = $(tmpl); defer.resolve(self.$messageTemplate); }) - .fail(function() { - defer.reject(); + .fail(function(jqXHR, textStatus, errorThrown) { + defer.reject(jqXHR.status, errorThrown); }); } else { defer.resolve(this.$messageTemplate); @@ -244,9 +254,16 @@ var OCdialogs = { return defer.promise(); }, _getFileList: function(dir, mimeType) { + if (typeof(mimeType) === "string") { + mimeType = [mimeType]; + } + return $.getJSON( OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, mimetype: mimeType} + { + dir: dir, + mimetypes: JSON.stringify(mimeType) + } ); }, _determineValue: function(element) { @@ -285,11 +302,7 @@ var OCdialogs = { filename: entry.name, date: OC.mtime2date(entry.mtime) }); - if (entry.mimetype === "httpd/unix-directory") { - $li.find('img').attr('src', OC.imagePath('core', 'filetypes/folder.png')); - } else { - $li.find('img').attr('src', OC.Router.generate('core_ajax_preview', {x:32, y:32, file:escapeHTML(dir+'/'+entry.name)}) ); - } + $li.find('img').attr('src', entry.mimetype_icon); self.$filelist.append($li); }); diff --git a/core/js/share.js b/core/js/share.js index 27c16f38b92..5d34faf8a5d 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -233,6 +233,7 @@ OC.Share={ // } else { $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) { if (result.status == 'success' && result.data.length > 0) { + $( "#shareWith" ).autocomplete( "option", "autoFocus", true ); response(result.data); } else { // Suggest sharing via email if valid email address @@ -240,6 +241,7 @@ OC.Share={ // if (pattern.test(search.term)) { // response([{label: t('core', 'Share via email:')+' '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]); // } else { + $( "#shareWith" ).autocomplete( "option", "autoFocus", false ); response([t('core', 'No people found')]); // } } @@ -423,7 +425,7 @@ OC.Share={ dateFormat : 'dd-mm-yy' }); } -} +}; $(document).ready(function() { @@ -512,7 +514,7 @@ $(document).ready(function() { $(document).on('change', '#dropdown .permissions', function() { if ($(this).attr('name') == 'edit') { - var li = $(this).parent().parent() + var li = $(this).parent().parent(); var checkboxes = $('.permissions', li); var checked = $(this).is(':checked'); // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck |