{"id":801,"date":"2015-05-07T00:14:41","date_gmt":"2015-05-07T00:14:41","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=801"},"modified":"2015-05-07T00:14:41","modified_gmt":"2015-05-07T00:14:41","slug":"extender-htmlinputelement","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=801","title":{"rendered":"extender &#8211; HTMLInputElement"},"content":{"rendered":"<blockquote><p>Goal: give some additional function to the HTMLInputElement type<\/p><\/blockquote>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n\/\/ 1. properties of the selected text (plus the original text as well)\r\nTypeExtend(HTMLInputElement, 'selection', function() {\r\n  var d = this;\r\n\r\n  return {\r\n    position: this.selectionStart,\r\n    start: this.selectionStart,\r\n    end: this.selectionEnd,\r\n    length: this.selectionEnd - this.selectionStart,\r\n    text: this.value.substring(this.selectionStart, this.selectionEnd),\r\n    isAll: function(){var l = d.selectionEnd - d.selectionStart; return (l &gt; 0 &amp;&amp; d.value.length == l);}(),\r\n    _original: {\r\n      text: this.value,\r\n      length: this.value.length\r\n    }\r\n  };\r\n  \r\n});\r\n<\/pre>\n<p>the usage is very simple:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n$('.myinputbox')[0].selection() \r\n{\r\n  position : 0,\r\n  start : 0,\r\n  end : 4,\r\n  length : 4,\r\n  text : 'aaaa',\r\n  isAll : true,\r\n  _original : {\r\n    text: 'aaaa',\r\n    length: 6\r\n  }\r\n}\r\n<\/pre>\n<p>in this case the inputbox value is <code data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">'aaaa'<\/code> and all the text selected <code data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">isAll == true<\/code><br \/>\nthis extender working in <strong>ie<\/strong> as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: give some additional function to the HTMLInputElement type the usage is very simple: in this case the inputbox value is and all the text selected this extender working in ie as well.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-801","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=801"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/801\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/801\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}