Subversion Repositories SmartDukaan

Rev

Rev 1035 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1035 Rev 1192
Line 6... Line 6...
6
 * All rights reserved.
6
 * All rights reserved.
7
 */
7
 */
8
/*global jQuery, document, setInterval*/
8
/*global jQuery, document, setInterval*/
9
(function ($) {
9
(function ($) {
10
	var style = document.documentElement.style,
10
	var style = document.documentElement.style,
11
        hasTextOverflow = ('textOverflow' in style || 'OTextOverflow' in style),
-
 
12
 
11
        
13
		domSplit = function (root, maxIndex) {
12
		domSplit = function (root, maxIndex) {
14
			var index = 0, result = [],
13
			var index = 0, result = [],
15
				domSplitAux = function (nodes) {
14
				domSplitAux = function (nodes) {
16
					var i = 0, tmp;
15
					var i = 0, tmp;
17
 
16
 
Line 47... Line 46...
47
 
46
 
48
	$.extend($.fn, {
47
	$.extend($.fn, {
49
        textOverflow: function (str, autoUpdate) {
48
        textOverflow: function (str, autoUpdate) {
50
            var more = str || '…';
49
            var more = str || '…';
51
            
50
            
52
            if (!hasTextOverflow) {
-
 
53
                return this.each(function () {
51
            return this.each(function () {
54
                    var element = $(this),
52
            	var element = $(this),
55
 
53
 
56
                        // the clone element we modify to measure the width 
54
            	// the clone element we modify to measure the width 
57
                        clone = element.clone(),
55
            	clone = element.clone(),
58
 
56
 
59
                        // we save a copy so we can restore it if necessary
57
            	// we save a copy so we can restore it if necessary
60
                        originalElement = element.clone(),
58
            	originalElement = element.clone(),
61
                        originalText = element.text(),
59
            	originalText = element.text(),
62
                        originalWidth = element.width(),
60
            	originalWidth = element.width(),
63
                        low = 0, mid = 0,
61
            	low = 0, mid = 0,
64
                        high = originalText.length,
62
            	high = originalText.length,
65
                        reflow = function () {
63
            	reflow = function () {
66
                            if (originalWidth !== element.width()) {
64
            		if (originalWidth !== element.width()) {
67
                                element.replaceWith(originalElement);
65
            			element.replaceWith(originalElement);
68
                                element = originalElement;
66
            			element = originalElement;
69
                                originalElement = element.clone();
67
            			originalElement = element.clone();
70
                                element.textOverflow(str, false);
68
            			element.textOverflow(str, false);
71
                                originalWidth = element.width();								
69
            			originalWidth = element.width();								
72
                            }
70
            		}
73
                        };
71
            	};
74
 
72
 
75
                    element.after(clone.hide().css({
73
            	element.after(clone.hide().css({
76
						'position': 'absolute',
74
            		'position': 'absolute',
77
						'width': 'auto',
75
            		'width': 'auto',
78
						'overflow': 'visible',
76
            		'overflow': 'visible',
79
						'max-width': 'inherit'
77
            		'max-width': 'inherit'
80
					}));	
78
            	}));	
81
 
79
 
82
                    if (clone.width() > originalWidth) {
80
            	if (clone.width() > originalWidth) {
83
                        while (low < high) {
81
            		while (low < high) {
84
                            mid = Math.floor(low + ((high - low) / 2));
82
            			mid = Math.floor(low + ((high - low) / 2));
85
							clone.empty().append(domSplit(originalElement.get(0), mid)).append(more);
83
            			clone.empty().append(domSplit(originalElement.get(0), mid)).append(more);
86
                            if (clone.width() < originalWidth) {
84
            			if (clone.width() < originalWidth) {
87
                                low = mid + 1;
85
            				low = mid + 1;
88
                            } else {
86
            			} else {
89
                                high = mid;
87
            				high = mid;
90
                            }
88
            			}
91
                        }
89
            		}
92
 
90
 
93
                        if (low < originalText.length) {
91
            		if (low < originalText.length) {
94
							element.empty().append(domSplit(originalElement.get(0), low - 1)).append(more);
92
            			element.empty().append(domSplit(originalElement.get(0), low - 1)).append(more);
95
                        }
93
            		}
96
                        element.attr("Title", originalText);
94
            		element.attr("title", originalText);
97
                    }
95
            	}
98
                    clone.remove();
96
            	clone.remove();
99
                    
-
 
-
 
97
 
100
                    if (autoUpdate) {    
98
            	if (autoUpdate) {    
101
                        setInterval(reflow, 200);
99
            		setInterval(reflow, 200);
102
                    }
-
 
103
                });
100
            	}
104
            } else {
-
 
105
                return this;
-
 
106
            }
101
            });
107
        }
102
        }
108
	});
103
	});
109
})(jQuery);
104
})(jQuery);