setup: function( data, namespaces ) {
			if ( this.nodeName.toLowerCase() !== "form" ) {
				jQuery.event.add(this, "click.specialSubmit", function( e ) {
					var elem = e.target,
						type = elem.type;

					if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
						e.liveFired = undefined;
						return trigger( "submit", this, arguments );
					}
				});

				jQuery.event.add(this, "keypress.specialSubmit", function( e ) {
					var elem = e.target,
						type = elem.type;

					if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
						e.liveFired = undefined;
						return trigger( "submit", this, arguments );
					}
				});

			} else {
				return false;
			}
		},
	jQuery.fn[ name ] = function( type, data, fn ) {
		// Handle object literals
		if ( typeof type === "object" ) {
			for ( var key in type ) {
				this[ name ](key, data, type[key], fn);
			}
			return this;
		}

		if ( jQuery.isFunction( data ) || data === false ) {
			fn = data;
			data = undefined;
		}

		var handler = name === "one" ? jQuery.proxy( fn, function( event ) {
			jQuery( this ).unbind( event, handler );
			return fn.apply( this, arguments );
		}) : fn;

		if ( type === "unload" && name !== "one" ) {
			this.one( type, data, fn );

		} else {
			for ( var i = 0, l = this.length; i < l; i++ ) {
				jQuery.event.add( this[i], type, handler, data );
			}
		}

		return this;
	};
	jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) {
		var type, i = 0, match, namespaces, preType,
			selector = origSelector || this.selector,
			context = origSelector ? this : jQuery( this.context );

		if ( typeof types === "object" && !types.preventDefault ) {
			for ( var key in types ) {
				context[ name ]( key, data, types[key], selector );
			}

			return this;
		}

		if ( jQuery.isFunction( data ) ) {
			fn = data;
			data = undefined;
		}

		types = (types || "").split(" ");

		while ( (type = types[ i++ ]) != null ) {
			match = rnamespaces.exec( type );
			namespaces = "";

			if ( match )  {
				namespaces = match[0];
				type = type.replace( rnamespaces, "" );
			}

			if ( type === "hover" ) {
				types.push( "mouseenter" + namespaces, "mouseleave" + namespaces );
				continue;
			}

			preType = type;

			if ( type === "focus" || type === "blur" ) {
				types.push( liveMap[ type ] + namespaces );
				type = type + namespaces;

			} else {
				type = (liveMap[ type ] || type) + namespaces;
			}

			if ( name === "live" ) {
				// bind live handler
				for ( var j = 0, l = context.length; j < l; j++ ) {
					jQuery.event.add( context[j], "live." + liveConvert( type, selector ),
						{ data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } );
				}

			} else {
				// unbind live handler
				context.unbind( "live." + liveConvert( type, selector ), fn );
			}
		}

		return this;
	};
Example #4
0
 bind: function (ev, cb) {
     if (this.bind && this.bind !== can.bind) {
         this.bind(ev, cb);
     } else if (isBindableElement(this)) {
         $.event.add(this, ev, cb);
     } else {
         can.addEvent.call(this, ev, cb);
     }
     return this;
 },
		setup: function( data, namespaces ) {
			if ( this.type === "file" ) {
				return false;
			}

			for ( var type in changeFilters ) {
				jQuery.event.add( this, type + ".specialChange", changeFilters[type] );
			}

			return rformElems.test( this.nodeName );
		},
			setup: function() {
				var elem = this;

				// The document needs no shimming; must be !== for oldIE
				if ( elem !== document ) {
					jQuery.event.add( document, name + "." + jQuery.guid, function() {
						jQuery.event.trigger( name, null, elem, true );
					});
					jQuery._data( this, name, jQuery.guid++ );
				}
				return false;
			},
	ret.each(function() {
		if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
			return;
		}

		var oldData = jQuery.data( orig[i++] ),
			curData = jQuery.data( this, oldData ),
			events = oldData && oldData.events;

		if ( events ) {
			delete curData.handle;
			curData.events = {};

			for ( var type in events ) {
				for ( var handler in events[ type ] ) {
					jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
				}
			}
		}
	});
Example #8
0
    LightBox.prototype.openFrame = function (url, options) {
        this.options = _.extend({}, this.options, options);
        options = this.options;

        var bodyElement = $(global.document.body);
        var lightBoxElement = $(_.template(TEMPLATE)({
            prefix: CLASS_PREFIX,
            url: url,
            spinner: options && SPINNERS[options.spinner] || _.values(SPINNERS)[0]
        }));
        var lightBoxOverlayElement = lightBoxElement.find('.' + CLASS_PREFIX + '-overlay');
        var lightBoxContentElement = lightBoxElement.find('.' + CLASS_PREFIX + '-content');
        var lightBoxIframeElement = lightBoxContentElement.find('.' + CLASS_PREFIX + '-content-iframe');
        var lightBoxSpinnerElement = lightBoxElement.find('.' + CLASS_PREFIX + '-spinner');

        var psDimensions = {
            width: '0px',
            height: '0px'
        };

        lightBoxElement.css({
            zIndex: options.zIndex
        });

        lightBoxOverlayElement.css({
            background: options.overlayBackground,
            opacity: options.overlayOpacity
        });

        lightBoxContentElement.css({
            margin: options.contentMargin,
            background: options.contentBackground
        });

        if (options.spinnerColor) {
            lightBoxSpinnerElement.find('path').css({
                fill: options.spinnerColor
            });
        }

        if (options.closeByClick) {
            lightBoxOverlayElement.on('click', _.bind(function () {
                this.closeFrame();
            }, this));
        }

        bodyElement.append(lightBoxElement);

        if (options.closeByKeyboard) {
            bodyElement.on('keyup' + EVENT_NAMESPACE, _.bind(function (event) {
                if (event.which == 27) {
                    this.closeFrame();
                }
            }, this));
        }

        var showContent = _.bind(function () {
            showContent = _.noop;
            hideSpinner(options);
            lightBoxContentElement.removeClass(CLASS_PREFIX + '-content__hidden');
            this.triggerEvent('load');
        }, this);

        var lightBoxResize = function () {
            lightBoxContentElement.css({
                top: 0,
                left: 0,
                width: options.width ? options.width : psDimensions.width,
                height: options.height ? options.height : psDimensions.height
            });

            var containerWidth = lightBoxElement.get(0).clientWidth,
                containerHeight = lightBoxElement.get(0).clientHeight;
            var contentWidth = lightBoxContentElement.outerWidth(true),
                contentHeight = lightBoxContentElement.outerHeight(true);
            var horMargin = contentWidth - lightBoxContentElement.outerWidth(),
                vertMargin = contentHeight - lightBoxContentElement.outerHeight();
            var horDiff = containerWidth - contentWidth,
                vertDiff = containerHeight - contentHeight;

            if (horDiff < 0) {
                lightBoxContentElement.width(containerWidth - horMargin);
            } else {
                lightBoxContentElement.css('left', Math.round(horDiff / 2));
            }

            if (vertDiff < 0) {
                lightBoxContentElement.height(containerHeight - vertMargin);
            } else {
                lightBoxContentElement.css('top', Math.round(vertDiff / 2));
            }
        };

        var bodyStyles;
        var hideScrollbar = _.bind(function () {
            bodyStyles = _.object(_.map(['overflow', 'paddingRight'], function (key) {
                return [key, bodyElement.css(key)];
            }));

            if (global.window.innerWidth > bodyElement.outerWidth(true)) {
                var bodyPad = parseInt((bodyElement.css('paddingRight') || 0), 10);
                bodyElement.css({
                    'paddingRight': bodyPad + this.measureScrollbar(),
                    'overflow': 'hidden'
                });
            }
        }, this);

        var resetScrollbar = function () {
            bodyElement.css(bodyStyles || {});
        };

        var showSpinner = function () {
            lightBoxSpinnerElement.show();
        };

        var hideSpinner = function () {
            lightBoxSpinnerElement.hide();
        };

        var loadTimer;
        lightBoxIframeElement.on('load', _.bind(function (event) {
            var timeout = !options.width || !options.height ? 30000 : 1000; //30000 if psDimensions will not arrive
            loadTimer = global.setTimeout(function () {
                showContent();
            }, timeout);
            $(event.target).off(event);
        }, this));

        var iframeWindow = lightBoxIframeElement.get(0).contentWindow || lightBoxIframeElement.get(0);

        // Cross-window communication
        this.message = new PostMessage(iframeWindow);
        if (options.width && options.height) {
            this.message.on('dimensions', function () {
                showContent();
            });
        } else {
            this.message.on('dimensions', function (event, data) {
                if (data.dimensions) {
                    psDimensions = _.object(_.map(['width', 'height'], function (dim) {
                        return [dim, Math.max(MIN_PS_DIMENSIONS[dim] || 0, data.dimensions[dim] || 0) + 'px'];
                    }));

                    lightBoxResize();
                }
                showContent();
            });
        }
        this.message.on('widget-detection', _.bind(function () {
            this.message.send('widget-detected', {version: version, lightBoxOptions: options});
        }, this));
        this.message.on('widget-close', _.bind(function () {
            this.closeFrame();
        }, this));
        this.message.on('status', _.bind(function (event, data) {
            this.triggerEvent('status', data);
        }, this));

        // Resize
        $.event.add(global.window, 'resize' + EVENT_NAMESPACE, lightBoxResize);

        // Clean up after close
        this.on('close', _.bind(function (event) {
            this.message.off();
            bodyElement.off(EVENT_NAMESPACE);
            $.event.remove(global.window, 'resize' + EVENT_NAMESPACE, lightBoxResize);
            lightBoxElement.remove();
            resetScrollbar();
            $(event.target).off(event);
        }, this));

        if (options.width && options.height) {
            lightBoxResize();
        }
        showSpinner();
        hideScrollbar();

        this.triggerEvent('open');
    };
		setup: function( data ) {
			jQuery.event.add( this, fix, data && data.selector ? delegate : withinElement, orig );
		},
			add: function( handleObj ) {
				jQuery.event.add( this,
					liveConvert( handleObj.origType, handleObj.selector ),
					jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) );
			},