Committer: vkurkin
LJSV-1601: Users can't upload or change pic in wishlistU trunk/htdocs/js/jquery_fn.js
Modified: trunk/htdocs/js/jquery_fn.js =================================================================== --- trunk/htdocs/js/jquery_fn.js 2011-07-01 06:53:01 UTC (rev 19414) +++ trunk/htdocs/js/jquery_fn.js 2011-07-01 07:48:38 UTC (rev 19415) @@ -4,56 +4,50 @@ cache: false }); -jQuery.fn.ljAddContextualPopup = function() -{ - if (!window.ContextualPopup) return this; - - return this.each(function() - { +jQuery.fn.ljAddContextualPopup = function(){ + if(!window.ContextualPopup) return this; + + return this.each(function(){ ContextualPopup.searchAndAdd(this); }); -} +}; -jQuery.fn.hourglass = function(xhr) -{ +jQuery.fn.hourglass = function(xhr){ var hourglasses = []; - this.each(function() - { + this.each(function(){ // is complete or was aborted - if (xhr && (xhr.readyState == 0 || xhr.readyState == 4)) return; - - if (this.nodeType) { // node - + if(xhr && (xhr.readyState == 0 || xhr.readyState == 4)) return; + + if(this.nodeType){ // node + } else { // position from event var e = jQuery.event.fix(this), hourglass = new Hourglass(), offset = {}; - + // from keyboard - if (!e.clientX || !e.clientY) { + if(!e.clientX || !e.clientY){ offset = jQuery(e.target).offset(); } - + hourglass.init(); hourglass.hourglass_at(offset.left || e.pageX, offset.top || e.pageY); } - - hourglasses.push(hourglass) - - if (xhr) - { - jQuery(hourglass.ele).bind('ajaxComplete', function(event, request) - { - if (request == xhr) { + + hourglasses.push(hourglass); + + if(xhr){ + jQuery(hourglass.ele).bind('ajaxComplete', function(event, request){ + if(request == xhr){ hourglass.hide(); jQuery(hourglass.ele).unbind('ajaxComplete', arguments.callee); } }); } }); - + return hourglasses; -} +}; // not work for password jQuery.fn.placeholder = (function() @@ -106,65 +100,64 @@ })(); //this one is fields type agnostic but creates additional label elements, which need to be styled -jQuery.fn.labeledPlaceholder = function() { - function focus_action( input, label ) { +jQuery.fn.labeledPlaceholder = function(){ + function focus_action(input, label){ label.hide(); } - function blur_action( input, label ) { - if( input.val().length === 0 ) { + function blur_action(input, label){ + if(input.val().length === 0){ label.show(); } } - return this.each( function() { + return this.each(function(){ - if ('placeholder' in document.createElement('input') && this.tagName.toLowerCase() === "input" ) { + if('placeholder' in document.createElement('input') && this.tagName.toLowerCase() === "input"){ return; } - if ('placeholder' in document.createElement('textarea') && this.tagName.toLowerCase() === "textarea" ) { + if('placeholder' in document.createElement('textarea') && this.tagName.toLowerCase() === "textarea"){ return; } - var $this = jQuery( this ), - placeholder = $this.attr( 'placeholder' ); + var $this = jQuery(this), + placeholder = $this.attr('placeholder'); - $this.wrap( '<span class="placeholder-wrapper" />' ); + $this.wrap('<span class="placeholder-wrapper" />'); - if( !placeholder || placeholder.length === 0 ) { return; } + if(!placeholder || placeholder.length === 0){ + return; + } - var label = jQuery( "<label></label>") - .addClass('placeholder-label') - .mousedown(function( ev ) { - setTimeout( function() { - focus_action( $this, label ) - $this.focus(); - }, 0); - } ) - .html( placeholder ) - .insertBefore( $this ); - $this.focus( function() { focus_action( $this, label ) } ) - .blur( function() { blur_action( $this, label ) } ); + var label = jQuery("<label></label>").addClass('placeholder-label').mousedown(function(ev){ + setTimeout(function(){ + focus_action($this, label); + $this.focus(); + }, 0); + }).html(placeholder).insertBefore($this); + $this.focus(function(){ + focus_action($this, label) + }).blur(function(){ + blur_action($this, label) + }); - blur_action( $this, label ); + blur_action($this, label); - } ); -} + }); +}; -jQuery.fn.input = function(fn) { - return fn - ? this.each(function() { - var last_value = this.value; - jQuery(this).bind("input keyup paste", function(e) { - // e.originalEvent use from trigger - if (!e.originalEvent || this.value !== last_value) { - last_value = this.value; - fn.apply(this, arguments); - } - }) +jQuery.fn.input = function(fn){ + return fn ? this.each(function(){ + var last_value = this.value; + jQuery(this).bind("input keyup paste", function(e){ + // e.originalEvent use from trigger + if(!e.originalEvent || this.value !== last_value){ + last_value = this.value; + fn.apply(this, arguments); + } }) - : this.trigger("input"); -} + }) : this.trigger("input"); +}; // ctrl+enter send form jQuery.fn.disableEnterSubmit = function() { @@ -191,34 +184,98 @@ tab container: ul>li tab container current: ul>li.current */ -jQuery.fn.tabsChanger = function(container) -{ +jQuery.fn.tabsChanger = function(container){ var links = this.children("li").children("a"); - - if (container) { + + if(container){ container = jQuery(container); } else { // next sibling of links container = links.parent().parent().next(); } - - links.click(function(e) - { + + links.click(function(e){ var item = jQuery(this).parent(), index = item.index(), containers = container.children("li"); - if (containers[index]) { + if(containers[index]){ links.parent().removeClass("current"); item.addClass("current"); - containers.removeClass("current") - .eq(index) - .addClass("current"); + containers.removeClass("current").eq(index).addClass("current"); e.preventDefault(); } }); return this; -} +}; +/** jQuery overlay plugin + * After creation overlay visibility can be toggled with + * $( '#selector' ).overlay( 'show' ) and $( '#selector' ).overlay( 'hide' ) + */ +jQuery.fn.overlay = function(opts){ + var options = { + hideOnInit: true, + hideOnClick: true + }; + + function Overlay(layer, options){ + this.layer = jQuery(layer); + this.options = options; + this.updateState(this.options.hideOnInit); + this.bindEvents(); + } + + Overlay.prototype.bindEvents = function(){ + var overlay = this; + + if(this.options.hideOnClick){ + overlay.layer.mousedown(function(ev){ + ev.stopPropagation(); + }); + + jQuery(document).mousedown(function(ev){ + overlay.updateState(true); + ev.stopPropagation(); + }); + } + }; + + Overlay.prototype.updateState = function(hide){ + this.layerVisible = !hide; + if(this.layerVisible){ + this.layer.show(); + } else { + this.layer.hide(); + } + }; + + Overlay.prototype.proccessCommand = function (cmd){ + switch(cmd){ + case 'show' : + this.updateState(false); + break; + case 'hide' : + this.updateState(true); + break; + } + }; + + var cmd; + if(typeof opts === "string"){ + cmd = opts; + } + + return this.each(function(){ + if(!this.overlay){ + var o = jQuery.extend({}, options, opts || {}); + this.overlay = new Overlay(this, o); + } + + if(cmd.length > 0){ + this.overlay.proccessCommand(opts) + } + }); +}; \ No newline at end of file