mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update version of jQuery used in content server and viewer. Required a little hackery in the viewer, hopefully nothing broke
This commit is contained in:
parent
279eead323
commit
e9af0cdf8f
8081
resources/content_server/jquery.js
vendored
8081
resources/content_server/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@ function selector(elem) {
|
|||||||
sel = selector_in_parent(obj) + sel;
|
sel = selector_in_parent(obj) + sel;
|
||||||
obj = obj.parent();
|
obj = obj.parent();
|
||||||
}
|
}
|
||||||
|
if (sel.length > 2 && sel.charAt(1) == ">") sel = sel.substring(2);
|
||||||
return sel;
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +27,8 @@ function calculate_bookmark(y, node) {
|
|||||||
var ratio = (y - elem.offset().top)/elem.height();
|
var ratio = (y - elem.offset().top)/elem.height();
|
||||||
if (ratio > 1) { ratio = 1; }
|
if (ratio > 1) { ratio = 1; }
|
||||||
if (ratio < 0) { ratio = 0; }
|
if (ratio < 0) { ratio = 0; }
|
||||||
return sel + "|" + ratio;
|
sel = sel + "|" + ratio;
|
||||||
|
return sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function animated_scrolling_done() {
|
function animated_scrolling_done() {
|
||||||
@ -37,6 +39,10 @@ function scroll_to_bookmark(bookmark) {
|
|||||||
bm = bookmark.split("|");
|
bm = bookmark.split("|");
|
||||||
var ratio = 0.7 * parseFloat(bm[1]);
|
var ratio = 0.7 * parseFloat(bm[1]);
|
||||||
$.scrollTo($(bm[0]), 1000,
|
$.scrollTo($(bm[0]), 1000,
|
||||||
{over:ratio, onAfter:function(){window.py_bridge.animated_scroll_done()}});
|
{
|
||||||
|
over:ratio,
|
||||||
|
onAfter:function(){window.py_bridge.animated_scroll_done()}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
93
resources/viewer/jquery_scrollTo.js
vendored
93
resources/viewer/jquery_scrollTo.js
vendored
@ -1,15 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* jQuery.ScrollTo
|
* jQuery.ScrollTo
|
||||||
* Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
||||||
* Dual licensed under MIT and GPL.
|
* Dual licensed under MIT and GPL.
|
||||||
* Date: 9/11/2008
|
* Date: 5/25/2009
|
||||||
*
|
*
|
||||||
* @projectDescription Easy element scrolling using jQuery.
|
* @projectDescription Easy element scrolling using jQuery.
|
||||||
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
|
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
|
||||||
* Tested with jQuery 1.2.6. On FF 2/3, IE 6/7, Opera 9.2/5 and Safari 3. on Windows.
|
* Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
|
||||||
*
|
*
|
||||||
* @author Ariel Flesler
|
* @author Ariel Flesler
|
||||||
* @version 1.4
|
* @version 1.4.2
|
||||||
*
|
*
|
||||||
* @id jQuery.scrollTo
|
* @id jQuery.scrollTo
|
||||||
* @id jQuery.fn.scrollTo
|
* @id jQuery.fn.scrollTo
|
||||||
@ -20,6 +20,8 @@
|
|||||||
* - A jQuery/DOM element ( logically, child of the element to scroll )
|
* - A jQuery/DOM element ( logically, child of the element to scroll )
|
||||||
* - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
|
* - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
|
||||||
* - A hash { top:x, left:y }, x and y can be any kind of number/string like above.
|
* - A hash { top:x, left:y }, x and y can be any kind of number/string like above.
|
||||||
|
* - A percentage of the container's dimension/s, for example: 50% to go to the middle.
|
||||||
|
* - The string 'max' for go-to-end.
|
||||||
* @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
|
* @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
|
||||||
* @param {Object,Function} settings Optional set of settings or the onAfter callback.
|
* @param {Object,Function} settings Optional set of settings or the onAfter callback.
|
||||||
* @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
|
* @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
|
||||||
@ -58,31 +60,31 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scrollTo.defaults = {
|
$scrollTo.defaults = {
|
||||||
axis:'y',
|
axis:'xy',
|
||||||
duration:1
|
duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns the element that needs to be animated to scroll the window.
|
// Returns the element that needs to be animated to scroll the window.
|
||||||
// Kept for backwards compatibility (specially for localScroll & serialScroll)
|
// Kept for backwards compatibility (specially for localScroll & serialScroll)
|
||||||
$scrollTo.window = function( scope ){
|
$scrollTo.window = function( scope ){
|
||||||
return $(window).scrollable();
|
return $(window)._scrollable();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hack, hack, hack... stay away!
|
// Hack, hack, hack :)
|
||||||
// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
|
// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
|
||||||
$.fn.scrollable = function(){
|
$.fn._scrollable = function(){
|
||||||
return this.map(function(){
|
return this.map(function(){
|
||||||
// Just store it, we might need it
|
var elem = this,
|
||||||
var win = this.parentWindow || this.defaultView,
|
isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;
|
||||||
// If it's a document, get its iframe or the window if it's THE document
|
|
||||||
elem = this.nodeName == '#document' ? win.frameElement || win : this,
|
|
||||||
// Get the corresponding document
|
|
||||||
doc = elem.contentDocument || (elem.contentWindow || elem).document,
|
|
||||||
isWin = elem.setInterval;
|
|
||||||
|
|
||||||
return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
|
if( !isWin )
|
||||||
: isWin ? doc.documentElement
|
return elem;
|
||||||
: this;
|
|
||||||
|
var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
|
||||||
|
|
||||||
|
return $.browser.safari || doc.compatMode == 'BackCompat' ?
|
||||||
|
doc.body :
|
||||||
|
doc.documentElement;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,6 +96,9 @@
|
|||||||
if( typeof settings == 'function' )
|
if( typeof settings == 'function' )
|
||||||
settings = { onAfter:settings };
|
settings = { onAfter:settings };
|
||||||
|
|
||||||
|
if( target == 'max' )
|
||||||
|
target = 9e9;
|
||||||
|
|
||||||
settings = $.extend( {}, $scrollTo.defaults, settings );
|
settings = $.extend( {}, $scrollTo.defaults, settings );
|
||||||
// Speed is still recognized for backwards compatibility
|
// Speed is still recognized for backwards compatibility
|
||||||
duration = duration || settings.speed || settings.duration;
|
duration = duration || settings.speed || settings.duration;
|
||||||
@ -106,7 +111,7 @@
|
|||||||
settings.offset = both( settings.offset );
|
settings.offset = both( settings.offset );
|
||||||
settings.over = both( settings.over );
|
settings.over = both( settings.over );
|
||||||
|
|
||||||
return this.scrollable().each(function(){
|
return this._scrollable().each(function(){
|
||||||
var elem = this,
|
var elem = this,
|
||||||
$elem = $(elem),
|
$elem = $(elem),
|
||||||
targ = target, toff, attr = {},
|
targ = target, toff, attr = {},
|
||||||
@ -116,7 +121,7 @@
|
|||||||
// A number will pass the regex
|
// A number will pass the regex
|
||||||
case 'number':
|
case 'number':
|
||||||
case 'string':
|
case 'string':
|
||||||
if( /^([+-]=)?\d+(px)?$/.test(targ) ){
|
if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
|
||||||
targ = both( targ );
|
targ = both( targ );
|
||||||
// We are done
|
// We are done
|
||||||
break;
|
break;
|
||||||
@ -134,8 +139,7 @@
|
|||||||
pos = Pos.toLowerCase(),
|
pos = Pos.toLowerCase(),
|
||||||
key = 'scroll' + Pos,
|
key = 'scroll' + Pos,
|
||||||
old = elem[key],
|
old = elem[key],
|
||||||
Dim = axis == 'x' ? 'Width' : 'Height',
|
max = $scrollTo.max(elem, axis);
|
||||||
dim = Dim.toLowerCase();
|
|
||||||
|
|
||||||
if( toff ){// jQuery / DOMElement
|
if( toff ){// jQuery / DOMElement
|
||||||
attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
|
attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
|
||||||
@ -150,14 +154,19 @@
|
|||||||
|
|
||||||
if( settings.over[pos] )
|
if( settings.over[pos] )
|
||||||
// Scroll to a fraction of its width/height
|
// Scroll to a fraction of its width/height
|
||||||
attr[key] += targ[dim]() * settings.over[pos];
|
attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
|
||||||
}else
|
}else{
|
||||||
attr[key] = targ[pos];
|
var val = targ[pos];
|
||||||
|
// Handle percentage values
|
||||||
|
attr[key] = val.slice && val.slice(-1) == '%' ?
|
||||||
|
parseFloat(val) / 100 * max
|
||||||
|
: val;
|
||||||
|
}
|
||||||
|
|
||||||
// Number or 'number'
|
// Number or 'number'
|
||||||
if( /^\d+$/.test(attr[key]) )
|
if( /^\d+$/.test(attr[key]) )
|
||||||
// Check the limits
|
// Check the limits
|
||||||
attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );
|
attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
|
||||||
|
|
||||||
// Queueing axes
|
// Queueing axes
|
||||||
if( !i && settings.queue ){
|
if( !i && settings.queue ){
|
||||||
@ -168,7 +177,8 @@
|
|||||||
// Don't animate this axis again in the next iteration.
|
// Don't animate this axis again in the next iteration.
|
||||||
delete attr[key];
|
delete attr[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
animate( settings.onAfter );
|
animate( settings.onAfter );
|
||||||
|
|
||||||
function animate( callback ){
|
function animate( callback ){
|
||||||
@ -176,16 +186,27 @@
|
|||||||
callback.call(this, target, settings);
|
callback.call(this, target, settings);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
function max( Dim ){
|
|
||||||
var attr ='scroll'+Dim,
|
|
||||||
doc = elem.ownerDocument;
|
|
||||||
|
|
||||||
return win
|
|
||||||
? Math.max( doc.documentElement[attr], doc.body[attr] )
|
|
||||||
: elem[attr];
|
|
||||||
};
|
|
||||||
}).end();
|
}).end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Max scrolling position, works on quirks mode
|
||||||
|
// It only fails (not too badly) on IE, quirks mode.
|
||||||
|
$scrollTo.max = function( elem, axis ){
|
||||||
|
var Dim = axis == 'x' ? 'Width' : 'Height',
|
||||||
|
scroll = 'scroll'+Dim;
|
||||||
|
|
||||||
|
if( !$(elem).is('html,body') )
|
||||||
|
return elem[scroll] - $(elem)[Dim.toLowerCase()]();
|
||||||
|
|
||||||
|
var size = 'client' + Dim,
|
||||||
|
html = elem.ownerDocument.documentElement,
|
||||||
|
body = elem.ownerDocument.body;
|
||||||
|
|
||||||
|
return Math.max( html[scroll], body[scroll] )
|
||||||
|
- Math.min( html[size] , body[size] );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
function both( val ){
|
function both( val ){
|
||||||
return typeof val == 'object' ? val : { top:val, left:val };
|
return typeof val == 'object' ? val : { top:val, left:val };
|
||||||
|
@ -150,6 +150,7 @@ class Document(QWebPage):
|
|||||||
self.setObjectName("py_bridge")
|
self.setObjectName("py_bridge")
|
||||||
self.debug_javascript = False
|
self.debug_javascript = False
|
||||||
self.current_language = None
|
self.current_language = None
|
||||||
|
self.loaded_javascript = False
|
||||||
|
|
||||||
self.setLinkDelegationPolicy(self.DelegateAllLinks)
|
self.setLinkDelegationPolicy(self.DelegateAllLinks)
|
||||||
self.scroll_marks = []
|
self.scroll_marks = []
|
||||||
@ -177,7 +178,7 @@ class Document(QWebPage):
|
|||||||
|
|
||||||
# Load javascript
|
# Load javascript
|
||||||
self.mainFrame().javaScriptWindowObjectCleared.connect(
|
self.mainFrame().javaScriptWindowObjectCleared.connect(
|
||||||
self.load_javascript_libraries)
|
self.add_window_objects)
|
||||||
|
|
||||||
def set_user_stylesheet(self):
|
def set_user_stylesheet(self):
|
||||||
raw = config().parse().user_css
|
raw = config().parse().user_css
|
||||||
@ -196,16 +197,20 @@ class Document(QWebPage):
|
|||||||
if self.do_fit_images:
|
if self.do_fit_images:
|
||||||
self.javascript('setup_image_scaling_handlers()')
|
self.javascript('setup_image_scaling_handlers()')
|
||||||
|
|
||||||
|
def add_window_objects(self):
|
||||||
|
self.mainFrame().addToJavaScriptWindowObject("py_bridge", self)
|
||||||
|
self.loaded_javascript = False
|
||||||
|
|
||||||
def load_javascript_libraries(self):
|
def load_javascript_libraries(self):
|
||||||
global bookmarks, referencing, hyphenation, jquery, jquery_scrollTo, hyphenator, images
|
global bookmarks, referencing, hyphenation, jquery, jquery_scrollTo, hyphenator, images
|
||||||
self.mainFrame().addToJavaScriptWindowObject("py_bridge", self)
|
if self.loaded_javascript:
|
||||||
|
return
|
||||||
|
self.loaded_javascript = True
|
||||||
if jquery is None:
|
if jquery is None:
|
||||||
jquery = P('content_server/jquery.js', data=True)
|
jquery = P('content_server/jquery.js', data=True)
|
||||||
|
self.javascript(jquery)
|
||||||
if jquery_scrollTo is None:
|
if jquery_scrollTo is None:
|
||||||
jquery_scrollTo = P('viewer/jquery_scrollTo.js', data=True)
|
jquery_scrollTo = P('viewer/jquery_scrollTo.js', data=True)
|
||||||
if hyphenator is None:
|
|
||||||
hyphenator = P('viewer/hyphenate/Hyphenator.js', data=True).decode('utf-8')
|
|
||||||
self.javascript(jquery)
|
|
||||||
self.javascript(jquery_scrollTo)
|
self.javascript(jquery_scrollTo)
|
||||||
if bookmarks is None:
|
if bookmarks is None:
|
||||||
bookmarks = P('viewer/bookmarks.js', data=True)
|
bookmarks = P('viewer/bookmarks.js', data=True)
|
||||||
@ -224,6 +229,8 @@ class Document(QWebPage):
|
|||||||
if not lang:
|
if not lang:
|
||||||
lang = default_lang
|
lang = default_lang
|
||||||
lang = lang.lower()[:2]
|
lang = lang.lower()[:2]
|
||||||
|
if hyphenator is None:
|
||||||
|
hyphenator = P('viewer/hyphenate/Hyphenator.js', data=True).decode('utf-8')
|
||||||
self.javascript(hyphenator)
|
self.javascript(hyphenator)
|
||||||
p = P('viewer/hyphenate/patterns/%s.js'%lang)
|
p = P('viewer/hyphenate/patterns/%s.js'%lang)
|
||||||
if not os.path.exists(p):
|
if not os.path.exists(p):
|
||||||
@ -256,6 +263,9 @@ class Document(QWebPage):
|
|||||||
self.javascript('goto_reference("%s")'%ref)
|
self.javascript('goto_reference("%s")'%ref)
|
||||||
|
|
||||||
def goto_bookmark(self, bm):
|
def goto_bookmark(self, bm):
|
||||||
|
bm = bm.strip()
|
||||||
|
if bm.startswith('>'):
|
||||||
|
bm = bm[1:].strip()
|
||||||
self.javascript('scroll_to_bookmark("%s")'%bm)
|
self.javascript('scroll_to_bookmark("%s")'%bm)
|
||||||
|
|
||||||
def javascript(self, string, typ=None):
|
def javascript(self, string, typ=None):
|
||||||
@ -641,6 +651,7 @@ class DocumentView(QWebView):
|
|||||||
# An <iframe> finished loading
|
# An <iframe> finished loading
|
||||||
return
|
return
|
||||||
self.loading_url = None
|
self.loading_url = None
|
||||||
|
self.document.load_javascript_libraries()
|
||||||
self.document.set_bottom_padding(0)
|
self.document.set_bottom_padding(0)
|
||||||
self.document.fit_images()
|
self.document.fit_images()
|
||||||
self._size_hint = self.document.mainFrame().contentsSize()
|
self._size_hint = self.document.mainFrame().contentsSize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user