Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created March 18, 2012 04:04
Show Gist options
  • Save pamelafox/2068758 to your computer and use it in GitHub Desktop.
Save pamelafox/2068758 to your computer and use it in GitHub Desktop.
Zepto + FancyBox Diffs
diff --git a/application/static/js/libs/jquery.fancybox.js b/application/static/js/libs/jquery.fancybox.js
index be77275..c1d74b7 100755
--- a/application/static/js/libs/jquery.fancybox.js
+++ b/application/static/js/libs/jquery.fancybox.js
@@ -359,7 +359,6 @@
this.style.visibility = 'inherit';
});
}
-
overlay.show();
}
} else {
@@ -386,7 +385,7 @@
content.fadeTo(currentOpts.changeFade, 0.3, function() {
var finish_resizing = function() {
- content.html( tmp.contents() ).fadeTo(currentOpts.changeFade, 1, _finish);
+ content.html( tmp.children() ).fadeTo(currentOpts.changeFade, 1, _finish);
};
$.event.trigger('fancybox-change');
@@ -425,7 +424,7 @@
if (currentOpts.transitionIn == 'elastic') {
start_pos = _get_zoom_from();
- content.html( tmp.contents() );
+ content.html( tmp.children() );
wrap.show();
@@ -454,7 +453,7 @@
'width' : final_pos.width - currentOpts.padding * 2,
'height' : selectedOpts.autoDimensions ? 'auto' : final_pos.height - titleHeight - currentOpts.padding * 2
})
- .html( tmp.contents() );
+ .html( tmp.children() );
wrap
.css(final_pos)
@@ -957,7 +956,7 @@
title.empty().hide();
wrap.hide();
- $.event.trigger('fancybox-cleanup');
+ $('#fancybox-overlay, #fancybox-inline-tmp').trigger('fancybox-cleanup');
content.empty();
@@ -1153,4 +1151,4 @@
$.fancybox.init();
});
-})(jQuery);
\ No newline at end of file
+})(window.jQuery || window.Zepto);
\ No newline at end of file
diff --git a/application/static/js/libs/phonegap-fb.js b/application/static/js/libs/phonegap-fb.js
new file mode 100644
index 0000000..b3da333
--- /dev/null
+++ b/application/static/js/libs/phonegap-fb.js
@@ -0,0 +1 @@
+/* Intentionally left blank. */
\ No newline at end of file
diff --git a/application/static/js/libs/zepto.js b/application/static/js/libs/zepto.js
index fbba92c..5ee1b71 100644
--- a/application/static/js/libs/zepto.js
+++ b/application/static/js/libs/zepto.js
@@ -98,7 +98,10 @@ var Zepto = (function() {
}
function fragment(html, name) {
- if (name === undefined) fragmentRE.test(html) && RegExp.$1;
+ if (name === undefined) {
+ if (!fragmentRE.test(html)) return document.createTextNode(html);
+ name = RegExp.$1;
+ }
if (!(name in containers)) name = '*';
var container = containers[name];
container.innerHTML = '' + html;
@@ -248,6 +251,12 @@ var Zepto = (function() {
},
filter: function(selector){
return $([].filter.call(this, function(element){
+ if (selector === ':visible') {
+ var width = element.offsetWidth;
+ var height = element.offsetHeight;
+ var isHidden = (width === 0 && height === 0) || $(element).css("display") === "none";
+ return !isHidden;
+ }
return element.parentNode && $$(element.parentNode, selector).indexOf(element) >= 0;
}));
},
@@ -498,9 +507,10 @@ var Zepto = (function() {
}
adjacencyOperators.forEach(function(key, operator) {
- $.fn[key] = function(html){
- var nodes = isO(html) ? html : fragment(html);
- if (!('length' in nodes) || nodes.nodeType) nodes = [nodes];
+ $.fn[key] = function(){
+ var nodes = $.map(arguments, function(html) {
+ return isO(html) ? html : fragment(html);
+ });
if (nodes.length < 1) return this;
var size = this.length, copyByClone = size > 1, inReverse = operator < 2;
@@ -1427,17 +1437,8 @@ window.Zepto = Zepto;
$.expr = {':': {}};
// Used by bootstrap
- $.support = {};
-
+ $.support = {
+ opacity: true
};
// Used by dateinput
@@ -1610,3 +1611,192 @@ window.Zepto = Zepto;
};
})(Zepto);
+// Zepto.js
+// (c) 2010, 2011 Thomas Fuchs
+// Zepto.js may be freely distributed under the MIT license.
+
+(function($, undefined){
+ var prefix = '', eventPrefix, endEventName, endAnimationName,
+ vendors = {Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS'},
+ document = window.document, testEl = document.createElement('div'),
+ supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i;
+ cachedAnimation = {};
+
+ function downcase(str) { return str.toLowerCase() }
+ function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) };
+
+ $.each(vendors, function(vendor, event){
+ if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
+ prefix = '-' + downcase(vendor) + '-';
+ eventPrefix = event;
+ return false;
+ }
+ });
+
+ $.fx = {
+ off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined),
+ cssPrefix: prefix,
+ transitionEnd: normalizeEvent('TransitionEnd'),
+ animationEnd: normalizeEvent('AnimationEnd')
+ };
+
+ $.fn.animate = function(properties, duration, ease, callback){
+ if ($.isObject(duration))
+ ease = duration.easing, callback = duration.complete, duration = duration.duration;
+ if (duration) duration = duration / 1000;
+ return this.anim(properties, duration, ease, callback);
+ };
+
+ $.fn.stop = function(){
+ if(cachedAnimation.callback && cachedAnimation.endEvent){
+ this.one(cachedAnimation.endEvent, cachedAnimation.callback);
+ }
+ cachedAnimation = {};
+ return this;
+ }
+
+ $.fn.anim = function(properties, duration, ease, callback){
+ var transforms, cssProperties = {}, key, that = this, wrappedCallback, endEvent = $.fx.transitionEnd;
+ if (duration === undefined) duration = 0.4;
+ if ($.fx.off) duration = 0;
+
+ if (typeof properties == 'string') {
+ // keyframe animation
+ cssProperties[prefix + 'animation-name'] = properties;
+ cssProperties[prefix + 'animation-duration'] = duration + 's';
+ endEvent = $.fx.animationEnd;
+ } else {
+ // CSS transitions
+ for (key in properties)
+ if (supportedTransforms.test(key)) {
+ transforms || (transforms = []);
+ transforms.push(key + '(' + properties[key] + ')');
+ }
+ else cssProperties[key] = properties[key];
+
+ if (transforms) cssProperties[prefix + 'transform'] = transforms.join(' ');
+ if (!$.fx.off) cssProperties[prefix + 'transition'] = 'all ' + duration + 's ' + (ease || '');
+ }
+
+ wrappedCallback = function(){
+ var props = {};
+ props[prefix + 'transition'] = props[prefix + 'animation-name'] = 'none';
+ $(this).css(props);
+ callback && callback.call(this);
+ }
+ cachedAnimation.endEvent = endEvent;
+ cachedAnimation.callback = callback;
+ if (duration > 0) this.one(cachedAnimation.endEvent, cachedAnimation.callback);
+
+ setTimeout(function() {
+ that.css(cssProperties);
+ if (duration <= 0) setTimeout(function() {
+ that.each(function(){ wrappedCallback.call(this) });
+ }, 0);
+ }, 0);
+
+ return this;
+ };
+
+ testEl = null;
+})(Zepto);
+
+
+// Zepto.js
+// (c) 2010, 2011 Thomas Fuchs
+// Zepto.js may be freely distributed under the MIT license.
+
+(function($, undefined){
+ var document = window.document, docElem = document.documentElement,
+ origShow = $.fn.show, origHide = $.fn.hide, origToggle = $.fn.toggle,
+ speeds = { _default: 400, fast: 200, slow: 600 };
+
+ function translateSpeed(speed) {
+ return typeof speed == 'number' ? speed : (speeds[speed] || speeds._default);
+ }
+
+ function anim(el, speed, opacity, scale, callback) {
+ if (typeof speed == 'function' && !callback) callback = speed, speed = undefined;
+ var props = { opacity: opacity };
+ if (scale) {
+ if ($.fx.transforms3d) props.scale3d = scale + ',1';
+ else props.scale = scale;
+ el.css($.fx.cssPrefix + 'transform-origin', '0 0');
+ }
+ return el.anim(props, translateSpeed(speed) / 1000, null, callback);
+ }
+
+ function hide(el, speed, scale, callback) {
+ return anim(el, speed, 0, scale, function(){
+ origHide.call($(this));
+ callback && callback.call(this);
+ });
+ }
+
+ $.fn.show = function(speed, callback) {
+ origShow.call(this);
+ if (speed === undefined) speed = 0;
+ else this.css('opacity', 0);
+ return anim(this, speed, 1, '1,1', callback);
+ };
+
+ $.fn.hide = function(speed, callback) {
+ if (speed === undefined) return origHide.call(this);
+ else return hide(this, speed, '0,0', callback);
+ }
+
+ $.fn.toggle = function(speed, callback) {
+ if (speed === undefined || typeof speed == 'boolean') return origToggle.call(this, speed);
+ else return this[this.css('display') == 'none' ? 'show' : 'hide'](speed, callback);
+ };
+
+ $.fn.fadeTo = function(speed, opacity, callback) {
+ return anim(this, speed, opacity, null, callback);
+ };
+
+ $.fn.fadeIn = function(speed, callback) {
+ var target = this.css('opacity')
+ if (target > 0) this.css('opacity', 0)
+ else target = 1
+ return origShow.call(this).fadeTo(speed, target, callback);
+ };
+
+ $.fn.fadeOut = function(speed, callback) {
+ return hide(this, speed, null, callback);
+ };
+
+ $.fn.fadeToggle = function(speed, callback) {
+ var hidden = this.css('opacity') == 0 || this.css('display') == 'none';
+ return this[hidden ? 'fadeIn' : 'fadeOut'](speed, callback);
+ };
+
+ $.extend($.fx, {
+ speeds: speeds,
+ // feature detection for 3D transforms adapted from Modernizr
+ transforms3d: (function(props){
+ var ret = false;
+ $.each(props, function(i, prop){
+ if (docElem.style[prop] !== undefined) {
+ ret = i != 1 || webkitTransforms3d();
+ return false;
+ }
+ });
+ return ret;
+ })('perspectiveProperty WebkitPerspective MozPerspective OPerspective msPerspective'.split(' '))
+ });
+
+ function webkitTransforms3d() {
+ var ret, div = document.createElement('div'),
+ testEl = document.createElement('div'),
+ css = '@media (-webkit-transform-3d){#zeptotest{left:9px;position:absolute}}',
+ style = ['&shy;', '<style>', css, '</style>'].join('');
+
+ div.innerHTML += style;
+ testEl.id = 'zeptotest';
+ div.appendChild(testEl);
+ docElem.appendChild(div);
+ ret = testEl.offsetLeft === 9;
+ div.parentNode.removeChild(div);
+ return ret;
+ }
+})(Zepto);
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment