var OwUtils = function(){ var langs = {}; var messageTime = 10000; var $messageCont = $('
'); var events = {}; $(function(){ $messageCont.appendTo(document.body); }); this.message = function( message, type, paramTime ){ var $messageNode = $('').appendTo($messageCont); if( paramTime == undefined ){ paramTime = messageTime; } $messageNode.fadeIn(1000, function(){ window.setTimeout( function(){ $messageNode.fadeOut(1000, function(){ $messageNode.remove(); } ); }, paramTime ); } ); } this.error = function( message ){ this.message(message, 'error'); }; this.warning = function( message ){ this.message(message, 'warning'); }; this.info = function( message ){ this.message(message, 'info'); }; this.addScriptFiles = function( urlList, callback ){ var scripts = $('script'); //TODO: Sardar require once check /* var docScripts = []; for( var i = 0; i < scripts.length; i++ ){ docScripts[i] = $(scripts[i]).attr('src'); }*/ if( urlList && urlList.length > 0 ){ var recursiveInclude = function(urlList, i){ if( (i+1) == urlList.length ) { $.getScript(urlList[i], callback); return; } $.getScript(urlList[i], function(){recursiveInclude(urlList, ++i);}); } recursiveInclude(urlList, 0); }else{ callback.apply(this); } }; /*this.addScriptFile = function( url, callback ){ var scripts = $('script'); for( var i = 0; i < scripts.length; i++ ){ if( $(scripts[i]).attr('src') == $.trim(url) ){ return; } } $.getScript(url, callback); //$('head').append( $('') ); };*/ this.addScript = function( script ){ if (!script) { return false; } (new Function(script))(); }, this.addCssFile = function( url ) { $('head').append($('')); }, this.addCss = function( css ){ $('head').append($('')); } this.getLanguageText = function(prefix, key, assignedVars) { if ( langs[prefix] === undefined ) { return prefix + '+' + key; } if ( langs[prefix][key] === undefined ) { return prefix + '+' + key; } var langValue = langs[prefix][key]; if ( assignedVars ) { for( varName in assignedVars ) { langValue = langValue.replace('{$'+varName+'}', assignedVars[varName]); } } return langValue; }; this.registerLanguageKey = function(prefix, key, value) { if ( langs[prefix] === undefined ) { langs[prefix] = {}; } langs[prefix][key] = value; }; this.inProgressNode = function(node) { return $(node).inprogress(); } this.activateNode = function(node) { return $(node).activate(); }; this.showUsers = function(userIds, title) { title = title || OW.getLanguageText('base', 'ajax_floatbox_users_title'); this.ajaxFloatBox('BASE_CMP_FloatboxUserList', [userIds], {iconClass: "ow_ic_user", title: title, width: 450}); }, this.getActiveFloatBox = function getFloatBox() { if ( typeof window.OWActiveFloatBox == 'undefined' ) { return false; } return window.OWActiveFloatBox; }, /** * @param string cmpClass * * Cmp class params or targetNode selector or targetNod HtmlElement or ready callback * @param array|string|HTMLElement|jQuery|function p1 * * Options or targetNode selector or targetNod HtmlElement or ready callback * @param object|string|HTMLElement|jQuery|function p2 */ this.loadComponent = function( cmpClass, p1, p2 ) { function isNode( node ) { return typeof node === 'string' || node.jquery || node.nodeType } var params = [], options = {}; if ( isNode(p2) ) { options.place = $(p2); } else if ( $.isPlainObject(p2) ) { options = p2; } else if ( $.isFunction(p2) ) { options.onReady = p2; } if ( isNode(p1) ) { options.place = $(p1); } else if ( $.isArray(p1) || $.isPlainObject(p1) ) { params = p1; } else if ( $.isFunction(p1) ) { options.onReady = p1; } options = $.extend({}, { place: false, onLoad: function( r ){}, onReady: function( r ){}, onError: function( r ){}, onComplete: function( r ){}, addClass: '' }, options); var rsp = this.ajaxComponentLoaderRsp, jsonParams = JSON.stringify(params), $preloader = false; if ( options.place ) { $preloader = $('
'); $(options.place).html($preloader); } var ajaxOptions = { url: rsp + '?cmpClass=' + cmpClass + '&r=' + Math.random(), dataType: 'json', type: 'POST', data: {params: jsonParams}, error: function(r) { options.onError(r); }, complete: function(r) { options.onComplete(r); }, success: function(markup) { var contentHtml = markup.content, $contentHtml = $(contentHtml); if ( !$contentHtml.length ) { contentHtml = '' + contentHtml + ''; $contentHtml = $(contentHtml) } if ( $preloader ) { $preloader.replaceWith($contentHtml); } options.onReady($contentHtml); if (markup.styleSheets) { $.each(markup.styleSheets, function(i, o) { OW.addCssFile(o); }); } if (markup.styleDeclarations) { OW.addCss(markup.styleDeclarations); } if (markup.scriptFiles) { OW.addScriptFiles(markup.scriptFiles, function() { if (markup.onloadScript) { OW.addScript(markup.onloadScript); options.onLoad(); } }); } else { if (markup.onloadScript) { OW.addScript(markup.onloadScript); } options.onLoad(); } } }; $.ajax(ajaxOptions); }, this.ajaxFloatBox = function(cmpClass, params, options) { params = params || []; options = options || {}; options = $.extend({}, { title: '', width: false, height: false, iconClass: false }, options); var self = this, $place = $('
'); var floatBox = new OW_FloatBox({ $title: options.title, $contents: $place, width: options.width, height: options.height, icon_class: options.iconClass }); this.loadComponent(cmpClass, params, { place: $place, addClass: 'ow_ajax_floatbox_preloader', onReady: function() { floatBox.fitWindow(); } }) return floatBox; }; this.bind = function(type, func) { if (events[type] == undefined) { events[type] = []; } events[type].push(func); }; this.trigger = function(type, params, applyObject) { if (events[type] == undefined) { return false; } applyObject = applyObject || this; params = params || []; if ( !$.isArray(params) ) { params = [params]; } for (var i = 0, func; func = events[type][i]; i++) { if (func.apply(applyObject, params) === false) { return false; } } return true; }; this.unbind = function( type ) { if (events[type] == undefined) { return false; } events[type] = []; }; this.editLanguageKey = function( prefix, key, success ) { var fb = OW.ajaxFloatBox("BASE_CMP_LanguageValueEdit", [prefix, key, true], {width: 520, title: this.getLanguageText('admin', 'edit_language')}); OW.bind("admin.language_key_edit_success", function( e ) { fb.close(); OW.unbind("admin.language_key_edit_success"); success(e); }); }; this.bindAutoClicks = function(context){ var autoClicks; if ( context ) { autoClicks = $('.form_auto_click', context); } else { autoClicks = $('.form_auto_click'); } $.each(autoClicks, function(i,o){ var context = $(o); $('textarea.invitation', context) .bind('focus.auto_click', {context:context}, function(e){ $('.ow_submit_auto_click', e.data.context).show(); $(this).unbind('focus.auto_click') } );/* .bind('keyup.auto_click', function(){ if( $(this).val() != '' ){ $(this).unbind('focus.auto_click').unbind('keyup.auto_click').unbind('mouseup.auto_click').unbind('blur.auto_click'); } } ) .bind('mouseup.auto_click', function(){ if( $(this).val() != '' ){ $(this).unbind('focus.auto_click').unbind('keyup.auto_click').unbind('mouseup.auto_click').unbind('blur.auto_click'); } } ) .bind('blur.auto_click', {context:context}, function(e){ if( $(this).hasClass('invitation') ){ $('.ow_submit_auto_click', e.data.context).hide(); } } );*/ }); }; this.initWidgetMenu = function( items ){ var $toolbarCont = null; var $contex = null; var condIds = []; var linkIds = []; $.each( items, function(key, value){ if( $toolbarCont === null ){ $contex = $('#'+value['contId']).closest('.ow_box, .ow_box_empty'); $toolbarCont = $('.ow_box_toolbar_cont', $contex); } condIds.push('#'+value['contId']); linkIds.push('#'+value['id']); } ); var contIdSelector = $(condIds.join(',')); var linkIdSelector = $(linkIds.join(',')); $.each( items, function(key, value){ $('#'+value['id']).bind('click', {value:value}, function(e){ contIdSelector.hide(); $('#'+e.data.value.contId).show(); linkIdSelector.removeClass('active'); $(this).addClass('active'); if( e.data.value.toolbarId != undefined ){ if( e.data.value.toolbarId ){ if( $toolbarCont.length === 0 ){ $toolbarCont = $('
'); $contex.append($toolbarCont); } $toolbarCont.html($('#'+e.data.value.toolbarId).html()); } else{ if( $toolbarCont.length !== 0 ){ $toolbarCont.remove(); $toolbarCont = []; } } } } ); } ); }; this.showTip = function( $el, params ){ params = params || {}; params = $.extend({side:'top', show:null, width:null, timeout:0, offset:5, hideEvent: null}, params); var showTipN = function(){ var $rootEl = $el.data('owTip'); var coords = $el.offset(); switch( params.side ) { case 'top': var left = coords.left + $el.outerWidth()/2 - $rootEl.outerWidth()/2; var top = coords.top - $rootEl.outerHeight() - params.offset; break; case 'bot': var left = coords.left + $el.outerWidth()/2 - $rootEl.outerWidth()/2; var top = coords.top + $el.outerHeight() + params.offset; break; case 'right': var left = coords.left + $el.outerWidth() + params.offset; var top = coords.top + $el.outerHeight()/2 - $rootEl.outerHeight()/2; break; case 'left': var left = coords.left - $rootEl.outerWidth() - params.offset; var top = coords.top + $el.outerHeight()/2 - $rootEl.outerHeight()/2; break; default: return; } $rootEl.css({left:left, top:top}); setTimeout( function(){ $el.data('owTip').show( 1, function(){ if( params.hideEvent ){ $el.bind(params.hideEvent, function(){OW.hideTip($el)}); } $el.data('owTipStatus', true); if( $el.data('owTipHide') == true ){ OW.hideTip($el); } } ); }, params.timeout); } if( $el.data('owTip') ){ if( $el.data('owTipStatus') == true ){ return; } showTipN(); return; } var showContent; if( params.show != null ){ showContent = ( typeof(params.show) == 'string' ? params.show : params.show.html() ); } else{ if( !$el.attr('title') ){ return; } showContent = ''+$el.attr('title')+''; } var $rootEl = $('
').css({display:'none'}).append($('
'+ showContent +'
')); if( params.width != null ){ $rootEl.css({width:params.width}); } $('body').append($rootEl); $el.removeAttr('title'); $el.data('owTip', $rootEl); showTipN(); }; this.hideTip = function( $el ){ if( $el.data('owTip') && $el.data('owTipStatus') == true ){ $el.data('owTip').hide(); $el.data('owTipStatus', false); $el.data('owTipHide', false); } }; this.resizeImg = function($context, params){ if( !params.width ){ return; } $( 'img', $context ).each(function(){ $(this).load( function(){ if( $(this).data('imgResized') != true){ var $fakeImg = $(this).clone(); $fakeImg.css({width:'auto',height:'auto',visibility:'hidden',position:'absolute',left:'-9999px'}).removeAttr('width').removeAttr('height'); $(document.body).append ($fakeImg); var self = this; $fakeImg.load(function(){ var width = $(this).width(); if( width < params.width ){ $(self).css({width:'auto', height:'auto'}); } else if( $(self).width() >= params.width ){ $(self).css({width:params.width, height:'auto'}); } $(self).data('imgResized', true); $(this).remove(); }); } } ); }); }; this.showImageInFloatBox = function( src ){ var floatBox = new OW_FloatBox({$title:' ', icon_class:'ow_ic_picture', width:350,$contents:'
'}); var $fakeImg = $(''); $fakeImg.css({visibility:'hidden',position:'absolute',left:'-9999px'}); $(document.body).append ($fakeImg); $fakeImg.load(function(){ var width = $fakeImg.width(); var height = $fakeImg.height(); if( width > 340 || height > 220 ){ if( width > 800 ){ $fakeImg.css({width:'800px', height:'auto'}); } else if( $fakeImg.height > 600 ){ $fakeImg.css({height:'600px', width:'auto'}); } width = $fakeImg.width(); height = $fakeImg.height(); $('.ow_image_float_box', floatBox.$container).removeClass('ow_preloader_content'); floatBox.fitWindow({ "width": width + 20, "height": height + 80, "animate": true, "complete": function() { $('.ow_image_float_box', floatBox.$container).css({height:'auto', width:'auto'}).append($fakeImg); } }); } else{ $('.ow_image_float_box', floatBox.$container).removeClass('ow_preloader_content').append($fakeImg); } $fakeImg.css({visibility:'visible',position:'static',left:0}); }); } } //Enable / Disable node jQuery.fn.extend({ inprogress: function() { this.each(function() { var $this = jQuery(this).addClass('ow_inprogress'); this.disabled = true; if ( this.tagName != 'INPUT' && this.tagName != 'TEXTAREA' && this.tagName != 'SELECT' ) { this.jQuery_disabled_clone = $this.clone().removeAttr('id').removeAttr('onclick').get(0); $this.hide() .bind('unload', function(){ $this.activate(); }) .after(this.jQuery_disabled_clone); } }); return this; }, activate: function() { this.each(function() { var $this = jQuery(this).removeClass('ow_inprogress'); this.disabled = false; if ( this.jQuery_disabled_clone ) { jQuery(this.jQuery_disabled_clone).remove(); this.jQuery_disabled_clone = null; jQuery(this) .unbind('unload', function(){ $this.activate(); }) .show(); } }); return this; } }); window.OW = new OwUtils(); function lg(o){ console.log(o); } $( //8aa: resize fullsize images to fit to it's parendt width function (){ if(typeof($) == 'undefined') return; $('.fullsize-image').hide(); var node = $('.fullsize-image')[0]; while( node = $(node).parent()[0]){ if( node.tagName != 'DIV'){ continue; } if($('.fullsize-image').width() > parseInt($(node).innerWidth())) $('.fullsize-image').width( (parseInt($(node).innerWidth()) - 10) + 'px' ); $('.fullsize-image').show(); break; } } ); /** * Float box constructor. * * @param string|jQuery $title * @param string|jQuery $contents * @param jQuery $controls * @param object position {top, left} = center * @param integer width = auto * @param integer height = auto */ function OW_FloatBox(options) { var fl_box = this; var fb_class; this.parentBox = OW.getActiveFloatBox(); this.events = {close: [], show: []}; if (typeof document.body.style.maxHeight === 'undefined') { //if IE 6 jQuery('body').css({height: '100%', width: '100%'}); jQuery('html').css('overflow', 'hidden'); if (document.getElementById('floatbox_HideSelect') === null) { //iframe to hide select elements in ie6 jQuery('body').append('
'); fb_class = OW_FloatBox.detectMacXFF() ? 'floatbox_overlayMacFFBGHack' : 'floatbox_overlayBG'; jQuery('#floatbox_overlay').addClass(fb_class); } } else { //all others if (document.getElementById('floatbox_overlay') === null) { jQuery('body').append('
'); fb_class = OW_FloatBox.detectMacXFF() ? 'floatbox_overlayMacFFBGHack' : 'floatbox_overlayBG'; jQuery('#floatbox_overlay').addClass(fb_class).click(function(){ fl_box.close(); }); } } jQuery('body').addClass('floatbox_nooverflow'); var activeCanvas = jQuery('.floatbox_canvas_active'); this.$canvas = jQuery('.floatbox_canvas', '#floatbox_prototype').clone().appendTo(document.body); activeCanvas.removeClass('floatbox_canvas_active'); this.$canvas.addClass('floatbox_canvas_active'); if (this.parentBox) { this.$canvas.addClass('floatbox_canvas_sub'); this.parentBox.bind('close', function() { fl_box.close(); }); } this.$canvas.click(function(e){ if ( $(e.target).is(this) ) { fl_box.close(); } }); this.$container = jQuery('.floatbox_container', '#floatbox_prototype').clone().hide().appendTo('body'); if (typeof options.$title == 'string') { options.$title = jQuery(''+options.$title+''); } else { this.$title_parent = options.$title.parent(); } this.$header = jQuery('.floatbox_header', this.$container); var $fbTitle = jQuery('.floatbox_cap', this.$header) .find('.floatbox_title') .append(options.$title); if (typeof options.icon_class == 'string') { $fbTitle.addClass(options.icon_class); } this.$body = jQuery('.floatbox_body', this.$container); if (typeof options.$contents == 'string') { var $contentsNode = jQuery(options.$contents); if ( !$contentsNode.length ) { $contentsNode = jQuery('' + options.$contents + ''); } options.$contents = jQuery($contentsNode); } else { this.$contents_parent = options.$contents.parent(); } this.$body.append(options.$contents); this.$bottom = jQuery('.floatbox_bottom', this.$container); if (options.$controls) { if (typeof options.$controls == 'string') { options.$controls = jQuery(''+options.$controls+''); } else { this.$controls_parent = options.$controls.parent(); } this.$bottom.append(options.$controls); } if (options.width) this.$container.css("width", options.width); if (options.height) this.$body.css("height", options.height); jQuery('.close', this.$header) .one('click', function() { fl_box.close(); return false; }); this.esc_listener = function(event) { if (event.keyCode == 27) { fl_box.close(); return false; } return true; } jQuery(document).bind('keydown', this.esc_listener); this.$container .fadeTo(1, 0.1, function() { var $this = jQuery(this); $this.css('display', 'block'); if (options.position) { if (options.position.left) $this.css('margin-left', options.position.left); if (options.position.top) $this.css('margin-top', options.position.top); } else { fl_box.fitWindow(); var position = { top:((jQuery(window).height()/10) - ($this.height()/10))/*.ceil()*/, left:((jQuery(window).width()/2) - ($this.width()/2))/*.ceil()*/ }; $this.css(position); } // trigger on show event fl_box.trigger('show'); $this.fadeTo(100, 1); }); window.OWActiveFloatBox = this; } OW_FloatBox.version = 2; OW_FloatBox.detectMacXFF = function() { var userAgent = navigator.userAgent.toLowerCase(); return (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1); } OW_FloatBox.prototype = { fitWindow: function( params ) { params = params || {}; params = $.extend({ "width": null, "height": null, "animate": false, "complete": function() {} }, params); var css = {}; css.marginBottom = ( jQuery(window).height() / 2 ) - ( (params.height || this.$container.height()) /2 + 100 ); css.marginBottom = css.marginBottom < 20 ? 20 : css.marginBottom; if ( params.width ) { css.width = params.width; } if ( params.height ) { css.height = params.height; } if ( params.animate ) { this.$container.animate(css, 'fast', function() { params.complete.apply(this); }); } else { this.$container.css(css); params.complete.apply(this); } }, setContent: function( $contents ) { this.$body.html($contents); }, close: function() { if (this.trigger('close') === false) { return false; } jQuery(document).unbind('keydown', this.esc_listener); if (this.$title_parent && this.$title_parent.length) { this.$title_parent.append( jQuery('.floatbox_title', this.$header).children() ); } if (this.$contents_parent && this.$contents_parent.length) { this.$contents_parent.append(this.$body.children()); } if (this.$controls_parent && this.$controls_parent.length) { this.$controls_parent.append(this.$bottom.children()); } this.$container.remove(); if (jQuery('.floatbox_canvas:visible').length === 0) { jQuery('html, body').removeClass('floatbox_nooverflow'); jQuery('#floatbox_overlay, #floatbox_HideSelect').remove(); } window.OWActiveFloatBox = this.parentBox; return true; }, bind: function(type, func) { if (this.events[type] == undefined) { throw 'form error: unknown event type "'+type+'"'; } this.events[type].push(func); }, trigger: function(type, params) { if (this.events[type] == undefined) { throw 'form error: unknown event type "'+type+'"'; } params = params || []; for (var i = 0, func; func = this.events[type][i]; i++) { if (func.apply(this, params) === false) { return false; } } return true; } } /* OW Forms */ var OwFormElement = function( id, name ){ this.id = id; this.name = name; this.input = document.getElementById(id); this.validators = []; } OwFormElement.prototype = { validate: function(){ var error = false; try{ for( var i = 0; i < this.validators.length; i++ ){ this.validators[i].validate(this.getValue()); } }catch (e) { error = true; this.showError(e); } if( error ){ throw e; } }, addValidator: function( validator ){ this.validators.push(validator); }, getValue: function(){ return $(this.input).val(); }, setValue: function( value ){ $(this.input).val(value); }, resetValue: function(){ $(this.input).val(''); }, showError: function( errorMessage ){ $('#'+this.id+'_error').append(errorMessage).fadeIn(50); }, removeErrors: function(){ $('#'+this.id+'_error').empty().fadeOut(50); } } var OwForm = function( formId, formName ){ this.id = formId; this.name = formName; this.form = document.getElementById(formId); this.elements = {}; this.ajax = false; this.ajaxDataType = 'json'; var actionUrl = $(this.form).attr('action'); this.actionUrl = ( !actionUrl ? location.href : actionUrl ); this.reset = true; this.showErrors = true; this.events = { submit:[], success:[] } }; OwForm.prototype = { addElement: function( element ){ this.elements[element.name] = element; }, getElement: function( name ){ if( this.elements[name] === undefined ){ return null; } return this.elements[name]; }, validate: function(){ var error = false; var element = null; var errorMessage; $.each( this.elements, function(index, data){ try{ data.validate(); }catch (e){ error = true; if( element == null ){ element = data; errorMessage = e; } } } ); if(error){ element.input.focus(); if( this.validateErrorMessage ){ throw this.validateErrorMessage; }else{ throw errorMessage; } } }, bind: function( event, fnc ){ this.events[event].push(fnc); }, sucess: function( fnc ){ this.bind('success', fnc); }, submit: function( fnc ){ this.bind('submit', fnc); }, trigger: function( event, data ){ if( this.events[event] == undefined || this.events[event].length == 0 ){ return; } for( var i = 0; i < this.events[event].length; i++ ){ this.events[event][i].apply(this.form, [data]); } }, getValues: function(){ var values = {}; $.each(this.elements, function( index, data ){ values[data.name] = data.getValue(); } ); return values; }, setValues: function( values ){ var self = this; $.each( values, function( index, data ){ if(self.elements[index]){ self.elements[index].setValue(data); } } ); }, resetForm: function(){ $.each( this.elements, function( index, data ){ data.resetValue(); } ); }, removeErrors: function(){ $.each( this.elements, function( index, data ){ data.removeErrors(); } ); }, submitForm: function(){ var self = this; this.removeErrors(); try{ this.validate(); }catch(e){ if( this.showErrors ){ OW.error(e); } return false; } var buttons = $('input[type=button], input[type=submit], button', '#' + this.id).addClass('ow_inprogress'); if( this.ajax ){ OW.inProgressNode(buttons); var dataToSend = this.getValues(); var postString = ''; $.each( dataToSend, function( index, data ){ if( $.isArray(data) ){ for( var i = 0; i < data.length; i++ ){ postString += index + '[]=' + encodeURIComponent(data[i]) + '&'; } } else{ postString += index + '=' + encodeURIComponent(data) + '&'; } } ); $.ajax({ type: 'post', url: this.actionUrl, data: postString, dataType: self.ajaxDataType, success : function(data){ if(self.reset){ self.resetForm(); } self.trigger('success', data); }, error : function( XMLHttpRequest, textStatus, errorThrown ){ OW.error(textStatus); throw textStatus; }, complete: function(){ OW.activateNode(buttons); } }); return false; } $.each(this.elements, function( i, o ){ if( $(o.input).hasClass('invitation') ){ $(o.input).attr('disabled', 'disabled'); } } ); return true; } } // custom fields var addInvitationBeh = function( formElement, invitationString ){ formElement.invitationString = invitationString; formElement.getValue = function(){ var val = $(this.input).val(); if( val != '' && val != this.invitationString ){ $(this.input).removeClass('invitation'); return val; } else{ return ''; } }; $(formElement.input ).bind('focus.invitation', {formElement:formElement}, function(e){ el = $(this); el.removeClass('invitation'); if( el.val() == '' || el.val() == e.data.formElement.invitationString){ el.val(''); //hotfix for media panel if( 'htmlarea' in el.get(0) ){ el.unbind('focus.invitation').unbind('blur.invitation'); el.get(0).htmlarea(); el.get(0).htmlareaFocus(); } } else{ el.unbind('focus.invitation').unbind('blur.invitation'); } } )/*.bind('blur.invitation', {formElement:formElement}, function(e){ el = $(this); if( el.val() == '' || el.val() == e.data.formElement.invitationString){ el.addClass('invitation'); el.val(e.data.formElement.invitationString); } else{ el.unbind('focus.invitation').unbind('blur.invitation'); } } );*/ } var OwTextField = function( id, name, invitationString ){ var formElement = new OwFormElement(id, name); if( invitationString ){ addInvitationBeh(formElement, invitationString); } return formElement; } var OwTextArea = function( id, name, invitationString ){ var formElement = new OwFormElement(id, name); if( invitationString ){ addInvitationBeh(formElement, invitationString); } return formElement; } var OwWysiwyg = function( id, name, invitationString ){ var formElement = new OwFormElement(id, name); formElement.input.focus = function(){this.htmlareaFocus();}; addInvitationBeh(formElement, invitationString); formElement.resetValue = function(){$(this.input).val('');$(this.input).keyup();}; formElement.getValue = function(){ var val = $(this.input).val(); if( val != '' && val != '
' && val != '

' && val != this.invitationString ){ $(this.input).removeClass('invitation'); return val; } else{ return ''; } }; return formElement; } var OwRadioField = function( id, name ){ var formElement = new OwFormElement(id, name); formElement.getValue = function(){ var value = $("input[name='"+this.name +"']:checked", $(this.input.form)).val(); return ( value == undefined ? '' : value ); }; formElement.resetValue = function(){ $("input[name='"+this.name +"']:checked", $(this.input.form)).removeAttr('checked'); }; formElement.setValue = function(value){ $("input[name='"+ this.name +"'][value='"+value+"']", $(this.input.form)).attr('checked', 'checked'); }; return formElement; } var OwCheckboxGroup = function( id, name ){ var formElement = new OwFormElement(id, name); formElement.getValue = function(){ var $inputs = $("input[name='"+ this.name +"[]']:checked", $(this.input.form)); var values = []; $.each( $inputs, function(index, data){ if( this.checked == true ){ values.push($(this).val()); } } ); return values; }; formElement.resetValue = function(){ var $inputs = $("input[name='"+ this.name +"[]']:checked", $(this.input.form)); $.each( $inputs, function(index, data){ $(this).removeAttr('checked'); } ); }; formElement.setValue = function(value){ for( var i = 0; i < value.length; i++ ){ $("input[name='"+ this.name +"[]'][value='"+value[i]+"']", $(this.input.form)).attr('checked', 'checked'); } }; return formElement; } var OwCheckboxField = function( id, name ){ var formElement = new OwFormElement(id, name); formElement.getValue = function(){ var $input = $("input[name='"+this.name+"']:checked", $(this.input.form)); if( $input.length == 0 ){ return ''; } return 'on'; }; formElement.setValue = function(value){ var $input = $("input[name='"+this.name+"']:checked", $(this.input.form)); if( value ){ $input.attr('checked', 'checked'); } else{ $input.removeAttr('checked'); } }; formElement.resetValue = function(){ var $input = $("input[name='"+this.name+"']:checked", $(this.input.form)); $input.removeAttr('checked'); }; return formElement; } var OwRange = function( id, name ){ var formElement = new OwFormElement(id, name); formElement.getValue = function(){ var $inputFrom = $("select[name='"+ this.name +"[from]']"); var $inputTo = $("select[name='"+ this.name +"[to]']"); var values = []; values.push($inputFrom.val()); values.push($inputTo.val()); return values; }; formElement.setValue = function(value){ var $inputFrom = $("select[name='"+ this.name +"[from]']"); var $inputTo = $("select[name='"+ this.name +"[to]']"); if( value[1] ){ $("option[value='"+ value[1] +"']", $inputFrom).attr('selected', 'selected'); } if( value[2] ){ $("option[value='"+ value[2] +"']", $inputTo).attr('selected', 'selected'); } }; return formElement; } /* end of forms */ /* Drag and drop fix */ DND_InterfaceFix = new (function(){ var embed = function(context){ var $context = $(context); var cWidth = $context.innerWidth(); var configureEmbed = function($embed) { var embed = $embed.get(0); if ( embed.default_width === undefined || embed.default_width === null ) { embed.default_width = $embed.width(); } if ( cWidth < embed.default_width ) { $embed.css('width', '100%'); } else { $embed.css('width', embed.default_width + 'px'); } $embed.attr('wmode', 'transparent'); }; var configureObject = function($object) { $object.css('width', '100%'); }; $('embed', context).each(function(){ var $node = $(this).hide(); configureEmbed($node); $node.show(); }); $('object', context).each(function() { var $node = $(this).hide(), $embeds = $('embed', this); configureObject($node); if ( $embeds.length ) { configureEmbed($embeds); } $node.show(); }); }; var image = function(context) { var $context = $(context), cWidth; var cWidth = $context.innerWidth(); if ( !cWidth ) { return; } var resize = function(img) { var $img = $(img); if ( img.default_width === undefined || img.default_width === null ) { img.default_width = $img.width(); } if ( img.default_width > cWidth ) { $img.css('width', '100%'); } else { $img.css('width', img.default_width); } }; $context.find('img').each(function(){ $(this).css('max-width', '100%'); if (this.naturalWidth == 0) { $(this).load(function(){ resize(this); }); } else { resize(this); } }); }; var iframe = function(context) { var $iframe = $('iframe', context); var cWidth = $(context).innerWidth(); $iframe.each(function(i, o) { var $o = $(o); if ( $o.width() > cWidth ) { $o.css('width', '100%'); } }); }; this.fix = function(context) { this.embed(context); this.image(context); this.iframe(context); }; this.embed = function(context) { $(context).each(function(){ embed(this); }) }; this.image = function(context) { $(context).each(function(){ image(this); }); }; this.iframe = function(context) { $(context).each(function(){ iframe(this); }); }; })(); /* Comments */ var OwComments = function( contextId, formName ){ this.formName = formName; this.$cmpContext = $('#' + contextId); } OwComments.prototype = { repaintCommentsList: function( data ){ owForms[this.formName].getElement('commentText').resetValue(); if(data.error){ OW.error(data.error); return; } $('.comments_list_cont', this.$cmpContext).empty().append($(data.commentList)); OW.addScript(data.onloadScript); }, updateCommentsCountOnPage: function( count ){ if( count == 0 ) { count = parseInt($('input[name=commentCountOnPage]', this.$cmpContext).val()) + 1; } $('input[name=commentCountOnPage]', this.$cmpContext).val(count); } }; var OwCommentsList = function( params ){ this.$context = $('#' + params.contextId); $.extend(this, params); } OwCommentsList.prototype = { init: function(){ var self = this; //Js event trigger OW.trigger('base.comments_list_init', {entityType: this.entityType, entityId: this.entityId}, this); if( this.pagesCount > 0 ) { for( var i = 1; i <= this.pagesCount; i++ ) { $('a.page-'+i, self.$context).bind( 'click', {i:i}, function(event){ self.reload(event.data.i); } ); } } for( var i = 0; i < this.commentIds.length; i++ ) { $('#del-'+this.commentIds[i]).bind( 'click', {i:i}, function(e){ if( confirm(self.delConfirmMsg) ) { $.ajax({ type: 'POST', url: self.delUrl, data: 'cid='+self.cid+'&commentCountOnPage='+self.commentCountOnPage+'&ownerId='+self.ownerId+'&pluginKey='+self.pluginKey+'&displayType='+self.displayType+'&entityType='+self.entityType+'&entityId='+self.entityId+'&page='+self.page + '&commentId=' + self.commentIds[e.data.i], dataType: 'json', success : function(data){ if(data.error){ OW.error(data.error); return; } self.$context.replaceWith(data.commentList); OW.addScript(data.onloadScript); }, error : function( XMLHttpRequest, textStatus, errorThrown ){ alert('Ajax Error: '+textStatus+'!'); throw textStatus; } }); } } ); if( $('#att'+this.commentIds[i]).length > 0 ) { $('.attachment_delete',$('#att'+this.commentIds[i])).bind( 'click', {i:i}, function(e){ $('#att'+self.commentIds[e.data.i]).slideUp(300, function(){$(this).remove();}); $.ajax({ type: 'POST', url: self.delAtchUrl, data: 'cid='+self.cid+'&commentCountOnPage='+self.commentCountOnPage+'&ownerId='+self.ownerId+'&pluginKey='+self.pluginKey+'&displayType='+self.displayType+'&entityType='+self.entityType+'&entityId='+self.entityId+'&page='+self.page + '&commentId=' + self.commentIds[e.data.i], dataType: 'json' }); } ); } $('#flag-'+this.commentIds[i]).bind( 'click', {i:i}, function(e){ alert(self.commentIds[e.data.i]); } ); } if( this.displayType == 3 || this.displayType == 4 ) { $('.comments_view_all a', this.$context).one('click', function(){ $(this).replaceWith(''); self.commentCountOnPage = 1000; if( window.commentCmps && window.commentCmps[self.cid] ) { window.commentCmps[self.cid].updateCommentsCountOnPage(1000); } self.reload(1); } ); } }, reload:function( page ){ var self = this; $.ajax({ type: 'POST', url: self.respondUrl, data: 'cid='+self.cid+'&commentCountOnPage='+self.commentCountOnPage+'&ownerId='+self.ownerId+'&pluginKey='+self.pluginKey+'&displayType='+self.displayType+'&entityType='+self.entityType+'&entityId='+self.entityId+'&page='+page, dataType: 'json', success : function(data){ if(data.error){ OW.error(data.error); return; } self.$context.replaceWith(data.commentList); OW.addScript(data.onloadScript); }, error : function( XMLHttpRequest, textStatus, errorThrown ){ OW.error('Ajax Error: '+textStatus+'!'); throw textStatus; } }); } } var OwAttachment = function( params ) { var self = this; var floatbox; var $context = $('#'+params.uid); var $previewCont = $('#attachment_preview_'+params.uid); var $videoCont = $('#video_code_'+params.uid); this.params = params; OW.bind('base.init_attachment', function(uid){if(uid == self.params.uid) self.init();}); this.init = function(){ $previewCont.empty(); this.item = null; while( $('#hd_'+this.params.uid).length > 0 ){ $('#hd_'+this.params.uid).remove(); } $('input[type=button]', $videoCont).unbind('click').click(function(){self.submitVideo();}); $('a.video', $context).show().unbind('click').click( function(){ floatbox = new OW_FloatBox({ $title: self.params.langs.addVideoLabel, $contents: $videoCont, width: 500, height: 300, icon_class: 'ow_ic_video' }); } ); this.hideLoader(); $('textarea', $videoCont).val(''); $previewCont.removeClass('item_loaded').empty(); $('a.image', $context).show().empty().append($('')); $('input[type=file]', $context).unbind('change').change( function(){ self.submitFile(); } ); } this.submitFile = function(){ this.disableButtons(); this.showLoader(); $form = $('
') .append($('input[type=file]', $context)); $('