Sha256: 34a5a6fb11b1e25963dfea9ffcb277f80cd40d74bb65efbceece20f2f2ef88c4

Contents?: true

Size: 1.75 KB

Versions: 15

Compression:

Stored size: 1.75 KB

Contents

/*
 * jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
 * (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
 */

(function() {

	var fieldSelection = {

		getSelection: function() {

			var e = this.jquery ? this[0] : this;

			return (

				/* mozilla / dom 3.0 */
				('selectionStart' in e && function() {
					var l = e.selectionEnd - e.selectionStart;
					return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
				}) ||

				/* exploder */
				(document.selection && function() {

					e.focus();

					var r = document.selection.createRange();
					if (r == null) {
						return { start: 0, end: e.value.length, length: 0 }
					}

					var re = e.createTextRange();
					var rc = re.duplicate();
					re.moveToBookmark(r.getBookmark());
					rc.setEndPoint('EndToStart', re);

					return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
				}) ||

				/* browser not supported */
				function() {
					return { start: 0, end: e.value.length, length: 0 };
				}

			)();

		},

		replaceSelection: function() {

			var e = this.jquery ? this[0] : this;
			var text = arguments[0] || '';

			return (

				/* mozilla / dom 3.0 */
				('selectionStart' in e && function() {
					e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
					return this;
				}) ||

				/* exploder */
				(document.selection && function() {
					e.focus();
					document.selection.createRange().text = text;
					return this;
				}) ||

				/* browser not supported */
				function() {
					e.value += text;
					return this;
				}

			)();

		}

	};

	jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; });

})();

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
markdown-toolbar-1.0.1 app/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-1.0.0 app/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.2.4 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.2.3 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.1.3 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.1.2 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.8 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.7 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.6 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.5 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.4 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.3 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.2 vendor/assets/javascripts/jquery-fieldselection.js
markdown-toolbar-0.0.1 vendor/assets/javascripts/jquery-fieldselection.js
trainbbcodeeditor-0.1.0 rails_generators/tbbcejs/templates/jquery.fieldselection.js