aboutsummaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-24 19:27:33 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-24 19:27:33 +0200
commit66813e9df6eb96a960462a3dc8dbe1de4df5314c (patch)
tree69985a6adc77d66a5289e321172231f89849a4ec /core/js
parent54e0f1d739b4b3820cafafca039a3524d3dd28ba (diff)
parent3917d18980638e86f5cce9242adeded0ca760260 (diff)
downloadnextcloud-server-66813e9df6eb96a960462a3dc8dbe1de4df5314c.tar.gz
nextcloud-server-66813e9df6eb96a960462a3dc8dbe1de4df5314c.zip
Merge branch 'master' into fix-language-detection
Diffstat (limited to 'core/js')
-rw-r--r--core/js/jquery.avatar.js6
-rw-r--r--core/js/jquery.placeholder.js216
-rw-r--r--core/js/js.js2
-rw-r--r--core/js/octemplate.js2
-rw-r--r--core/js/placeholder.js6
-rw-r--r--core/js/share.js57
6 files changed, 245 insertions, 44 deletions
diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js
index 00068101726..dbab032b971 100644
--- a/core/js/jquery.avatar.js
+++ b/core/js/jquery.avatar.js
@@ -60,7 +60,7 @@
if (typeof(this.data('user')) !== 'undefined') {
user = this.data('user');
} else {
- this.placeholder('x');
+ this.imageplaceholder('x');
return;
}
}
@@ -76,9 +76,9 @@
if (typeof(result) === 'object') {
if (!hidedefault) {
if (result.data && result.data.displayname) {
- $div.placeholder(user, result.data.displayname);
+ $div.imageplaceholder(user, result.data.displayname);
} else {
- $div.placeholder(user);
+ $div.imageplaceholder(user);
}
} else {
$div.hide();
diff --git a/core/js/jquery.placeholder.js b/core/js/jquery.placeholder.js
new file mode 100644
index 00000000000..689462582b3
--- /dev/null
+++ b/core/js/jquery.placeholder.js
@@ -0,0 +1,216 @@
+/*
+ jQuery placeholder plugin
+ by Andrey Kuzmin, @unsoundscapes
+
+ Based on existing plugin http://mths.be/placeholder by @mathias
+ and this demo http://robertnyman.com/2011/05/02/ by @robertnyman
+
+ Adopted to toggle placeholder on user input instead of focus
+
+ Released under the MIT license
+*/
+
+(function (factory) {
+ 'use strict';
+
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as anonymous module.
+ define(['jquery'], factory)
+ } else {
+ // Browser globals.
+ factory(jQuery)
+ }
+}(function ($) {
+ 'use strict';
+
+ var isInputSupported = 'placeholder' in document.createElement('input')
+ , isTextareaSupported = 'placeholder' in document.createElement('textarea')
+ , $placeholders = $()
+
+ function getAttributes (element) {
+ // Return an object of element attributes
+ var newAttrs = {}
+ , rinlinejQuery = /^jQuery\d+$/
+
+ $.each(element.attributes, function () {
+ if (this.specified && !rinlinejQuery.test(this.name)) {
+ newAttrs[this.name] = this.value
+ }
+ })
+ return newAttrs
+ }
+
+ function setCaretTo (element, index) {
+ // Set caret to specified @index
+ if (element.createTextRange) {
+ var range = element.createTextRange()
+ range.move('character', index)
+ range.select()
+ } else if (element.selectionStart !== null) {
+ element.focus()
+ element.setSelectionRange(index, index)
+ }
+ }
+
+
+ function Placeholder (element, options) {
+ this.options = options || {}
+ this.$replacement = this.$element = $(element)
+ this.initialize.apply(this, arguments)
+ // Cache all elements with placeholders
+ $placeholders = $placeholders.add(element)
+ }
+
+ Placeholder.prototype = {
+
+ initialize: function () {
+ this.isHidden = true
+ this.placeholderAttr = this.$element.attr('placeholder')
+ // do not mess with default behavior
+ this.$element.removeAttr('placeholder')
+ this.isPassword = this.$element.is('[type=password]')
+ if (this.isPassword) this.makeReplacement()
+ this.$replacement.on({
+ 'keydown.placeholder': $.proxy(this.hide, this)
+ , 'focus.placeholder drop.placeholder click.placeholder': $.proxy(this.setCaret, this)
+ })
+ this.$element.on({
+ 'blur.placeholder keyup.placeholder': $.proxy(this.show, this)
+ })
+ this.show()
+ }
+
+ // Set or get input value
+ // Setting value toggles placeholder
+ , val: function (value) {
+ if (value === undefined) {
+ return this.isHidden ? this.$element[0].value : '';
+ }
+ if (value === '') {
+ if (this.isHidden) {
+ this.$element[0].value = value
+ this.show()
+ }
+ } else {
+ if (!this.isHidden) this.hide()
+ this.$element[0].value = value
+ }
+ return this
+ }
+
+ // Hide placeholder at user input
+ , hide: function (e) {
+ var isActiveElement = this.$replacement.is(':focus')
+ if (this.isHidden) return;
+ if (!e || !(e.shiftKey && e.keyCode === 16) && e.keyCode !== 9) {
+ this.isHidden = true
+ if (this.isPassword) {
+ this.$replacement.before(this.$element.show()).hide()
+ if (isActiveElement) this.$element.focus()
+ } else {
+ this.$element[0].value = ''
+ this.$element.removeClass(this.options.className)
+ }
+ }
+ }
+
+ // Show placeholder on blur and keyup
+ , show: function (e) {
+ var isActiveElement = this.$element.is(':focus')
+ if (!this.isHidden) return;
+ if (this.$element[0].value === '') {
+ this.isHidden = false
+ if (this.isPassword) {
+ this.$element.before(this.$replacement.show()).hide()
+ if (isActiveElement) this.$replacement.focus()
+ } else {
+ this.$element[0].value = this.placeholderAttr
+ this.$element.addClass(this.options.className)
+ if (isActiveElement) this.setCaret(e)
+ }
+ }
+ }
+
+ // Set caret at the beginning of the input
+ , setCaret: function (e) {
+ if (e && !this.isHidden) {
+ setCaretTo(this.$replacement[0], 0)
+ e.preventDefault()
+ }
+ }
+
+ // Make and return replacement element
+ , makeReplacement: function () {
+ // we can't use $.fn.clone because ie <= 8 doesn't allow type change
+ var replacementAttributes =
+ $.extend(
+ getAttributes(this.$element[0])
+ , { 'type': 'text'
+ , 'value': this.placeholderAttr
+ }
+ )
+
+ // replacement should not have input name
+ delete replacementAttributes.name
+
+ this.$replacement = $('<input>', replacementAttributes)
+ .data('placeholder', this)
+ .addClass(this.options.className)
+
+ return this.$replacement;
+ }
+
+ }
+
+
+ // Override jQuery val and prop hooks
+ $.valHooks.input = $.valHooks.textarea = $.propHooks.value = {
+ get: function (element) {
+ var placeholder = $(element).data('placeholder')
+ return placeholder ? placeholder.val() : element.value;
+ }
+ , set: function (element, value) {
+ var placeholder = $(element).data('placeholder')
+ return placeholder ? placeholder.val(value) : element.value = value;
+ }
+ }
+
+
+ // Plugin definition
+ $.fn.placeholder = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('placeholder')
+ , options = $.extend({}, $.fn.placeholder.defaults, typeof option === 'object' && option)
+
+ if (!data && $this.is('[placeholder]') && (options.force ||
+ !isInputSupported && $this.is('input') ||
+ !isTextareaSupported && $this.is('textarea'))) {
+ $this.data('placeholder', data = new Placeholder(this, options))
+ }
+
+ if (data && typeof option === 'string') data[option]()
+ })
+ }
+ $.fn.placeholder.defaults = {
+ force: false
+ , className: 'placeholder'
+ }
+ $.fn.placeholder.Constructor = Placeholder
+
+
+ // Events
+ $(document).on('submit.placeholder', 'form', function () {
+ // Clear the placeholder values so they don't get submitted
+ $placeholders.placeholder('hide')
+ // And then restore them back
+ setTimeout(function () { $placeholders.placeholder('show') }, 10)
+ })
+ $(window).on('beforeunload.placeholder', function () {
+ // Clear placeholders upon page reload
+ $placeholders.placeholder('hide')
+ })
+
+ return Placeholder
+
+}));
diff --git a/core/js/js.js b/core/js/js.js
index c17e3fa2959..f5991cfc9dd 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -933,7 +933,7 @@ jQuery.fn.selectRange = function(start, end) {
*/
jQuery.fn.exists = function(){
return this.length > 0;
-}
+};
/**
* Calls the server periodically every 15 mins to ensure that session doesnt
diff --git a/core/js/octemplate.js b/core/js/octemplate.js
index 46ffa976574..aab705059d2 100644
--- a/core/js/octemplate.js
+++ b/core/js/octemplate.js
@@ -82,7 +82,7 @@
}
);
} catch(e) {
- console.error(e, 'data:', data)
+ console.error(e, 'data:', data);
}
},
options: {
diff --git a/core/js/placeholder.js b/core/js/placeholder.js
index ee2a8ce84c4..47cff780d2f 100644
--- a/core/js/placeholder.js
+++ b/core/js/placeholder.js
@@ -30,7 +30,7 @@
*
* And call this from Javascript:
*
- * $('#albumart').placeholder('The Album Title');
+ * $('#albumart').imageplaceholder('The Album Title');
*
* Which will result in:
*
@@ -38,7 +38,7 @@
*
* You may also call it like this, to have a different background, than the seed:
*
- * $('#albumart').placeholder('The Album Title', 'Album Title');
+ * $('#albumart').imageplaceholder('The Album Title', 'Album Title');
*
* Resulting in:
*
@@ -47,7 +47,7 @@
*/
(function ($) {
- $.fn.placeholder = function(seed, text) {
+ $.fn.imageplaceholder = function(seed, text) {
// set optional argument "text" to value of "seed" if undefined
text = text || seed;
diff --git a/core/js/share.js b/core/js/share.js
index 281cccaaef8..ff557652b67 100644
--- a/core/js/share.js
+++ b/core/js/share.js
@@ -200,13 +200,13 @@ OC.Share={
}
});
- html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />';
+ html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with user or group …')+'" />';
html += '<ul id="shareWithList">';
html += '</ul>';
var linksAllowed = $('#allowShareWithLink').val() === 'yes';
if (link && linksAllowed) {
html += '<div id="link">';
- html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share with link')+'</label>';
+ html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share link')+'</label>';
html += '<br />';
html += '<input id="linkText" type="text" readonly="readonly" />';
html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
@@ -310,6 +310,9 @@ OC.Share={
$('#dropdown').show('blind', function() {
OC.Share.droppedDown = true;
});
+ if ($('html').hasClass('lte9')){
+ $('#dropdown input[placeholder]').placeholder();
+ }
$('#shareWith').focus();
},
hideDropDown:function(callback) {
@@ -363,29 +366,21 @@ OC.Share={
shareChecked = 'checked="checked"';
}
var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
- html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
- if(shareWith.length > 14){
- html += escapeHTML(shareWithDisplayName.substr(0,11) + '...');
- }else{
- html += escapeHTML(shareWithDisplayName);
- }
+ var showCrudsButton;
+ html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
+ html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>';
var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
if (mailNotificationEnabled === 'yes') {
var checked = '';
if (mailSend === '1') {
checked = 'checked';
}
- html += '<label><input type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' />'+t('core', 'notify user by email')+'</label>';
+ html += '<label><input type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' />'+t('core', 'notify by email')+'</label> ';
}
if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
- if (editChecked == '') {
- html += '<label style="display:none;">';
- } else {
- html += '<label>';
- }
- html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>';
+ html += '<label><input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label> ';
}
- html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
+ showCrudsButton = '<a href="#" class="showCruds"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>';
html += '<div class="cruds" style="display:none;">';
if (possiblePermissions & OC.PERMISSION_CREATE) {
html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>';
@@ -401,7 +396,15 @@ OC.Share={
}
html += '</div>';
html += '</li>';
- $(html).appendTo('#shareWithList');
+ html = $(html).appendTo('#shareWithList');
+ // insert cruds button into last label element
+ var lastLabel = html.find('>label:last');
+ if (lastLabel.exists()){
+ lastLabel.append(showCrudsButton);
+ }
+ else{
+ html.find('.cruds').before(showCrudsButton);
+ }
$('#expiration').show();
}
},
@@ -507,26 +510,8 @@ $(document).ready(function() {
}
});
- $(document).on('mouseenter', '#dropdown #shareWithList li', function(event) {
- // Show permissions and unshare button
- $(':hidden', this).filter(':not(.cruds)').show();
- });
-
- $(document).on('mouseleave', '#dropdown #shareWithList li', function(event) {
- // Hide permissions and unshare button
- if (!$('.cruds', this).is(':visible')) {
- $('a', this).hide();
- if (!$('input[name="edit"]', this).is(':checked')) {
- $('input[type="checkbox"]', this).hide();
- $('label', this).hide();
- }
- } else {
- $('a.unshare', this).hide();
- }
- });
-
$(document).on('click', '#dropdown .showCruds', function() {
- $(this).parent().find('.cruds').toggle();
+ $(this).closest('li').find('.cruds').toggle();
return false;
});