"use strict"; window.initCAjaxPoll = function($,appcfg) { //-- pollyfill for "isArray" if (!Array.isArray) { Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } //-- pollyfill for "includes" if (!Array.prototype.includes) { Array.prototype.includes = function( findme ) { for( var i=0; i") == -1 ) { return this.toString(); } else { return this .replace(//g,'') .replace(/<\/sb>/g,''); } }; } //-- polyfill for JSON if (!window.JSON) { window.JSON = { parse: function(sJSON) { return eval('(' + sJSON + ')'); }, stringify: (function () { var toString = Object.prototype.toString; var isArray = Array.isArray || function (a) { return toString.call(a) === '[object Array]'; }; var escMap = {'"': '\\"', '\\': '\\\\', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t'}; var escFunc = function (m) { return escMap[m] || '\\u' + (m.charCodeAt(0) + 0x10000).toString(16).substr(1); }; var escRE = /[\\"\u0000-\u001F\u2028\u2029]/g; return function stringify(value) { if (value == null) { return 'null'; } else if (typeof value === 'number') { return isFinite(value) ? value.toString() : 'null'; } else if (typeof value === 'boolean') { return value.toString(); } else if (typeof value === 'object') { if (typeof value.toJSON === 'function') { return stringify(value.toJSON()); } else if (isArray(value)) { var res = '['; for (var i = 0; i < value.length; i++) { res += (i ? ', ' : '') + stringify(value[i]); } return res + ']'; } else if (toString.call(value) === '[object Object]') { var tmp = []; for (var k in value) { if (value.hasOwnProperty(k)) { tmp.push(stringify(k) + ': ' + stringify(value[k])); } } return '{' + tmp.join(', ') + '}'; } } return '"' + value.toString().replace(escRE, escFunc) + '"'; }; })() }; } var CUtil = { printError : function( msg ) { console.log( msg ); }, hsc : function( s ) { return $("
").text(s).html(); }, recalcStyle : function( jqo ) { var dummy = jqo.get(0).offsetWidth; }, ajaxSend : function( requ, obj, func ) { console.log("ajaxSend",requ); var _this = this; $.ajax({ url:appcfg.url_server, data:"requ="+encodeURIComponent(JSON.stringify(requ)), dataType:"jsonp", success:function(resp){ if ( resp.result == "OK" ) { console.log("resp",resp); func.call(obj,resp); } else { _this.printError( resp.result ); } }, error:function( jqXHR, textStatus, errorThrown ){ var s = "[$.ajax.error]\n"; s += jqXHR.responseText+"\n"; s += textStatus+"\n"; s += errorThrown; _this.printError( s ); } }); }, jsShallowCopy : function( obj ) { return $.extend({},obj); }, jsDeepCopy : function( obj ) { return $.extend(true,{},obj); }, isIE7or8 : function() { return (navigator.appVersion.indexOf("MSIE 7.")!=-1) || (navigator.appVersion.indexOf("MSIE 8.")!=-1); }, canCssAnim : function() { return ( document.createElement("div") .style.animationName !== undefined ); }, isTouchDevice : function() { return (("ontouchstart" in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); }, shuffleArray : function(ax) { var tmp, idx; var i = ax.length; while (0 !== i) { idx = Math.floor(Math.random() * i); i -= 1; tmp = ax[i]; ax[i] = ax[idx]; ax[idx] = tmp; } return ax; }, ensureArray : function( s ) { if ( s == undefined ) { return []; } else if ( Array.isArray(s) ) { return s; } else { s = s.trim(); if ( s ) { var sx = s.split(","); for( var i=0; i= 2 ) { rx.parent = ( lx[1] != "" ) ? lx[1] : whole; ap = lx[0]; } else { rx.parent = lx[0]; } if ( ap ) { ap = ap.split("-"); if (!(( 1<=ap.length ) && ( ap.length<= 2 ))) { ap = "top-left".split("-"); } var v = ap[0]; var h = ap[1]; v = ["top","middle","bottom"].includes(v) ? v : "top"; h = ["left","center","right"].includes(h) ? h : "left"; rx.abspos = {v:v,h:h}; } else { rx.abspos = null; } return rx; } } return { parent:"main-left", abspos:null }; }, normalizeMove : function( str ) { if ( typeof str == "string" ) { str = str.trim(); if ( str ) { var sx = str.split(" "); for( var i=0; i=0; i-- ) { var jqo = jqos.eq(i); if ( !jqo.hasClass("apsmx-nodisplay") ) { if ( jqo.hasClass("apsmx-cf-flex") ) { break; } else { jqo.css({ right:right+"px", width:jqo.outerWidth()+"px" }); right += jqo.outerWidth(true); } } } var w = jqo_prt.width()-left-right; $(this).css({left:left+"px",width:w+"px"}); } else { var top = 0; for( var i=0; i=0; i-- ) { var jqo = jqos.eq(i); if ( !jqo.hasClass("apsmx-nodisplay") ) { if ( jqo.hasClass("apsmx-cf-flex") ) { break; } else { jqo.css({ bottom:bottom+"px", height:jqo.outerHeight()+"px" }); bottom += jqo.outerHeight(true); } } } var h = jqo_prt.height()-top-bottom; $(this).css({top:top+"px",height:h+"px"}); } }); }, paddingToAbsolute : function( jqo_root ) { jqo_root.find(".apsmx-cf-pbox").each(function(){ if ( $(this).css("position") != "absolute" ) { return; } var css = { left:$(this).css("padding-left"), right:$(this).css("padding-right"), top:$(this).css("padding-top"), bottom:$(this).css("padding-bottom"), padding:0 }; $(this).css(css); }); }, }; var CImg = this.CImg = { getNaturalSize : function( jqo_img ) { var size = {}; var img = jqo_img.get(0); if ( img.naturalWidth ) { size.w = img.naturalWidth; size.h = img.naturalHeight; } else { //IE7&8 var image = new Image(); image.src = img.src; size.w = image.width; size.h = image.height; } return size; }, getNaturalSizeFromUrl : function( url ) { return this.getNaturalSize($("") .attr("src",url)); } }; var CPreloader = this.CPreloader = { flag_list : {}, flag_idx : 0, cancelAll : function() { this.flag_list = {}; this.flag_idx = 0; }, flag : function() { var idx = this.flag_idx; this.flag_list[idx] = true; this.flag_idx++; return idx; }, unflag : function( idx ) { if ( this.flag_list[idx] ) { delete this.flag_list[idx]; return true; } else { return false; } }, loadImgs : function( urls, obj, func ) { var _this = this; var max_url = urls.length; if ( max_url ) { var idx = this.flag(); var n_loaded = 0; for( var i=0; i") .load(function(){ n_loaded++; if ( max_url == n_loaded ) { if ( _this.unflag(idx) ) { if ( func ) { func.call(obj); } } } }); jqo.attr("src",url); } } else { if ( func ) { func.call(obj); } } }, loadBg : function( jqo, url, obj, func ) { var isFirefox = navigator.userAgent .toLowerCase().indexOf('firefox') > -1; if ( !isFirefox ) { if ( func ) { func.call(obj,jqo,url); } return; } var t = ( pollcfg.delay_loadbg ) ? pollcfg.delay_loadbg : 1; var _this = this; var idx = this.flag(); if ( !func ) { CRefCnt.lock(); } var w = Math.min(100,jqo.width()); jqo .html($("") .load(function(){ $(this).animate({ opacity:0 },t*1000,function(){ $(this).remove(); if ( !func ) { CRefCnt.unlock(); } if ( _this.unflag(idx) ) { if ( func ) { func.call(obj,jqo,url); } } }); }) .css({ width:w+"px", opacity:1 }) .attr("src",url) ); } }; function CAnimBoardOne( px ) { for( var p in px ) { this[p] = px[p]; } if ( !this.threshold ) { this.threshold = 500;/*ms*/ } this.setup(); }; CAnimBoardOne.prototype = { setup : function() { this.prev_t = 0; this.que = []; }, clearQue : function() { for( var i=0; i this.threshold ) { this.clearQue(); } } this.t_prev = t; //-- assign data-* attributes if ( px.data ) { for( var p in px.data ) { var v = px.data[p]; if ( v ) { this.jqo_ctar.attr("data-"+p,v); } } } //-- set class this.jqo_ctar.addClass(clsname+"_begin_"); if ( b_anim ) { this.jqo_ctar.addClass(clsname); } else { this.jqo_ctar.addClass(clsname+"_end_"); } this.que.push(clsname); } }; var CAnimBoard = this.CAnimBoard = { create : function( px ) { return new CAnimBoardOne(px); } }; var CCMS = this.CCMS = { cancel : {}, binding : {}, trigger : function( ename, data, ref ) { if (0){ console.log((this.classname ? this.classname : "CCMS") + " ccms["+pollcfg.pid+"]",ename,ref?"[resume]":"",data); } if ( data == undefined ) { data = {}; } if ( ename in this.binding ) { var ls = this.binding[ename]; var b_skip = ( ref ) ? true : false; for( var ele in ls ) { var rec = ls[ele]; if ( rec.func != null ) { if ( b_skip ) { b_skip = ( rec.obj != ref ); } else { var ret = rec.func.call(rec.obj,data); if ( ret == this.cancel ) { return; } } } } } }, bind : function( enames, obj, func, pos ) { var ex = enames.split(","); for( var e in ex ) { var ename = ex[e].replace(/^\s+|\s+$/g,''); if (!( ename in this.binding )) { this.binding[ename] = []; } if ( pos === true ) { this.binding[ename].unshift({ obj:obj, func:func }); } else { this.binding[ename].push({ obj:obj, func:func }); } } }, unbind : function( enames, obj ) { var ex = enames.split(","); for( var e in ex ) { var ename = ex[e].replace(/^\s+|\s+$/g,''); if ( ename in this.binding ) { if ( !obj ) { var temp = this.binding[ename]; this.binding[ename] = []; return temp; } else { for( var x in this.binding[ename] ) { if ( this.binding[ename][x].obj == obj ) { var func = this.binding[ename][x].func; this.binding[ename][x].obj = null; this.binding[ename][x].func = null; return func; } } } } } }, unbindAll : function() { this.binding = {}; } }; //-- deep copy CCMS to CPollCMS var CPollCMS = this.CPollCMS = CUtil.jsDeepCopy(CCMS); CPollCMS.classname = "CPollCMS"; var CWinBind = this.CWinBind = { handler:{}, timer_id:{}, bind : function( key, obj, func, delay ) { this.unbind(key); var _this = this; delay = parseFloat(delay); if ( isNaN(delay) || ( delay == 0 )) { this.handler[key] = function() { func.call(obj); }; } else { this.timer_id[key] = null; this.handler[key] = function() { if ( _this.timer_id[key] ) { clearTimeout(_this.timer_id[key]); } _this.timer_id[key] = setTimeout(function(){ func.call(obj); _this.timer_id[key] = null; },delay*1000); }; } $( window ).bind( key, this.handler[key] ); }, unbind : function(key){ if ( this.handler[key] ) { $( window ).unbind( key, this.handler[key] ); } }, unbindAll : function(){ for( var key in this.handler ) { this.unbind(key); } this.handler = {}; this.timer_id = {}; } }; var CTimer = this.CTimer = { tox : [], itx : [], timeout : function( obj, func, msec ) { this.tox.push(setTimeout(function(){ func.call(obj); },msec)); }, interval : function( obj, func, msec ) { this.itx.push(setInterval(function(){ func.call(obj); },msec)); }, clearAll : function() { this.clearAllTimeout(); this.clearAllInterval(); }, clearAllTimeout : function() { for( var i=0; i") .css({visibility:"hidden"}) .attr("class","apsmx-tooltip") if ( this.key ) { jqo_test_ctar.attr("data-key",this.key); } if ( this.type ) { jqo_test_ctar.attr("data-type",this.type); } var jqo_test = $("
"); jqo_test .css({visibility:"hidden"}) .attr("class",cls) .appendTo(jqo_test_ctar); jqo_test_ctar.appendTo(this.prt.jqo_ctar); var v = jqo_test.css(attr); jqo_test_ctar.remove(); return v; }, getCssInt : function( cls, attr ) { return parseInt(this.getCssVal(cls,attr)); }, getTipSize : function() { return this.getCssInt("apsmx-tooltip-triangle", "border-top-width"); }, getBoxRadius : function() { return this.getCssInt("apsmx-tooltip-msgbox", "border-top-left-radius"); }, getBgColor : function() { return this.getCssVal("apsmx-tooltip-msgbox", "background-color"); }, getMsgBoxSize : function( jqo_msgbox ) { jqo_msgbox .css({visibility:"hidden"}) .appendTo(this.prt.jqo_ctar); var size = { w:parseInt(jqo_msgbox.css("width")), h:parseInt(jqo_msgbox.css("height")) }; jqo_msgbox .remove() .css({visibility:"visible"}) return size; }, getRect : function( clip, space ) { var jqo_ctar = this.prt.jqo_ctar; var view = {}; var jqo_sref = CPoll.getScrollRef(); var size_cref = CPoll.getClientSizeRef(); view.top = jqo_sref.scrollTop(); view.bottom = view.top + size_cref.h; view.left = jqo_sref.scrollLeft(); view.right = view.left + size_cref.w; var ctar = {}; ctar.top = jqo_ctar.offset().top; ctar.bottom = ctar.top + jqo_ctar.height(); ctar.left = jqo_ctar.offset().left; ctar.right = ctar.left + jqo_ctar.width(); var cv = {}; cv.top = Math.max(view.top,ctar.top); cv.bottom = Math.min(view.bottom,ctar.bottom); cv.left = Math.max(view.left,ctar.left); cv.right = Math.min(view.right,ctar.right); clip.x = cv.left; clip.y = cv.top; clip.w = cv.right - cv.left; clip.h = cv.bottom - cv.top; var ref = {}; ref.top = this.jqo_ref.offset().top; ref.bottom = ref.top + this.jqo_ref.outerHeight(); ref.left = this.jqo_ref.offset().left; ref.right = ref.left + this.jqo_ref.outerWidth(); space.top = ref.top - cv.top; space.bottom = cv.bottom - ref.bottom; space.left = ref.left - cv.left; space.right = cv.right - ref.right; }, findOrien : function( space, msgbox ) { var k = 1.0; var orien; var lx = { top:( space.top - msgbox.h * k ) * msgbox.w, bottom:( space.bottom - msgbox.h * k ) * msgbox.w, left:( space.left - msgbox.w * k ) * msgbox.h, right:( space.right - msgbox.w * k ) * msgbox.h }; var b_top_bottom = (( 0 < space.top ) && ( 0 < space.bottom )); var b_left_right = (( 0 < space.left ) && ( 0 < space.right )); if (( lx.top > 0 ) && b_left_right ) { orien = "top"; } else if (( lx.bottom > 0 ) && b_left_right ) { orien = "bottom"; } else if (( lx.right > 0 ) && b_top_bottom ) { orien = "right"; } else if (( lx.left > 0 ) && b_top_bottom ) { orien = "left"; } else { var n; n = lx.top; orien = "top"; if ( lx.bottom > n ) { n = lx.bottom; orien = "bottom"; } else if ( lx.right > n ) { n = lx.right; orien = "right"; } else if ( lx.left > n ) { n = lx.left; orien = "left"; } } return orien; }, open : function() { //-- tooltip's tip width and height var u = this.getTipSize(); var tri = { w:u*2, h:u }; //-- msgbox's border radius var r = this.getBoxRadius(); var radius = { x:r, y:r }; //-- container element size var clip = {}; var space = {}; this.getRect(clip,space); //-- reference element size var ref_pos = this.jqo_ref.offset(); var ref = { x:ref_pos.left, y:ref_pos.top, w:this.jqo_ref.outerWidth(), h:this.jqo_ref.outerHeight() }; //-- tooltip this.jqo_tooltip = $("
"); if ( this.key ) { this.jqo_tooltip.attr("data-key",this.key); } if ( this.type ) { this.jqo_tooltip.attr("data-type",this.type); } this.jqo_tooltip.attr("class","apsmx-tooltip apsmx-nosel"); //-- msgbox var msg = this.msg; msg = msg.replace(new RegExp("\r","g"),""); msg = msg.replace(new RegExp("\n","g"),"
"); var jqo_msgbox = $("
"); if ( this.key ) { jqo_msgbox.attr("data-key",this.key); } if ( this.type ) { jqo_msgbox.attr("data-type",this.type); } jqo_msgbox .attr("class","apsmx-tooltip-msgbox") .html($("
") .attr("class","apsmx-tooltip-msg") .html(msg) ); var msgbox = this.getMsgBoxSize(jqo_msgbox); msgbox.w += tri.w; msgbox.h += tri.w; //-- find orientation(top,bottom,left,right) var orien = this.findOrien(space,msgbox); //-- create tip var jqo_tri = $("
"); jqo_tri .attr("class","apsmx-tooltip-triangle") .css({"border-color":this.getBgColor()}) .addClass("apsmx-tooltip-triangle-"+orien) var jqo_tip = $("
") .attr("class","apsmx-tooltip-tip") .html(jqo_tri); //-- combine parts switch( orien ) { case "top": this.jqo_tooltip .append(jqo_msgbox) .append(jqo_tip); break; case "bottom": this.jqo_tooltip .append(jqo_tip) .append(jqo_msgbox); break; case "left": jqo_tip.css({display:"inline-block"}); jqo_msgbox.css({display:"inline-block"}); this.jqo_tooltip .append(jqo_msgbox) .append(jqo_tip); break; case "right": jqo_tip.css({display:"inline-block"}); jqo_msgbox.css({display:"inline-block"}); this.jqo_tooltip .append(jqo_tip) .append(jqo_msgbox); break; } //-- put it in ctar this.jqo_tooltip.appendTo(this.prt.jqo_ctar); //-- get size var msgbox = { w:jqo_msgbox.outerWidth(), h:jqo_msgbox.outerHeight() }; //-- adjust tip width or height switch( orien ) { case "top": case "bottom": jqo_tip.css({height:tri.h+"px"}); break; case "left": case "right": jqo_tip.css({ width:tri.h+"px", height:msgbox.h+"px" }); break; } //-- position tip in the center switch( orien ) { case "top": tri.y_init = 0; tri.x_init = (msgbox.w-tri.w)/2; break; case "bottom": tri.y_init = -tri.h; tri.x_init = (msgbox.w-tri.w)/2; break; case "left": tri.y_init = (msgbox.h-tri.w)/2; tri.x_init = 0; break; case "right": tri.y_init = (msgbox.h-tri.w)/2; tri.x_init = -tri.h; break; } //-- position tooltip var x, y; switch( orien ) { case "top": case "bottom": x = ref.x+ref.w/2-msgbox.w/2; tri.x = tri.x_init; var d = (x + msgbox.w)-(clip.x+clip.w); if ( d > 0 ) { tri.x = tri.x + d; var d_tri = (tri.x+tri.w)-(msgbox.w-radius.x); if ( d_tri > 0 ) { tri.x = msgbox.w-radius.x-tri.w; x = x - d + d_tri; } else { x -= d; } } var d = clip.x-x; if ( d > 0 ) { tri.x = tri.x - d; var d_tri = radius.x - tri.x; if ( d_tri > 0 ) { tri.x = radius.x; x = x + d - d_tri; } else { x += d; } } tri.y = tri.y_init; break; case "left": case "right": y = ref.y-(msgbox.h-ref.h)/2; tri.y = tri.y_init; var d = (y + msgbox.h)-(clip.y+clip.h); if ( d > 0 ) { tri.y = tri.y + d; var d_tri = (tri.y+tri.h)-(msgbox.h-radius.h); if ( d_tri > 0 ) { tri.y = msgbox.h-radius.y-tri.h; y = y - d + d_tri; } else { y -= d; } } var d = clip.y-y; if ( d > 0 ) { tri.y = tri.y - d; var d_tri = radius.y - tri.y; if ( d_tri > 0 ) { tri.y = radius.y; y = y + d -d_tri; } else { y += d; } } tri.x = tri.x_init; break; } //-- additional position calculations var d = 8; this.dx = 0; this.dy = 0; switch( orien ) { case "top": y = ref.y-(msgbox.h+tri.h); this.dy = -d; break; case "bottom": y = ref.y+ref.h; this.dy = d; break; case "left": x = ref.x-(msgbox.w+tri.h); this.dx = -d; break; case "right": x = ref.x+ref.w; this.dx = d; break; } //-- set tip poisitons jqo_tri .css({ top:tri.y+"px", left:tri.x+"px" }); //-- set tooltip poisitons var ctar_pos = this.prt.jqo_ctar.offset(); var x_end = x-ctar_pos.left; var y_end = y-ctar_pos.top; var x_start = x_end+this.dx; var y_start = y_end+this.dy; var _this = this; this.jqo_tooltip .css({ opacity:0, left:x_start+"px", top:y_start+"px" }) .animate({ opacity:1, left:x_end+"px", top:y_end+"px" }) .click(function(e){ _this.prt.close(_this.jqo_ref); }); }, close : function( b_quick ) { this.jqo_tooltip.stop(true); if ( b_quick ) { this.jqo_tooltip .css({opacity:0}) .remove(); } else { this.jqo_tooltip .animate({ opacity:0, left:"+="+this.dx+"px", top:"+="+this.dy+"px" },300,function(){ $(this).remove(); }); } } }; var CTooltip = this.CTooltip = { init : function(){ CCMS.bind("page-bind",this,function(){ CCMS.bind("begin-page",this,function(){ CCMS.bind("tooltip-open",this,this.openExe); }); CCMS.bind("page-setup",this,function(){ this.idx = 1000; this.list = {}; this.jqo_ctar = CPoll.jqo_css_ctar; }); CCMS.bind("wloader-show",this,function(){ this.closeAll(); }); }); }, attach : function( px ){ var _this = this; px.jqo_ref .hoverTS(function(){ _this.hoverStart($(this),px); },function(){ _this.hoverEnd($(this),px); }); }, hoverStart : function( jqo, px ){ px.jqo_ref = jqo; if ( px.client ? px.client_func.call(px.client,px) : true ) { this.open(px); } }, hoverEnd : function( jqo, px ){ this.close(jqo); }, open : function( px ){ CCMS.trigger("tooltip-open",px); }, openExe : function( px ){ if ( !px.jqo_ref.data("apsmx-tooltip-idx") ) { px.prt = this; this.list[this.idx] = new CTooltipOne(px); px.jqo_ref.data("apsmx-tooltip-idx",this.idx); this.idx++; } }, close : function( jqo_ref ) { var idx = jqo_ref.data("apsmx-tooltip-idx"); jqo_ref.data("apsmx-tooltip-idx",0); if ( idx in this.list ) { this.list[idx].close(); } }, closeAll : function() { for ( var i in this.list ) { var jqo_ref = this.list[i].jqo_ref; var idx = jqo_ref.data("apsmx-tooltip-idx"); if ( idx ) { jqo_ref.data("apsmx-tooltip-idx",0); this.list[i].close(true); } } this.list = {}; } }; var CToolBar = this.CToolBar = { init : function() { CCMS.bind("page-bind",this,function(){ //-- init this.handlers = {}; CCMS.bind("toolbtn-click",this,function(data){ this.click(data.jqo); }); CCMS.bind("page-setup",this,function(){ this.jqo_ctar = CPage.jqo_ctar; this.show(CPage.config("toolbars")); }); }); }, register : function( type, rec ) { this.handlers[type] = rec; }, show : function( toolbars ) { for( var key in toolbars ) { var qx = toolbars[key]; qx.key = key; this.insertToolBar(qx,this.createToolBar(qx)); } var _this = this; this.jqo_ctar.find(".apsmx-toolbtn") .click(function(e){ CTooltip.close($(this)); var cfg = $(this).data("cfg"); if ( cfg.type != "link" ) { e.preventDefault(); } CCMS.trigger("toolbtn-click",{ jqo:$(this) }); }) .bind("contextmenu",function(e){ e.preventDefault(); e.stopPropagation(); return false; }); }, insertToolBar : function( qx, jqo_toolbar ) { if ( !jqo_toolbar ) { return; } var jqo_ctar = this.jqo_ctar.find(".apsmx-"+qx.location); //-- ensure "clear" var jqo_clear = jqo_ctar.find(".apsmx-clear-both"); if ( !jqo_clear.length ) { jqo_clear = $("
").attr("class","apsmx-clear-both"); jqo_ctar.append(jqo_clear); } //-- vertical alignment if ( qx.align && (( qx.align == "left" ) || ( qx.align == "right" ))) { jqo_toolbar.css({ float:qx.align, "text-align":qx.align }); } //-- block if ( qx.block ) { jqo_toolbar.css({ display:"block", float:"" }); } //-- insert toolbar if ( qx.moveto == "top" ) { jqo_ctar.prepend(jqo_toolbar); } else { jqo_clear.before(jqo_toolbar); } //-- call show handler var jqo_list = jqo_toolbar.find(".apsmx-toolbtn"); for( var i=0; i") .attr("class","apsmx-toolbar") .attr("data-key",qx.key); } jqo_toolbar.append(jqo_toolbtn); } } return jqo_toolbar; }, createToolBtn : function( cfg ) { if ( !this.handlers[cfg.type] ) { console.log("Unknown Toolbtn Type: "+cfg.type); return null; } var rec = this.handlers[cfg.type]; //-- call init handler var b_ok = ( rec.init ) ? rec.init.call(rec.obj,cfg) : true; if ( b_ok ) { var jqo_toolbtn = cfg.jqo = $(pollcfg.htmlx.toolbtn); jqo_toolbtn .attr("data-type",cfg.type) .attr("data-key",cfg.key) .data("cfg",cfg); var b_build = ( rec.build ) ? rec.build.call(rec.obj,cfg) : true; if ( b_build ) { //-- tabindex jqo_toolbtn.attr("tabindex","0") var jqo_toolbtn_ibox = jqo_toolbtn .find(".apsmx-toolbtn-ibox"); var b_needed; //-- icon b_needed = false; var jqo_img = jqo_toolbtn_ibox .find(".apsmx-toolbtn-img") if ( jqo_img.length && cfg.icon ) { if ( cfg.icon == "" ) { cfg.icon = cfg.type+".png"; } if ( pollcfg.imgx[cfg.icon] ) { b_needed = true; jqo_img.attr("src",pollcfg.imgx[cfg.icon]); } } if ( !b_needed ) { jqo_img.remove(); } //-- label b_needed = false; var jqo_label = jqo_toolbtn_ibox .find(".apsmx-toolbtn-label") if ( jqo_label.length && cfg.label ) { b_needed = true; jqo_label .html(cfg.label) .bind("contextmenu",function(e){ e.preventDefault(); e.stopPropagation(); return false; }); } if ( !b_needed ) { jqo_label.remove(); } //-- tooltip if ( cfg.tooltip ) { var px = { jqo_ref:jqo_toolbtn, msg:cfg.tooltip, key:cfg.key, type:cfg.type }; if ( cfg.client ) { px.client = cfg.client; px.client_func = cfg.client_func; } CTooltip.attach(px); } } return jqo_toolbtn; } else { return null; } }, click : function( jqo_toolbtn ) { //-- click effect jqo_toolbtn.removeClass("apsmx-toolbtn-click"); CUtil.recalcStyle(jqo_toolbtn); jqo_toolbtn.addClass("apsmx-toolbtn-click"); //-- obtain config var cfg = jqo_toolbtn.data("cfg"); //-- animate CPage.animate({ ename:"toolbtn-click", data:{ "toolbtn-key":cfg.key, "toolbtn-type":cfg.type } }); //-- call click handler var rec = this.handlers[cfg.type]; if ( rec.click ) { rec.click.call(rec.obj,cfg); } }, editBtn : function( key, cfg ) { var jqo = this.jqo_ctar .find(".apsmx-toolbtn[data-key='"+key+"']") if ( cfg.icon && pollcfg.imgx[cfg.icon] ) { jqo .find(".apsmx-toolbtn-img") .attr("src",pollcfg.imgx[cfg.icon]); } if ( cfg.label ) { jqo .find(".apsmx-toolbtn-label") .html(cfg.label); } } }; var CBg = this.CBg = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("page-setup",this,function(){ this.jqo_ctar = CPage.jqo_ctar.parent().find(".apsmx-bg"); if ( this.jqo_ctar.length ) { if ( CPage.config("bg_color") ) { var bgc = CPage.config("bg_color"); try { this.jqo_ctar.css({ "background-color":bgc }); } catch(err) { console.log("Error:CBg",bgc); } this.jqo_ctar.show(); } } }); }); } }; var CSbg = this.CSbg = { getImgUrl : function() { var bgimgx = CPage.config("bgimgx"); if ( bgimgx.length == 0 ) { return null; } else { return bgimgx[0].url; } }, init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("page-setup",this,function(){ //-- init this.jqo_ctar = CPage.jqo_ctar.parent().find(".apsmx-sbg"); var url = this.getImgUrl(); if ( url ) { CRefCnt.lock(); CPreloader.loadImgs([url],this,function(){ //-- display background this.jqo_ctar .css({ background:"url("+CUtil.sq(url)+")", "background-position":"center center", "background-size":"cover" }); this.jqo_ctar.show(); CRefCnt.unlock(); }); } }); }); } }; var CWloader = this.CWloader = { setup : function() { CPollCMS.bind("setup-poll-end",this,function(){ this.active_cnt = 0; this.s_delay_init = pollcfg.wloader_delay_init; this.s_delay = pollcfg.wloader_delay; this.jqo_prt = CPoll.jqo_css_ctar; var _this = this; this.handler_scroll = function(){ _this.update(); }; this.handler_resize = function(){ _this.update(); }; this.show(); }); }, getMiddlePos : function() { var vp_top = $(window).scrollTop(); var vp_bottom = vp_top + $(window).height(); var ctar_top = this.jqo_wloader.offset().top; var ctar_bottom = ctar_top + this.jqo_wloader.height(); var cv_top = Math.max(vp_top,ctar_top); var cv_bottom = Math.min(vp_bottom,ctar_bottom); var y = parseInt((cv_bottom-cv_top)/2) + cv_top - ctar_top; return y; }, update : function() { var y = this.getMiddlePos(); if ( this.jqo_wloader.height() ) { var dd = parseInt(this.jqo_wloader_msgbox.height()/2); this.jqo_wloader_msgbox.css({ visibility:"visible", top:(y-dd)+"px" }); } else { this.jqo_wloader_msgbox.css({ visibility:"hidden" }); } }, show : function() { this.active_cnt++; var s_delay = ( this.active_cnt > 1 ) ? this.s_delay : this.s_delay_init; if ( s_delay < 0 ) { return; } var jqo_wloader = this.jqo_prt.find(".apsmx-wloader"); if ( jqo_wloader.length ) { jqo_wloader.remove(); } CCMS.trigger("wloader-show"); this.jqo_prt.append(pollcfg.htmlx.wloader); this.jqo_wloader = this.jqo_prt.find(".apsmx-wloader"); this.jqo_wloader_msgbox = this.jqo_wloader.find(".apsmx-wloader-msgbox"); this.jqo_wloader_msg = this.jqo_wloader.find(".apsmx-wloader-msg"); this.msg = pollcfg.ptext["wloader:msg"]; if ( this.msg ) { this.jqo_wloader_msg.html(this.msg.sb()); } else { this.jqo_wloader_msg.remove(); } $(window).bind("scroll",this.handler_scroll); $(window).bind("resize",this.handler_resize); var _this = this; setTimeout(function(){ _this.update(); },s_delay*1000); }, hide : function() { if ( this.jqo_prt.find(".apsmx-wloader").length ) { $(window).unbind("scroll",this.handler_scroll); $(window).unbind("resize",this.handler_resize); CCMS.trigger("wloader-hide"); //-- fadeout and remove this.jqo_wloader.remove(); /* .find(".apsmx-wloader-ibox") .html("") .animate({ opacity:0 },300,function(){ $(this).remove(); }); */ } } }; var CSelCnt = this.CSelCnt = { init : function() { CCMS.bind("page-bind",this,function(){ //-- bind CCMS.bind("selcnt-change",this,function(data){ var jqo_selcnt = CPage.jqo_ctar.find(".apsmx-selcnt"); if ( data.need_more <= 0 ) { jqo_selcnt.addClass("apsmx-selcnt-ready"); } else { jqo_selcnt.removeClass("apsmx-selcnt-ready"); } jqo_selcnt.find(".apsmx-selcnt-num") .html(data.selcnt.toString()); }); }); } }; var COptAm = this.COptAm = { registerHanlder : function(key,func) { this.handlers[key] = func; }, setupHanlders : function() { this.handlers = {}; this.registerHanlder("none", function(key) { var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i0; i--) { var jqo_abox_i = jqo_aboxes.eq(i); var rec_i = jqo_abox_i.data("rec"); var j = Math.floor(Math.random() * (i+1)); var jqo_abox_j = jqo_aboxes.eq(j); var rec_j = jqo_abox_j.data("rec"); var temp = rec_i.delay; rec_i.delay = rec_j.delay; rec_j.delay = temp; } } break; case "bottom-up": case "bottom-up-c": for( var i=0; i 1 ) { str = $.trim(sx[Math.floor(Math.random()*sx.length)]); } sx = str.split(/\s+/); if ( sx.length != 3 ) { str = "none"; } else { key = $.trim(sx[0]); order = $.trim(sx[1]); //-- duration var d = $.trim(sx[2]); b_n = ( d.substr(0,1) == "n" ); if ( b_n ) { d = d.substr(1); } dura = parseFloat(d); } } //-- validate key if (!( key in this.handlers )) { key = "none"; } //-- validate order var order_list = [ "all-at-once", "top-down", "bottom-up", "random", "top-down-c", "bottom-up-c", "random-c" ]; if ( $.inArray(order,order_list) == -1 ) { order = order_list[0]; } //-- validate dura if ( key == "none" ) { dura = 0; } else { dura = ( isNaN(dura) ) ? 0 : dura; if ( b_n ) { var len = this.jqo_ctar.find(".apsmx-opt-abox"); dura = dura * len; } } //-- setup order if ( key != "none") { this.setupOrder(order,dura); } //-- complete callback function if ( this.oncomplete ) { CTimer.timeout(this,function(){ this.b_running = false; this.oncomplete.call(this.prt); },dura*1000); } //-- execute this.handlers[key].call(this,key); }, abort : function() { if ( this.b_running ) { this.jqo_ctar.find(".apsmx-opt-abox").stop(true); } } }; COptAm.setupHanlders(); var COptBg = this.COptBg = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("opt-setup",this,function(){ this.bgcx = CUtil.ensureArray(CPage.config("opt_bg_color")); this.attach(); }); }); }, attach : function() { var jqo_aboxes = COpt.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i") .attr("class","apsmx-opt-bg"); var jqo_sbg = jqo_bgctar.children(".apsmx-opt-sbg"); if ( jqo_sbg.length ) { jqo_bg.insertBefore(jqo_sbg); } else { jqo_bg.prependTo(jqo_bgctar); } var bgc = (rec.bgc) ? rec.bgc : ( this.bgcx ? this.bgcx[i % this.bgcx.length] : null ); if ( bgc ) { try { jqo_bg.css({ "background-color":bgc }); } catch(err) { console.log("Error:COptBg",bgc); } } } } }; var COptSbg = this.COptSbg = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("opt-setup",this,function(){ this.preloadImg(); this.attach(); }); }); }, preloadImg : function() { var urls = []; var opts = CPage.config("opts"); for( var i=0; i 0 ) { rec.bgimg = rec.bgimgx[0]; urls.push(rec.bgimg.url); } } CRefCnt.lock(); CPreloader.loadImgs(urls,this,function(){ CRefCnt.unlock(); }); }, attach : function() { var jqo_aboxes = COpt.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i") .attr("class","apsmx-opt-sbg"); var jqo_bg = jqo_bgctar.children(".apsmx-opt-bg"); if ( jqo_bg.length ) { jqo_sbg.insertAfter(jqo_bg); } else { jqo_sbg.prependTo(jqo_bgctar); } if ( rec.bgimg ) { var url = rec.bgimg.url; jqo_sbg .css({ background:"url("+CUtil.sq(url)+")", "background-position":"center center", "background-size":"cover" }); CPreloader.loadBg(jqo_sbg,url); } } } }; var COpt = this.COpt = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("opt-create",this,function(data){ this.createOpt(data); }); CCMS.bind("opt-sort",this,function(data){ this.sortOpt(data); }); CCMS.bind("opt-setup",this,function(data){ this.setupOpt(data); }); CCMS.bind("opt-configure",this,function(data){ this.configureOpt(data); }); CCMS.bind("opt-height",this,function(data){ this.heightOpt(data); }); CCMS.bind("opt-layout",this,function(data){ this.layoutOpt(data); }); CCMS.bind("opt-align",this,function(data){ this.alignOpt(data); }); CCMS.bind("opt-move",this,function(data){ this.moveOpt(data); }); CCMS.bind("opt-update",this,function(data){ this.updateOpt(data); }); CCMS.bind("opt-internal-begin",this,function(data){ this.beginOptInternal(data); }); CCMS.bind("opt-begin",this,function(){ if ( CPage.config("b_focus") ) { //-- focus first element CPage.jqo_ctar .find("*[tabindex='0']") .eq(0).focus(); } }); CCMS.bind("page-setup",this,function(){ //-- init this.scroll_threshold = 0; this.tpl = pollcfg.tpl; this.jqo_ctar = CPage.jqo_ctar.find(".apsmx-opt-area"); if ( this.jqo_ctar.length == 0 ) { CCMS.trigger("opt-begin"); return; } CRefCnt.lock(); this.buildOpt(this,function(){ CRefCnt.unlock(); }); }); CCMS.bind("page-ready",this,function(){ //-- if scroll bar shows up, //-- update one more time if ( this.checkWidthChange() ) { CCMS.trigger("opt-update"); } }); CCMS.bind("begin-page",this,function(){ this.beginOpAnim(this,function(){ CCMS.trigger("opt-internal-begin"); CCMS.trigger("opt-begin"); }); }); CCMS.bind("abort-page",this,function(){ COptAm.abort(); }); CCMS.bind("resize",this,function(){ CCMS.trigger("opt-update"); }); }); }, each : function( obj, func ) { var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i ctar_top ) ? ( ctar_bottom - vp_top ) : ( vp_bottom - ctar_top ); return ( vish > this.scroll_threshold ); }, checkWidthChange : function() { if ( this.ctar_width == undefined ) { this.ctar_width = this.jqo_ctar.get(0).clientWidth; return false; } else { var ctar_width = this.jqo_ctar.get(0).clientWidth; if ( this.ctar_width == ctar_width ) { return false; } else { this.ctar_width = ctar_width; return true; } } }, updateOpt : function( data ) { var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); if ( !jqo_aboxes.length ) {return;} //-- get requested size data.max_col = Math.max(0,parseInt( CPage.config("opt_max_column"))); //-- slimcol CSlimCol.setup(CPage.config("slimcol")); if ( CSlimCol.singlecol() ) { data.max_col = 1; } if ( CSlimCol.slim() ) { CPage.jqo_ctar.addClass("apsmx-slimcol-slim"); } else { CPage.jqo_ctar.removeClass("apsmx-slimcol-slim"); } CUtil.recalcStyle(CPage.jqo_ctar); //-- back up previus position for( var i=0; i b.vcnt) {return 1;} return 0; }; break; case "desc": func = function sort_desc(a,b) { if (a.vcnt < b.vcnt) {return 1;} if (a.vcnt > b.vcnt) {return -1;} return 0; }; break; case "random": CUtil.shuffleArray(opts); break; } if ( func ) { opts.sort(func); } }, configureOpt : function( data ) { var area_w = data.area_w; var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i area_w ) { jqo_abox.css({ width:area_w+"px" }); jqo_opt.css({ width:"auto" }); } } }, getOptH : function() { var opt_h = CPage.config("opt:height"); if ( typeof opt_h === "undefined" ) { return "auto" } var h; if ( typeof opt_h === "string" ) { if ( opt_h.substr(0,1) == "x" ) { var ratio = parseFloat(opt_h.substr(1)); if ( !isNaN(ratio) ) { return -ratio; } } if ( opt_h == "image" ) { return "image" } h = parseFloat(opt_h); if ( !isNaN(h) ) { return h; } } if ( typeof opt_h === "number" ) { return opt_h; } return "auto" }, heightOpt : function( data ) { var opt_h = this.getOptH(); var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i area_w ) || (( 0 < max_col ) && ( max_col <= col ))) { size.w = Math.max(x,size.w); x = 0; size.h += h; h = 0; col = 0; } rec.x = x; rec.y = size.h; x += rec.w; h = Math.max(h,rec.h); col++; num_of_col = Math.max(num_of_col,col); } size.w = Math.max(x,size.w); size.h += h; }, alignOpt : function( data ) { var size = data.size; var area = data.area; var dx = (area.w-size.w)/2; var dy = (area.h-size.h)/2; if ( data.align ) { var a = data.align; if ( a.indexOf("left") != -1 ) { dx = 0; } else if ( a.indexOf("right") != -1 ) { dx = area.w-size.w; } if ( a.indexOf("top") != -1 ) { dy = 0; } else if ( a.indexOf("bottom") != -1 ) { dy = area.h-size.h; } } var jqo_aboxes = this.jqo_ctar.find(".apsmx-opt-abox"); for( var i=0; i 0 ) { jqo_box.css({width:vper_rect+"%"}); var jqo_inner = $("
") .attr("class","apsmx-opt-bar-inner"); if ( CPage.config("b_animation") && CUtil.canCssAnim() ) { jqo_bg.addClass("apsmx-anim"); jqo_inner.addClass("apsmx-anim"); } else { jqo_inner.css({width:"100%"}); } jqo_inner.appendTo(jqo_box); } else { jqo_box .css({ visibility:"hidden", width:0 }) } } } }, animateStats : function() { var jqo_statsx = this.jqo_ctar.find(".apsmx-opt-stats"); if ( CPage.config("b_animation") ) { jqo_statsx.addClass("apsmx-anim"); } jqo_statsx .css({ visibility:"visible" }); }, animate : function( jqo, px ) { if ( jqo.data("animboard") ) { jqo.data("animboard").run(px); } }, hoverStart : function( jqo ) { this.animate(jqo,{ename:"hover-start"}); }, hoverEnd : function( jqo ) { this.animate(jqo,{ename:"hover-end"}); }, insertComp : function( key, jqos ) { //-- location var loc = CPos.normalizeLoc(CPage.config(key+":location")); var move = CPos.normalizeMove(CPage.config(key+":moveto")); //-- create marks jqos .find(".apsmx-opt-"+loc.parent) .append(pollcfg.htmlx[key]); //-- size & animation var size = CPage.config(key+":size"); if ( size ) { COpt.jqo_ctar.find(".apsmx-"+key) .attr("data-size",size.toLowerCase()); } var anim = CPage.config(key+":animation"); if ( anim ) { COpt.jqo_ctar.find(".apsmx-"+key) .attr("data-anim",anim.toLowerCase()); } //-- positioning CPos.pos(COpt.jqo_ctar,[ key, key+"-centering", key+"-ibox"], loc,move ); //-- tooltip var tooltip = CPage.config(key+":tooltip"); if ( tooltip ) { var px = { jqo_ref:COpt.jqo_ctar.find(".apsmx-"+key+"-ibox"), msg:tooltip, type:key }; CTooltip.attach(px); } } }; var CStatus = this.CStatus = { init : function() { this.status = CPage.config("status"); CCMS.bind("page-bind",this,function(){ CCMS.bind("status",this,this.animateStatus); CCMS.bind("page-setup",this,function(){ //-- init this.jqo_ctar = CPage.jqo_ctar.find(".apsmx-sect-status"); if ( this.jqo_ctar.length ) { //-- insert code this.jqo_ctar.append(pollcfg.htmlx.status); //-- print status if ( pollcfg.ptext[this.status] ) { var jqo_status_msg = this.jqo_ctar.find(".apsmx-status-msg"); if ( jqo_status_msg.length ) { var msg = pollcfg.ptext[this.status]; jqo_status_msg.html(msg.sb()); } } else { this.jqo_ctar.remove(); } } }); CCMS.bind("page-start",this,function(){ CCMS.trigger("status",{key:this.status}); }); }); }, animateStatus : function( data ){ CPage.animate({ ename:"status", data:{"status-key":data.key} }); } }; var CAlert = this.CAlert = { init : function() { this.usermsg_idx = 1000; CCMS.bind("page-bind",this,function(){ CCMS.bind("alert-open",this,this.openExe); }); }, getMiddlePos : function() { var jqo_ctar = CPoll.jqo_ctar; var vp_top = $(window).scrollTop(); var vp_bottom = vp_top + $(window).height(); var ctar_top = jqo_ctar.offset().top; var ctar_bottom = ctar_top + jqo_ctar.height(); var cv_top = Math.max(vp_top,ctar_top); var cv_bottom = Math.min(vp_bottom,ctar_bottom); var y = parseInt((cv_bottom-cv_top)/2) + cv_top - ctar_top; return y; }, normalizeKey : function( key ) { pollcfg.alert = pollcfg.ptext; if ( key[0] == "@" ) { key = key.substr(1); } else { var s = key; key = "_usermsg_"+this.usermsg_idx; pollcfg.alert[key] = s; this.user_msg_idx++; } return key; }, open : function( key, jqo_ref ) { CCMS.trigger("alert-open",{ key:this.normalizeKey(key), jqo_ref:jqo_ref }); }, openExe : function( data ) { var key = data.key; var jqo_ref = data.jqo_ref; //-- animate CPage.animate({ ename:"alert-open", data:{"alert-key":key} }); //-- get alert message var msg = ( pollcfg.alert[key] ) ? pollcfg.alert[key] : ""; //-- show alert var ts = 400; var d_show = 30/2; var d_intro_short = 50; var d_intro_long = 150; var jqo_ctar = CPoll.jqo_ctar; var jqo_alert = jqo_ctar.find(".apsmx-alert"); if ( jqo_alert.length ) { jqo_alert .stop(true,true) .remove(); } jqo_ctar.append(pollcfg.htmlx.alert); var jqo_alert = jqo_ctar .find(".apsmx-alert") .attr("data-key",key); jqo_alert.find(".apsmx-alert-msg").html(msg.sb()); var dura = ( pollcfg.alert_duration ) ? pollcfg.alert_duration : 2.5; dura = dura * 1000; var h = jqo_alert.height(); var d_intro, d_outro; var y; if ( jqo_ref ) { d_intro = d_intro_short; d_outro = d_intro_short; y = jqo_ref.offset().top - jqo_ctar.offset().top - h - d_show; jqo_alert.attr("data-dir","up"); } else { d_intro = -d_intro_long; d_outro = -20; y = this.getMiddlePos() - h/2; d_show = -d_show; jqo_alert.attr("data-dir","down"); } jqo_alert .css({ visibility:"visible", opacity:0, top:(y+d_show+d_intro)+"px", left:0 }) .animate({ opacity:1, top:(y+d_show)+"px" },ts,function(){ $(this) .animate({ opacity:1, top:(y-d_show)+"px" },dura,"linear",function(){ $(this) .animate({ opacity:0, top:(y-d_show-d_outro)+"px" },ts,function(){ $(this).remove(); }); }); }) .click(function(e){ $(this).stop(true); $(this).remove(); }); } }; var CCmark = this.CCmark = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("opt-setup",this,function(){ this.setup(); this.resetAllChecks(); }); CCMS.bind("page-ready",this,function(){ this.triggerSelCnt("init"); }); CCMS.bind("opt-internal-begin",this,function(){ if ( CPage.config("b_can_vote") ) { this.start(); } }); CCMS.bind("mark-show",this,this.showMarkExe); CCMS.bind("mark-hide",this,this.hideMarkExe); CCMS.bind("mark-notallowed",this,this.notallowedMarkExe); }); }, setup : function() { COpt.insertComp("cmark", COpt.jqo_ctar.find(".apsmx-opt")); //-- create marks var url = pollcfg.imgx["cmark.png"]; COpt.jqo_ctar .find(".apsmx-cmark-imgbox") .css({ background:"url("+CUtil.sq(url)+")", "background-size":"100% 100%", }); //-- update //-- this.redrawAllMarks(); }, start : function() { //-- bind CCMS.bind("cmark-click",this,function( data ){ this.jqo_clicked = data.jqo; //-- process click if ( this.jqo_clicked ) { var rec = this.jqo_clicked.data("rec"); if ( rec.state == "n" ) { var cnt = this.countCheck(); var opt_min = pollcfg.opt_min; var opt_max = pollcfg.opt_max; if ( opt_max == 1 ) { this.resetAllChecks(); this.showMark(this.jqo_clicked,true); rec.state = "y"; cnt++; this.triggerSelCnt("check"); } else { //-- check if count is max if ( opt_max > cnt ) { this.showMark(this.jqo_clicked,true); rec.state = "y"; cnt++; this.triggerSelCnt("check"); } else { this.notallowedMark(this.jqo_clicked); } } if ( CPage.config("b_quick_vote") ) { if ( cnt >= opt_min ) { CCMS.trigger("vote"); } } } else { this.hideMark(this.jqo_clicked,true); rec.state = "n"; this.triggerSelCnt("uncheck"); } } }); //-- event if ( CPage.config("b_opt_click") ) { //-- click area == inside vote option COpt.jqo_ctar.find(".apsmx-opt") .css({ cursor:"pointer" }) .click(function(e){ e.preventDefault(); var jqo_abox = $(this) .parents(".apsmx-opt-abox").eq(0); var rec = jqo_abox.data("rec"); CCMS.trigger("cmark-click",{ loc:"opt", oid:rec.oid, jqo:jqo_abox }); }) .keydown(function(e){ var cc = e.which; if (( cc == 13 ) || ( cc == 32 )) { e.preventDefault(); $(this).click(); } }); } else { //-- click area == inside checkbox COpt.jqo_ctar.find(".apsmx-cmark") .css({ cursor:"pointer" }) .click(function(e){ e.preventDefault(); var jqo_abox = $(this) .parents(".apsmx-opt-abox").eq(0); var rec = jqo_abox.data("rec"); CCMS.trigger("cmark-click",{ loc:"cmark", oid:rec.oid, jqo:jqo_abox }); }) .keydown(function(e){ var cc = e.which; if (( cc == 13 ) || ( cc == 32 )) { e.preventDefault(); $(this).click(); } }); } }, resetAllChecks : function() { COpt.each(this,function(jqo,rec){ if ( rec.state == "y" ) { this.hideMark(jqo); } rec.state = "n"; }); }, triggerSelCnt : function( event ) { var selcnt = this.countCheck(); var data = { event:event, selcnt:selcnt, total:COpt.len(), opt_min:pollcfg.opt_min, opt_max:pollcfg.opt_max, need_more:pollcfg.opt_min-selcnt }; CCMS.trigger("selcnt-change",data); }, /* redrawAllMarks : function() { COpt.each(this,function(jqo,rec){ var jqo_img = jqo.find(".apsmx-cmark-img"); if ( rec.state == "y" ) { this.showMark(jqo); } else { this.hideMark(jqo); } }); }, */ toggleMark : function( jqo, b_focus, b ) { var prev = b ? "uncheck" : "check"; var next = b ? "check" : "uncheck"; var jqo_cmark = jqo.find(".apsmx-cmark"); jqo_cmark .removeClass("apsmx-cmark-notallowed") .removeClass("apsmx-cmark-"+prev) .addClass("apsmx-cmark-"+next); CPage.setConfigCss("cmark", jqo_cmark.find(".apsmx-cmark-ibox"), b ? "check" : "uncheck" ); if ( b_focus ) { jqo_cmark.focus(); } }, showMark : function( jqo, b_focus ) { CCMS.trigger("mark-show",{jqo:jqo,b_focus:b_focus}); }, showMarkExe : function( data ) { var jqo = data.jqo; var oid = jqo.data("rec").oid; CPage.animate({ ename:"mark-show", data:{oid:oid} }); COpt.animate(jqo.find(".apsmx-opt"),{ ename:"mark-show" }); this.toggleMark(data.jqo,data.b_focus,true); }, hideMark : function( jqo, b_focus ) { CCMS.trigger("mark-hide",{jqo:jqo,b_focus:b_focus}); }, hideMarkExe : function( data ) { var jqo = data.jqo; var oid = jqo.data("rec").oid; CPage.animate({ ename:"mark-hide", data:{oid:oid} }); COpt.animate(jqo.find(".apsmx-opt"),{ ename:"mark-hide" }); this.toggleMark(data.jqo,data.b_focus,false); }, notallowedMark : function( jqo ) { CCMS.trigger("mark-notallowed",{jqo:jqo}); }, notallowedMarkExe : function( data ) { var jqo = data.jqo; var oid = jqo.data("rec").oid; CPage.animate({ ename:"mark-notallowed", data:{oid:oid} }); COpt.animate(jqo.find(".apsmx-opt"),{ ename:"mark-notallowed" }); var jqo_cmark = data.jqo.find(".apsmx-cmark"); jqo_cmark .removeClass("apsmx-cmark-check") .removeClass("apsmx-cmark-uncheck") .removeClass("apsmx-cmark-notallowed"); CUtil.recalcStyle(jqo_cmark); jqo_cmark.addClass("apsmx-cmark-notallowed"); }, countCheck : function( jqo ) { var cnt_clicked = 0; COpt.each(this,function(jqo,rec){ if ( rec.state == "y" ) { cnt_clicked++; } }); return cnt_clicked; }, getAns : function() { var ans = []; COpt.each(this,function(jqo,rec){ if ( rec.state == "y" ) { ans.push(rec.oid); } }); return ans; } }; var CVmark = this.CVmark = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("opt-setup",this,function(){ this.setup(); }); CCMS.bind("opt-internal-begin",this,function(){ this.draw(); }); }); }, setup : function() { //-- init var jqo_aboxes = CPage.jqo_ctar.find(".apsmx-opt-abox"); //-- duration var dura = CPage.config("vmark:duration"); function getCntStr( dura ) { var str; if ( dura == "infinite" ) { str = "infinite"; } else { var d = parseInt(dura); if ( isNaN(d) || (d <= 0)) { d = 0; } str = d.toString(); } return str; }; var cnt_str = getCntStr( dura ); var jqos = $("#apsmx-does-not-exist"); jqo_aboxes.each(function(){ if ( $(this).data("rec").vmark ) { jqos = jqos.add($(this)); } }); COpt.insertComp("vmark",jqos); //-- create marks var url = pollcfg.imgx["vmark.png"]; jqos.each(function(){ $(this) .find(".apsmx-vmark-circle") .css({ "animation-iteration-count":cnt_str }) .next(".apsmx-vmark-imgbox") .css({ background:"url("+CUtil.sq(url)+")", "background-size":"100% 100%" }); }); //-- prepare for animation if ( !CPage.config("b_animation") ) { COpt.jqo_ctar .find(".apsmx-vmark") .addClass("apsmx-visible"); } }, draw : function() { if ( CPage.config("b_animation") ) { COpt.jqo_ctar .find(".apsmx-vmark") .addClass("apsmx-visible") .addClass("apsmx-anim"); } } }; var CVoteBtn = this.CVoteBtn = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("page-setup",this,function(){ //-- init this.jqo_ctar = CPage.jqo_ctar.find(".apsmx-sect-votebtn"); //-- insert code this.jqo_ctar.prepend(pollcfg.htmlx.votebtn); //-- get vote button this.jqo_btn_vote = this.jqo_ctar.find(".apsmx-votebtn"); //-- quick mode if ( CPage.config("b_quick_vote") ) { this.jqo_ctar.remove(); } }); CCMS.bind("opt-begin",this,function(){ if ( !CPage.config("b_quick_vote") ) { CCMS.trigger("votebtn-show"); } }); CCMS.bind("votebtn-show",this,this.showVoteBtn); CCMS.bind("vote",this,this.vote); CCMS.bind("validate",this,function(data){ var cnt = data.ans.length; if ( cnt < pollcfg.opt_min ) { data.errmsg = "@check-option"; data.result = false; } }); }); }, vote : function() { CPage.animate({ename:"vote"}); var ans = CCmark.getAns(); var data = { cmd:"vote", ans:ans, result:true }; CCMS.trigger("validate",data); if ( data.result ) { CCMS.trigger("pause"); CWloader.show(); var requ = { cmd:"vote", ans:ans }; CPoll.callServer( requ, this, function(resp){ if ( resp.pagecfg ) { if ( resp.alert ) { CPage.init_alert = resp.alert; } pollcfg.pagecfg = resp.pagecfg; CPage.setup(); } else { CCMS.trigger("resume"); CWloader.hide(); if ( resp.alert ) { console.log(resp.alert); this.showAlert(resp.alert); } } }); } else { this.showAlert(data.errmsg); } }, showAlert : function( key ) { if ( CPage.config("b_quick_vote") ) { var jqo = CCmark.jqo_clicked; } else { var jqo = this.jqo_btn_vote; } CAlert.open(key,jqo); }, showVoteBtn : function() { CPage.animate({ ename:"votebtn-show", b_anim:CPage.config("b_animation") }); var _this = this; this.jqo_btn_vote.click(function(e){ CCMS.trigger("vote"); }) .keydown(function(e){ var cc = e.which; if (( cc == 13 ) || ( cc == 32 )) { e.preventDefault(); $(this).click(); } }); } }; var CVtotal = this.CVtotal = { init : function() { CCMS.bind("page-bind",this,function(){ CCMS.bind("page-setup",this,function(){ //-- init this.b_exists = false; this.jqo_ctar = CPage.jqo_ctar.find(".apsmx-sect-vtotal"); if ( this.jqo_ctar.length ) { //-- insert code this.jqo_ctar.prepend(pollcfg.htmlx.vtotal); this.jqo_vtotal = this.jqo_ctar.find(".apsmx-vtotal"); if ( this.jqo_vtotal.length ) { this.b_exists = true; this.calcTotal(); this.jqo_vtotal_msg = this.jqo_vtotal .find(".apsmx-vtotal-msg"); var vtotal_tpl = CPage.config("vtotal:text"); var vtotal_str = vtotal_tpl.replace("%vtotal%", ''+this.vtotal+''); this.jqo_vtotal_msg.html(vtotal_str.sb()); } } }); CCMS.bind("opt-begin",this,function(){ if ( this.b_exists ) { CCMS.trigger("vtotal-show"); } }); CCMS.bind("vtotal-show",this,this.showTotal); }); }, calcTotal : function() { var opts = CPage.config("opts"); this.vtotal = 0; for( var i=0; i y ) { var jqo = this.getFullScreen() ? this.jqo_css_ctar : $("html, body"); jqo .animate({ scrollTop:y+"px" },800); } } }, getPollLoadCnt : function() { return CApp.pmap[pollcfg.wid].load_cnt; }, clearHeight : function() { //-- clear the height of
if //-- this is the first page of the first poll load if (( this.getPollLoadCnt() == 1 ) && ( this.page_load_cnt == 1 )) { if ( pollcfg.clear_height ) { pollcfg.jqo_ctar.css({ "height":"auto", "max-height":"none", "min-height":0 }); } } }, fixPollSize : function() { //-- if there is the previous poll then //-- fix the size of
this.jqo_css_ctar_prev = pollcfg.jqo_ctar.children().eq(0); var b_fix = false; if ( this.jqo_css_ctar_prev.length ) { b_fix = true; pollcfg.jqo_ctar .css({ "width":pollcfg.jqo_ctar.width()+"px", "height":pollcfg.jqo_ctar.height()+"px", }); } return b_fix; }, releasePollSize : function() { //-- if there is the previous poll then //-- it's time to delte it if ( this.jqo_css_ctar_prev && this.jqo_css_ctar_prev.length ) { this.jqo_css_ctar_prev.remove(); this.jqo_css_ctar_prev = null; } //-- release the parent fit class so the poll can freely expand this.jqo_css_ctar.removeClass("apsmx-parentfit"); //-- release the fixed the sie of
pollcfg.jqo_ctar.css({width:"auto",height:"auto"}); }, fixPageSize : function() { //-- maintain min-height until a new page content //-- gets it's height, otherwize containers may shrink if ( this.page_load_cnt > 1 ) { this.jqo_ctar.css({ "width":this.jqo_ctar.width()+"px", "height":this.jqo_ctar.height()+"px" }); } }, releasePageSize : function() { this.releasePollSize(); if ( this.page_load_cnt > 1 ) { this.jqo_ctar.css({"width":"auto"}); this.jqo_ctar.css({"height":"auto"}); //-- make page invisible this.jqo_page_ctar_prev .find("*") .css({"visibility":"hidden"}); } }, createBuffer : function( html ) { this.jqo_page_ctar_prev = this.jqo_page_ctar .css({ position:"absolute", top:0, left:0, width:"100%", height:"100%" }); this.jqo_page_ctar = $("
") .attr("class","apsmx-page-ctar") .css({ position:"relative", opacity:0 }) .insertAfter(this.jqo_page_ctar_prev); this.jqo_page_ctar .append($("
").attr("class","apsmx-bg")) .append($("
").attr("class","apsmx-sbg")) .append(html); return this.jqo_page_ctar.find(".apsmx-page"); }, removeBuffer : function() { if ( this.jqo_page_ctar_prev ) { this.jqo_page_ctar_prev.remove(); this.jqo_page_ctar_prev = undefined; } }, displayBuffer : function() { this.removeBuffer(); this.jqo_page_ctar.css({opacity:1}) if ( this.page_load_cnt > 1 ) { this.scrollToTop(pollcfg.scroll_to_top); } }, callServer : function( requ, obj, func ) { //-- reassing tag parameters var rec = CApp.getParams(pollcfg.wid); var ls = ["wid","pid","tid","iid","pswitch"]; for( var i=0; i") .attr("class","apsmx-page-ctar"); //-- poll container this.jqo_ctar = $("
") .attr("class","apsmx-poll") .append(this.jqo_page_ctar); //-- apply-css container //-- addt "apsmx-parentfit" to streach jqo_css_ctar //-- so wloader can show up. this.jqo_css_ctar = $("
") .attr("class",pollcfg.css_ctar) .addClass("apsmx-parentfit") .html(this.jqo_ctar); //-- if previous poll exists ( and so the size is fixed ) //-- append the new poll if ( b_fix ) { pollcfg.jqo_ctar.append(this.jqo_css_ctar); } else { pollcfg.jqo_ctar.html(this.jqo_css_ctar); } }, destroy : function() { CWloader.show(); CCMS.trigger("abort-page"); CCMS.unbindAll(); CPreloader.cancelAll(); CTimer.clearAll(); }, reboot : function() { this.scrollToTop(0); CApp.rebootPoll(pollcfg.wid); } }; CPoll.init(); }; /*js //==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>>==>>> // // Ajax Poll Script v4.12 // Copyright (c) phpkobo.com ( http://www.phpkobo.com/ ) // Email : admin@phpkobo.com // ID : APSMX-412 // URL : http://www.phpkobo.com/ajax_poll.php // // This software is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; version 2 of the // License. // //==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<<==<<< */ var CApp = { init_idx:0, wid:0, pmap:{}, trashque:[], max_trashque:2, getCssId : function( key ) { return appcfg.prefix_css + key; }, getJsId : function( key ) { return appcfg.prefix_js + key; }, removeCss : function( key ) { var id = this.getCssId(key); if ( $("#"+id).length ) { $("#"+id).remove(); } return id; }, insertCss : function( key, txt ) { var id = this.removeCss(key); var style = document.createElement("style"); style.type = "text/css"; style.id = id; if (style.styleSheet){ style.styleSheet.cssText = txt; } else { style.appendChild(document.createTextNode(txt)); } document.getElementsByTagName("head")[0].appendChild(style); }, removeJs : function( key ) { var id = this.getJsId(key); if ( $("#"+id).length ) { $("#"+id).remove(); } return id; }, insertJs : function( key, txt ) { var id = this.removeJs(key); var script = document.createElement("script"); script.type = "text/javascript"; script.id = id; if ( CUtil.isIE7or8() ) { script.text = txt; } else { script.appendChild(document.createTextNode(txt)); } document.getElementsByTagName("head")[0].appendChild(script); }, trash : function( wid ) { this.trashque.push(wid); if ( this.trashque.length > this.max_trashque ) { var wid_delete = appcfg.prefix_header+this.trashque.shift(); this.removeCss(wid_delete); this.removeJs(wid_delete); if ( this.pmap[wid_delete] ) { delete this.pmap[wid_delete]; } } }, setup : function() { this.extendJQuery(); this.setupAllInstances(); this.requestToServer(); }, getParams : function( wid ) { return this.pmap[wid]; }, ajaxSend : function( requ, obj, func ) { CUtil.ajaxSend(requ,obj,func); }, extendJQuery : function() { if ( !$.fn.hoverTS ) { $.fn.extend({ hoverTS:function( handlerIn, handlerOut ) { if ( CUtil.isTouchDevice() ) { $(this) .bind("touchstart",handlerIn) .bind("touchend touchcancel",handlerOut); } else { $(this).hover(handlerIn,handlerOut); } return this; } }); } }, getNumOfPoll : function() { var cnt = 0; for (var k in this.pmap) { if (this.pmap.hasOwnProperty(k)) { cnt++; } } return cnt; }, getPswitchVal : function( pswitch ) { var ax = pswitch.split(" "); var rx = []; for( var i=0; i tag if ( media ) { try { qx = JSON.parse(media); } catch(err) { } } //-- predifined media queries for( var key in appcfg.media ) { qx[key] = appcfg.media[key]; } //-- test media queries var rx = {}; for( var key in qx ) { var query = qx[key]; rx[key] = ( window.matchMedia && window.matchMedia(query).matches ) ? 1 : 0; } //-- touch device rx["touch"] = CUtil.isTouchDevice() ? 1 : 0; return rx; }, normalizeParam : function( jqo, key ) { var ret = jqo.attr("data-"+key); if ( !ret ) { ret = jqo.attr(key); } if ( !ret ) { ret = ""; } return ret; }, setupAllInstances : function() { var _this = this; $("."+appcfg.cls_selector).each(function(){ _this.setupInstance($(this)); }); }, setupInstance : function( jqo ) { if ( parseInt(jqo.attr("data-wid")) ) { return; } this.wid++; var wid = this.wid; jqo.attr("data-wid",wid); var pid = this.normalizeParam(jqo,"pid") if ( !pid ) { return; } var tid = this.normalizeParam(jqo,"tid"); if ( !tid ) { return; } var iid = this.normalizeParam(jqo,"iid"); var pswitch = this.normalizeParam(jqo,"pswitch"); var media = this.normalizeParam(jqo,"media"); var rec = { jqo_ctar:jqo, wid:wid, pid:pid, tid:tid, iid:iid, pswitch:this.getPswitchVal(pswitch), media:this.getMediaVal(media), media_org:media, load_cnt:1 }; this.pmap[wid] = rec; }, requestToServer : function() { var polls = []; for( var wid in this.pmap ) { var rec = this.pmap[wid]; if ( !rec.done ) { polls.push({ wid:rec.wid, pid:rec.pid, tid:rec.tid, iid:rec.iid, pswitch:rec.pswitch, media:rec.media }); } } if ( polls.length ) { this.init_idx++; var requ = { "cmd":"init", "polls":polls, "init_idx":this.init_idx }; this.ajaxSend(requ,this,function(resp){ if ( resp.result == "OK" ) { this.runPolls(resp); } else { var s = "[non-OK] " + resp.result; CUtil.printError( s ); } }); } }, rebootPoll : function( wid ) { if ( this.b_running ) { return; } this.b_running = true; var rec = this.pmap[wid]; rec.poll.CPoll.destroy(); this.trash(wid); var rec_new = {}; for( var key in rec ) { rec_new[key] = rec[key]; } this.wid++; var wid = this.wid; rec.jqo_ctar.attr("data-wid",wid); rec_new.wid = wid; rec_new.done = false; rec_new.load_cnt++; this.pmap[wid] = rec_new; this.requestToServer(); }, startPoll : function( px ) { if ( this.b_running ) { return; } this.b_running = true; var jqo = $(px.selector).eq(0); var wid = 0; if ( jqo.hasClass("apsmx") && jqo.attr("data-wid") ) { wid = parseInt(jqo.attr("data-wid")); if ( wid ) { var rec = this.pmap[wid]; rec.pid = px.pid; rec.tid = px.tid; if ( px.iid ) { rec.iid = px.iid } if ( px.pswitch ) { rec.pswitch = this.getPswitchVal(px.pswitch); } if ( px.media ) { rec.media = this.getMediaVal(px.media); } } } jqo .addClass("apsmx") .attr("data-pid",px.pid) .attr("data-tid",px.tid); if ( px.pswitch ) { jqo.attr("data-pswitch",px.pswitch) } if ( px.iid ) { jqo.attr("data-iid",px.iid) } if ( px.pswitch ) { jqo.attr("data-pswitch",px.pswitch) } if ( px.media ) { jqo.attr("data-media",px.media) } if ( wid ) { this.b_running = false; this.rebootPoll(wid); } else { this.setup(); } }, runPolls : function( resp ) { this.resp = resp; for( var key in resp.cssx ) { this.insertCss(key,resp.cssx[key]); } for( var key in resp.jsx ) { this.insertJs(key,resp.jsx[key]); } for( var wid in this.pmap ) { var rec = this.pmap[wid]; if ( !rec.done ) { rec.done = true; var pollcfg = resp.pollx[rec.wid]; if ( pollcfg ) { //-- init redirection if ( pollcfg.jump_url_init ) { document.location = pollcfg.jump_url_init; break; } //-- assign tag parameters pollcfg.pid = rec.pid; pollcfg.tid = rec.tid; pollcfg.iid = rec.iid; pollcfg.pswitch = rec.pswitch; pollcfg.media = rec.media; //-- assing jqo_ctar and "this" pollcfg.jqo_ctar = rec.jqo_ctar; pollcfg.app = this; //-- start poll rec.poll = new exePoll($,pollcfg); } } } //-- unflag b_running this.b_running = false; } }; var apsmx = { version : function() { return appcfg.version; }, run : function(px) { CApp.startPoll(px); } }; window.apsmx = apsmx; $(document).ready(function(){ CApp.setup(); }); };