From 4161e10192256b578af7353928ea2955395a1e57 Mon Sep 17 00:00:00 2001 From: vitalets Date: Fri, 18 Jan 2013 16:24:01 +0400 Subject: [PATCH 01/37] comments for selector --- src/element/editable-element.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/element/editable-element.js b/src/element/editable-element.js index 0849836..c00ab72 100644 --- a/src/element/editable-element.js +++ b/src/element/editable-element.js @@ -662,10 +662,12 @@ Makes editable any HTML element on the page. Applied as jQuery method. **/ unsavedclass: 'editable-unsaved', /** - If a css selector is provided, editable will be delegated to the specified targets. + If selector is provided, editable will be delegated to the specified targets. Usefull for dynamically generated DOM elements. - **Please note**, that delegated targets can't use `emptytext` and `autotext` options, - as they are initialized after first click. + **Please note**, that delegated targets can't be initialized with `emptytext` and `autotext` options, + as they actually become editable only after first click. + You should manually set class `editable-click` to these elements. + Also, if element originally empty you should add class `editable-empty`, set `data-value=""` and write emptytext into element: @property selector @type string @@ -673,8 +675,10 @@ Makes editable any HTML element on the page. Applied as jQuery method. @default null @example
- awesome - Operator + + Empty + + Operator
+ @property value @type mixed @default element's text From 4a63f802addd0b8bb54a43dc22ff2d0f0460a2b0 Mon Sep 17 00:00:00 2001 From: vitalets Date: Mon, 4 Feb 2013 10:21:18 +0400 Subject: [PATCH 06/37] typo in example code --- src/inputs/checklist.js | 1 - src/inputs/select.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/inputs/checklist.js b/src/inputs/checklist.js index 320b02c..4a194b6 100644 --- a/src/inputs/checklist.js +++ b/src/inputs/checklist.js @@ -16,7 +16,6 @@ $(function(){ {value: 2, text: 'option2'}, {value: 3, text: 'option3'} ] - } }); }); diff --git a/src/inputs/select.js b/src/inputs/select.js index 0a0b4a7..18f0d25 100644 --- a/src/inputs/select.js +++ b/src/inputs/select.js @@ -15,7 +15,6 @@ $(function(){ {value: 2, text: 'Blocked'}, {value: 3, text: 'Deleted'} ] - } }); }); @@ -85,4 +84,4 @@ $(function(){ $.fn.editabletypes.select = Select; -}(window.jQuery)); \ No newline at end of file +}(window.jQuery)); From 35c240ad8130fe06cb635ea9df52b96f6d3d53e7 Mon Sep 17 00:00:00 2001 From: vitalets Date: Tue, 5 Feb 2013 00:23:53 +0400 Subject: [PATCH 07/37] support for autoselect option in typeahead --- src/inputs/typeahead.js | 59 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/inputs/typeahead.js b/src/inputs/typeahead.js index 8945059..dc6d7e1 100644 --- a/src/inputs/typeahead.js +++ b/src/inputs/typeahead.js @@ -25,7 +25,6 @@ $(function(){ {value: 'us', text: 'United States'}, {value: 'ru', text: 'Russia'} ] - } }); }); @@ -57,8 +56,11 @@ $(function(){ //apply typeahead this.$input.typeahead(this.options.typeahead); - //attach own render method - this.$input.data('typeahead').render = $.proxy(this.typeaheadRender, this.$input.data('typeahead')); + //patch some methods in typeahead + var ta = this.$input.data('typeahead'); + ta.render = $.proxy(this.typeaheadRender, ta); + ta.select = $.proxy(this.typeaheadSelect, ta); + ta.move = $.proxy(this.typeaheadMove, ta); this.renderClear(); this.setClass(); @@ -161,7 +163,6 @@ $(function(){ return $.fn.typeahead.Constructor.prototype.highlighter.call(this, item.text); }, updater: function (item) { - item = this.$menu.find('.active').data('item'); this.$element.data('value', item.value); return item.text; }, @@ -172,7 +173,7 @@ $(function(){ There are a lot of disscussion in bootstrap repo on this point and still no result. See https://github.com/twitter/bootstrap/issues/5967 - This function just store item in via jQuery data() method instead of attr('data-value') + This function just store item via jQuery data() method instead of attr('data-value') */ typeaheadRender: function (items) { var that = this; @@ -184,10 +185,56 @@ $(function(){ return i[0]; }); - items.first().addClass('active'); + //add option to disable autoselect of first line + //see https://github.com/twitter/bootstrap/pull/4164 + if (this.options.autoSelect) { + items.first().addClass('active'); + } this.$menu.html(items); return this; + }, + + //add option to disable autoselect of first line + //see https://github.com/twitter/bootstrap/pull/4164 + typeaheadSelect: function () { + var val = this.$menu.find('.active').data('item') + if(this.options.autoSelect || val){ + this.$element + .val(this.updater(val)) + .change() + } + return this.hide() + }, + + /* + if autoSelect = false and nothing matched we need extra press onEnter that is not convinient. + This patch fixes it. + */ + typeaheadMove: function (e) { + if (!this.shown) return + + switch(e.keyCode) { + case 9: // tab + case 13: // enter + case 27: // escape + if (!this.$menu.find('.active').length) return + e.preventDefault() + break + + case 38: // up arrow + e.preventDefault() + this.prev() + break + + case 40: // down arrow + e.preventDefault() + this.next() + break + } + + e.stopPropagation() } + /*jshint eqeqeq: true, curly: true, laxcomma: false*/ }); From 57fe0a3f3d491310b7d175f16ebcb62f9a720976 Mon Sep 17 00:00:00 2001 From: vitalets Date: Tue, 5 Feb 2013 00:31:49 +0400 Subject: [PATCH 08/37] fix lint warns --- src/inputs-ext/address/address.js | 4 +++- src/inputs/typeahead.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/inputs-ext/address/address.js b/src/inputs-ext/address/address.js index 5477d64..c336d87 100644 --- a/src/inputs-ext/address/address.js +++ b/src/inputs-ext/address/address.js @@ -111,7 +111,9 @@ $(function(){ @param {mixed} value **/ value2input: function(value) { - if(!value) return; + if(!value) { + return; + } this.$input.filter('[name="city"]').val(value.city); this.$input.filter('[name="street"]').val(value.street); this.$input.filter('[name="building"]').val(value.building); diff --git a/src/inputs/typeahead.js b/src/inputs/typeahead.js index dc6d7e1..8f1ba36 100644 --- a/src/inputs/typeahead.js +++ b/src/inputs/typeahead.js @@ -139,7 +139,7 @@ $(function(){ /* Typeahead option methods used as defaults */ - /*jshint eqeqeq:false, curly: false, laxcomma: true*/ + /*jshint eqeqeq:false, curly: false, laxcomma: true, asi: true*/ matcher: function (item) { return $.fn.typeahead.Constructor.prototype.matcher.call(this, item.text); }, @@ -235,7 +235,7 @@ $(function(){ e.stopPropagation() } - /*jshint eqeqeq: true, curly: true, laxcomma: false*/ + /*jshint eqeqeq: true, curly: true, laxcomma: false, asi: false*/ }); From 31e39ab988806058aefca2fbc1cca5844103dbd8 Mon Sep 17 00:00:00 2001 From: vitalets Date: Tue, 5 Feb 2013 00:32:36 +0400 Subject: [PATCH 09/37] set ver 1.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1bae2fe..cf6190e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "X-editable", "title": "X-editable", "description": "In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery", - "version": "1.4.1", + "version": "1.4.2", "homepage": "http://github.com/vitalets/x-editable", "author": { "name": "Vitaliy Potapov", From e6224d3f0c8da98db0d8e996b2b33ecbafa8f638 Mon Sep 17 00:00:00 2001 From: vitalets Date: Wed, 6 Feb 2013 22:03:23 +0400 Subject: [PATCH 10/37] fix slow typing caused clear show/hide --- src/inputs/text.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/inputs/text.js b/src/inputs/text.js index b41d717..3c688c7 100644 --- a/src/inputs/text.js +++ b/src/inputs/text.js @@ -68,14 +68,24 @@ $(function(){ }, //show / hide clear button - toggleClear: function() { + toggleClear: function(e) { if(!this.$clear) { return; } - if(this.$input.val().length) { + //arrows, enter, tab, etc + if(~$.inArray(e.keyCode, [40,38,9,13,27])) { + return; + } + + var len = this.$input.val().length, + visible = this.$clear.is(':visible'); + + if(len && !visible) { this.$clear.show(); - } else { + } + + if(!len && visible) { this.$clear.hide(); } }, From 3df24e44b3a9943d8afd1a72176fe3d6ccb20f55 Mon Sep 17 00:00:00 2001 From: vitalets Date: Wed, 6 Feb 2013 22:04:29 +0400 Subject: [PATCH 11/37] comments for shown event --- src/containers/editable-container.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/editable-container.js b/src/containers/editable-container.js index 83cd56f..987a920 100644 --- a/src/containers/editable-container.js +++ b/src/containers/editable-container.js @@ -125,8 +125,8 @@ Applied as jQuery method. @param {Object} event event object @example $('#username').on('shown', function() { - var $tip = $(this).data('editableContainer').tip(); - $tip.find('input').val('overwriting value of input..'); + var editable = $(this).data('editable'); + editable.input.$input.val('overwriting value of input..'); }); **/ this.$element.triggerHandler('shown'); From 224acee2ec9f5aff9dc436d8eb32268ab618eaba Mon Sep 17 00:00:00 2001 From: vitalets Date: Wed, 6 Feb 2013 22:04:48 +0400 Subject: [PATCH 12/37] add jquery 1.9.0 --- test/libs/jquery/jquery-1.9.0.min.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/libs/jquery/jquery-1.9.0.min.js diff --git a/test/libs/jquery/jquery-1.9.0.min.js b/test/libs/jquery/jquery-1.9.0.min.js new file mode 100644 index 0000000..50d1b22 --- /dev/null +++ b/test/libs/jquery/jquery-1.9.0.min.js @@ -0,0 +1,4 @@ +/*! jQuery v1.9.0 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license */(function(e,t){"use strict";function n(e){var t=e.length,n=st.type(e);return st.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}function r(e){var t=Tt[e]={};return st.each(e.match(lt)||[],function(e,n){t[n]=!0}),t}function i(e,n,r,i){if(st.acceptData(e)){var o,a,s=st.expando,u="string"==typeof n,l=e.nodeType,c=l?st.cache:e,f=l?e[s]:e[s]&&s;if(f&&c[f]&&(i||c[f].data)||!u||r!==t)return f||(l?e[s]=f=K.pop()||st.guid++:f=s),c[f]||(c[f]={},l||(c[f].toJSON=st.noop)),("object"==typeof n||"function"==typeof n)&&(i?c[f]=st.extend(c[f],n):c[f].data=st.extend(c[f].data,n)),o=c[f],i||(o.data||(o.data={}),o=o.data),r!==t&&(o[st.camelCase(n)]=r),u?(a=o[n],null==a&&(a=o[st.camelCase(n)])):a=o,a}}function o(e,t,n){if(st.acceptData(e)){var r,i,o,a=e.nodeType,u=a?st.cache:e,l=a?e[st.expando]:st.expando;if(u[l]){if(t&&(r=n?u[l]:u[l].data)){st.isArray(t)?t=t.concat(st.map(t,st.camelCase)):t in r?t=[t]:(t=st.camelCase(t),t=t in r?[t]:t.split(" "));for(i=0,o=t.length;o>i;i++)delete r[t[i]];if(!(n?s:st.isEmptyObject)(r))return}(n||(delete u[l].data,s(u[l])))&&(a?st.cleanData([e],!0):st.support.deleteExpando||u!=u.window?delete u[l]:u[l]=null)}}}function a(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(Nt,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:wt.test(r)?st.parseJSON(r):r}catch(o){}st.data(e,n,r)}else r=t}return r}function s(e){var t;for(t in e)if(("data"!==t||!st.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function u(){return!0}function l(){return!1}function c(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function f(e,t,n){if(t=t||0,st.isFunction(t))return st.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return st.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=st.grep(e,function(e){return 1===e.nodeType});if(Wt.test(t))return st.filter(t,r,!n);t=st.filter(t,r)}return st.grep(e,function(e){return st.inArray(e,t)>=0===n})}function p(e){var t=zt.split("|"),n=e.createDocumentFragment();if(n.createElement)for(;t.length;)n.createElement(t.pop());return n}function d(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function h(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function g(e){var t=nn.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function m(e,t){for(var n,r=0;null!=(n=e[r]);r++)st._data(n,"globalEval",!t||st._data(t[r],"globalEval"))}function y(e,t){if(1===t.nodeType&&st.hasData(e)){var n,r,i,o=st._data(e),a=st._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)st.event.add(t,n,s[n][r])}a.data&&(a.data=st.extend({},a.data))}}function v(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!st.support.noCloneEvent&&t[st.expando]){r=st._data(t);for(i in r.events)st.removeEvent(t,i,r.handle);t.removeAttribute(st.expando)}"script"===n&&t.text!==e.text?(h(t).text=e.text,g(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),st.support.html5Clone&&e.innerHTML&&!st.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Zt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}function b(e,n){var r,i,o=0,a=e.getElementsByTagName!==t?e.getElementsByTagName(n||"*"):e.querySelectorAll!==t?e.querySelectorAll(n||"*"):t;if(!a)for(a=[],r=e.childNodes||e;null!=(i=r[o]);o++)!n||st.nodeName(i,n)?a.push(i):st.merge(a,b(i,n));return n===t||n&&st.nodeName(e,n)?st.merge([e],a):a}function x(e){Zt.test(e.type)&&(e.defaultChecked=e.checked)}function T(e,t){if(t in e)return t;for(var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Nn.length;i--;)if(t=Nn[i]+n,t in e)return t;return r}function w(e,t){return e=t||e,"none"===st.css(e,"display")||!st.contains(e.ownerDocument,e)}function N(e,t){for(var n,r=[],i=0,o=e.length;o>i;i++)n=e[i],n.style&&(r[i]=st._data(n,"olddisplay"),t?(r[i]||"none"!==n.style.display||(n.style.display=""),""===n.style.display&&w(n)&&(r[i]=st._data(n,"olddisplay",S(n.nodeName)))):r[i]||w(n)||st._data(n,"olddisplay",st.css(n,"display")));for(i=0;o>i;i++)n=e[i],n.style&&(t&&"none"!==n.style.display&&""!==n.style.display||(n.style.display=t?r[i]||"":"none"));return e}function C(e,t,n){var r=mn.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function k(e,t,n,r,i){for(var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;4>o;o+=2)"margin"===n&&(a+=st.css(e,n+wn[o],!0,i)),r?("content"===n&&(a-=st.css(e,"padding"+wn[o],!0,i)),"margin"!==n&&(a-=st.css(e,"border"+wn[o]+"Width",!0,i))):(a+=st.css(e,"padding"+wn[o],!0,i),"padding"!==n&&(a+=st.css(e,"border"+wn[o]+"Width",!0,i)));return a}function E(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=ln(e),a=st.support.boxSizing&&"border-box"===st.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=un(e,t,o),(0>i||null==i)&&(i=e.style[t]),yn.test(i))return i;r=a&&(st.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+k(e,t,n||(a?"border":"content"),r,o)+"px"}function S(e){var t=V,n=bn[e];return n||(n=A(e,t),"none"!==n&&n||(cn=(cn||st("