From: Marek Stępniowski Date: Fri, 7 Aug 2009 11:26:46 +0000 (+0200) Subject: Dodanie biblioteki jquery.fieldselection.js do wyciągania i zmieniania tekstu zaznacz... X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/d125fa3cb06bb8f426b5b54743489f8cff906760?ds=sidebyside Dodanie biblioteki jquery.fieldselection.js do wyciągania i zmieniania tekstu zaznaczonego w TextArea. --- diff --git a/project/static/js/jquery.fieldselection.js b/project/static/js/jquery.fieldselection.js new file mode 100644 index 00000000..448f9dc0 --- /dev/null +++ b/project/static/js/jquery.fieldselection.js @@ -0,0 +1,65 @@ +(function() { + jQuery.fn.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) }; + }) || + + // Internet Explorer + (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 null; } + )(); + }, + + jQuery.fn.replaceSelection = function() { + var e = this.jquery ? this[0] : this; + var text = arguments[0] || ''; + var scrollTop = $(this).scrollTop(); + + return ( + // Mozilla / dom 3.0 + ('selectionStart' in e && function() { + var selectionStart = e.selectionStart; + console.log(e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length)); + e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length); + $(e).scrollTop(scrollTop).focus(); + e.selectionStart = selectionStart + text.length; + e.selectionEnd = selectionStart + text.length; + return this; + }) || + + // Internet Explorer + (document.selection && function() { + e.focus(); + document.selection.createRange().text = text; + return this; + }) || + + // browser not supported + function() { + e.value += text; + return jQuery(e); + } + )(); + } +})(); \ No newline at end of file diff --git a/project/static/js/jquery.lazyload.js b/project/static/js/jquery.lazyload.js deleted file mode 100644 index 98a74c13..00000000 --- a/project/static/js/jquery.lazyload.js +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Lazy Load - jQuery plugin for lazy loading images - * - * Copyright (c) 2007-2009 Mika Tuupola - * - * Licensed under the MIT license: - * http://www.opensource.org/licenses/mit-license.php - * - * Project home: - * http://www.appelsiini.net/projects/lazyload - * - * Version: 1.3.2 - * - */ -(function($) { - - $.fn.lazyload = function(options) { - var settings = { - threshold : 0, - failurelimit : 0, - event : "scroll", - effect : "show", - container : window - }; - - if(options) { - $.extend(settings, options); - } - - /* Fire one scroll event per scroll. Not one scroll event per image. */ - var elements = this; - if ("scroll" == settings.event) { - $(settings.container).bind("scroll", function(event) { - var counter = 0; - elements.each(function() { - if (!$.belowthefold(this, settings) && - !$.rightoffold(this, settings)) { - $(this).trigger("appear"); - } else { - if (counter++ > settings.failurelimit) { - return false; - } - } - }); - /* Remove image from array so it is not looped next time. */ - var temp = $.grep(elements, function(element) { - return !element.loaded; - }); - elements = $(temp); - }); - } - - return this.each(function() { - var self = this; - /* TODO: use .data() instead of .attr() */ - $(self).attr("original", $(self).attr("src")); - if ("scroll" != settings.event - || $.belowthefold(self, settings) - || $.rightoffold(self, settings)) { - if (settings.placeholder) { - $(self).attr("src", settings.placeholder); - } else { - $(self).removeAttr("src"); - } - self.loaded = false; - } else { - self.loaded = true; - } - - /* When appear is triggered load original image. */ - $(self).one("appear", function() { - if (!this.loaded) { - $("") - .bind("load", function() { - $(self) - .hide() - .attr("src", $(self).attr("original")) - [settings.effect](settings.effectspeed); - self.loaded = true; - }) - .attr("src", $(self).attr("original")); - }; - }); - - /* When wanted event is triggered load original image */ - /* by triggering appear. */ - if ("scroll" != settings.event) { - $(self).bind(settings.event, function(event) { - if (!self.loaded) { - $(self).trigger("appear"); - } - }); - } - }); - - }; - - /* Convenience methods in jQuery namespace. */ - /* Use as $.belowthefold(element, {threshold : 100, container : window}) */ - - $.belowthefold = function(element, settings) { - if (settings.container === undefined || settings.container === window) { - var fold = $(window).height() + $(window).scrollTop(); - } - else { - var fold = $(settings.container).offset().top + $(settings.container).height(); - } - return fold <= $(element).offset().top - settings.threshold; - }; - - $.rightoffold = function(element, settings) { - if (settings.container === undefined || settings.container === window) { - var fold = $(window).width() + $(window).scrollLeft(); - } - else { - var fold = $(settings.container).offset().left + $(settings.container).width(); - } - return fold <= $(element).offset().left - settings.threshold; - }; - - $.aboveViewport = function(element, settings) { - if (settings.container === undefined || settings.container === window) { - var top = $(window).scrollTop(); - } - else { - var top = $(settings.container).offset().top; - } - return top >= $(element).offset().bottom - settings.threshold; - }; - - /* Custom selectors for your convenience. */ - /* Use as $("img:below-the-fold").something() */ - - $.extend($.expr[':'], { - "below-the-fold" : "$.belowthefold(a, {threshold : 0, container: window})", - "above-the-fold" : "!$.belowthefold(a, {threshold : 0, container: window})", - "right-of-fold" : "$.rightoffold(a, {threshold : 0, container: window})", - "left-of-fold" : "!$.rightoffold(a, {threshold : 0, container: window})" - }); - -})(jQuery);