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($('