var ctrlDown = false; var ctrlKey = 17, vKey = 86, cKey = 67; var lastrange = false; var currange = false; var touched = false; var mobile_template = 'notset'; function initxQuotes(){ //check for Jquery jq_loaded = 0; try{$("
"); jq_loaded = 1; loadTries=0; }catch(e){xLoadScript(jquri,"Jquery"); loadTries++; if(loadTries<=25){ try{console.log("Jquery not done loading");}catch(e){} setTimeout(initxQuotes,100);}else{xQuotesCrashedError()}} if(jq_loaded){ bindCtrlC(); //$(xsel_target_element_selector).keydown(function(e){copyfunction}); //$('.selopt').click(savequotefunction); $('#xQuotesBase').appendTo('body') if(qcount){$('#xQuotesBase').show();} setQuoteBindings(); setSelectionChecker(); } } function ctrlDownEvent(e){ if (e.keyCode == ctrlKey) ctrlDown = true; } function ctrlUpEvent(e){ if (e.keyCode == ctrlKey) ctrlDown = false; } function cDownEvent(e){ if (ctrlDown && (e.keyCode == cKey)){ e.stopPropagation(); savequotefunction(); setTimeout("clearSelectionNotification()",500); } } function bindCtrlC(){ unbindCtrlC(); $(document).keydown(ctrlDownEvent); $(document).keydown(cDownEvent); $(document).keyup(ctrlUpEvent); } function unbindCtrlC(){ $(document).unbind('keydown',ctrlDownEvent); $(document).unbind('keyup',ctrlUpEvent); $(document).unbind('keydown',cDownEvent); ctrlDown =false; } function setSelectionChecker(){ $(document).mousedown(function(event){ if(event.target.id === "selectionNotifier"){ event.stopPropagation(); savequotefunction(); setTimeout("clearSelectionNotification()",500); }else{ clearSelectionNotification(); } unbindCtrlC(); }); $( ".xquoteable" ).mouseup(function(event) { var selstart, selend,selcount = 0; try{ selstart = window.getSelection().getRangeAt(0).startOffset; selend = window.getSelection().getRangeAt(0).endOffset; selcount = parseInt(selend-selstart); var rect = window.getSelection().getRangeAt(0).getBoundingClientRect(); if(isNaN(rect.y)){ var box_y = $(window).scrollTop() + rect.top; var rect_off = (rect.right-rect.left) / 2; var box_x = rect.left + (rect_off); }else{ var box_y = $(window).scrollTop() + rect.y; var rect_off = (rect.right-rect.left) / 2; var box_x = rect.x + (rect_off); } try{ var isOpera = (navigator.userAgent.match(/Opera|OPR\//) ? true : false); if(isOpera){box_y = box_y + 60;} }catch(e){/*ignore error*/} if(selcount !== 0){ showSelectionNotification(parseInt(box_x),parseInt(box_y)); }else{ return; } }catch(e){ console.log("Quote JS error",e); } }); } function clearSelectionNotification(){ $('#selectionNotifier').remove(); } function showSelectionNotification(x,y){ //zitieren-popup über der Markierung anzeigen var $notifier = $("
Zitieren
"); $notifier.appendTo(document.body).css('visibility','visible'); var boxtop = parseInt(y) - 30; var nwidth = parseInt($notifier.width()/2); var boxleft = parseInt(x)-nwidth; $notifier.css('top',boxtop+'px').css('left',boxleft+'px'); bindCtrlC(); } function setQuoteBindings(){ $('.xQuotes.minimized .xQuotesHead').unbind('click'); $('.xquote').unbind('hover'); //$('.xquote').hover(function(){$(this).addClass('actquote'); },function(){$(this).removeClass('actquote');}); $('.xQuotes.minimized .xQuotesHead').click(maxquotesfunction); $.each($('.quote_action'),function(){ //this.addEventListener("touchstart", touchstart, false); }); $.each($('.quote_action'),function(){ this.addEventListener("mousedown", clickstart, false); }); } function setMBT(){ mobile_template = $('body').hasClass('mbt'); } function touchstart(){ touched = true; savequotefunction($(this).data('quotetarget')); $(this).addClass('act'); } function clickstart(){ if(touched){return;} savequotefunction($(this).data('quotetarget')); $(this).addClass('act'); } function minimizeQuotes(){$('#xQuotesBase').find('.xQuotes').addClass('minimized');setQuoteBindings();} function closeQuotes(){$('#xQuotesBase').hide();} function xgetQuotes(insert,insertnow){ if(!xselsaveurl){console.log("xselsaveurl is undefined");} insert_success = function(res){if(res.done){xquotes = res.quotes; $('#qcountspan').html(res.count); quotes_loaded=1; if(res.count>0) {showXQuotesToInsert();}else{$('#xQuotesInsertDiv, #quotesToInsert').fadeTo(0,'fast').remove()}}else{alert('error:' + res.error );}} insertnow_success = function(res){if(res.done){xquotes = res.quotes; $('#qcountspan').html(res.count); quotes_loaded=1; if(res.count>0) {insertSavedQuotes();}}else{alert('error:' + res.error );}} noinsert_success = function(res){if(res.done){xquotes = res.quotes; setQuoteCount(res.count);quotes_loaded=1; if(res.count>0) {showXQuotes();}}else{alert('error:' + res.error );}} if(insertnow){successfunc = insertnow_success;} else{successfunc = insert ? insert_success : noinsert_success;} $.ajax({"type":"post","dataType":"json", url: xselsaveurl,data :{'action':'load'},success: successfunc}); } function xdelQuote(qid){ $.ajax({"type":"post","dataType":"json", url: xselsaveurl,data :{'action':'del','quoteid':qid},success: function(res){if(res.done){$target = $('#xquote_'+res.qid); if($target.hasClass('quote_visible')){xgetQuotes(1); setQuoteCount(res.count);}else{$target.fadeTo(0).remove(); setQuoteCount(res.count);}}else{alert('error:' + res.error );}}}); } function xclearAllQuotes(insert){ insert_success = function(){$('#xQuotesInsertDiv, #quotesToInsert').fadeTo(0,'fast').remove();setQuoteCount('0')} noinsert_success = function(res){if(res.done){xquotes = []; $('#xQuotesBase').find('.xquote').fadeTo(0).remove(); setQuoteCount('0');minimizeQuotes();}else{alert('error:' + res.error );}} successfunc = insert ? insert_success : noinsert_success; $.ajax({"type":"post","dataType":"json", url: xselsaveurl,data :{'action':'clear'},success: successfunc}); } function insertSavedQuotes(){ $.each(xquotes,function(){xInsertQuote(this.id,null,null,1)}); //$('#xQuotesInsertDiv, #quotesToInsert').fadeTo(0,'fast').remove() } function xInsertQuote(qid,para,full,force,qdata){ if(!force && ! $('#xquote_'+qid).hasClass('actquote')){ $('.xquote').removeClass('actquote'); $('#xquote_'+qid).addClass('actquote'); return; } var failed = 0; curquote = qdata ? qdata : xquotes[qid]; var text=""; if(curquote.params){ curquote.params = curquote.params.replace("%guestname%","Gast"); text = '[quote='+curquote.params+']';} else{text = "[quote]";} if(parseInt(curquote.full) || full){text += curquote.plaintext;} else if(para){text += curquote.quote_para_plain;} else{text+= curquote.quote_plain;} text += "[/quote]"; text = text.replace(/\r/g,""); try{xob_insert(text + "\n");} catch(e){try{insert(text + "\n","");}catch(e){alert('Auf dieser Seite können Sie keine Zitate einfügen'); failed = 1;}} if($('#quoteToggler .nextquote')){$('#quoteToggler .nextquote').trigger('click');} } function setQuoteCount(count){ $('#xQuotesBase .qcount, #quotenav .qcount, #xquotes .qcount').html(count); } function showXQuotes(){ $.each(xquotes,function(){var qdiv = xQuoteSkeleton(this); $(qdiv).prependTo($('#xQuotesBase .xQuotesMain'));}); setQuoteBindings(); } function toggleQuotes(prev){ $cur = $('.quote_visible'); if(prev){ $show = $cur.prev('.xquote'); if(!$show.length){$show= $('.xquote').last();} }else{ $show = $cur.next('.xquote'); if(!$show.length){$show= $('.xquote').first();} } index = $('.xquote').index($show); $('.quote_visible').removeClass('quote_visible'); $show.addClass('quote_visible'); $('.quotetoggle_count').html(index+1); } function xQuoteOptionsSkeleton(q){ var str = ""; if(mobile_template){return xQuoteOptionsSkeleton_mbt(q);} insertquotespan = "Einfügen:"; if(!parseInt(q.full)){ insertquotespan += "Zitat"; insertquotespan += " | "; insertquotespan += "Absatz"; insertquotespan += " | "; } insertquotespan += "Beitrag"; insertquotespan += ""; str = "
"+insertquotespan+"
"; return $(str); } function showXQuotesToInsert(){ $('#quotesToInsert').remove(); $div = $('
'); $.each(xquotes,function(){ var qdiv = xQuoteSkeleton(this,1); var $qdiv = $(qdiv); $quoteopts = xQuoteOptionsSkeleton(this); $qdiv.prependTo($div);$quoteopts.appendTo($qdiv); }); if(mobile_template == 'notset'){setMBT();} if(mobile_template){ $div.appendTo('#xQuotesInsertDiv'); }else{ $("
").appendTo($div); $div.appendTo('#xQuotesInsertDiv'); $("
").insertAfter($div); } $div.find('.xquote').first().addClass('quote_visible'); curcount = $div.find('.xquote').length; $quotetoggler = $('
« zurück1 von '+curcount +'weiter »
'); $quotetoggler.prependTo($div); $('#showSavedQuotesSpan').find('a').first().html('Aktualisieren') setQuoteBindings(); } function xQuoteSkeleton(quote){ if(mobile_template == 'notset'){setMBT();} if(mobile_template){return xQuoteSkeleton_mbt(quote);} $('#quoteInfoDiv').remove(); $('#clearlink').show(); var curtext = quote.quote_html; var qparams = quote.params ? quote.params : ""; var infospan = xQuoteInfoSkeleton(quote); var str = ""; str = "
"; str += "

"; str = str + curtext; str += "

"; str += "Zitat löschen"; str += ""+infospan+""; str += "
"; str += "
"; return str; } function xQuoteInfoSkeleton(quote){ var uname = quote.username ? quote.username : "Gast"; var curuser = " ";} curuser += uname; if(quote.user_link){curuser += "";} curuser += ""; return curuser } function xQuoteOptionsSkeleton_mbt(q){ var str = ""; insertquotespan = "
"; if(!parseInt(q.full)){ insertquotespan += ""; insertquotespan += ""; insertquotespan += ""; }else{ insertquotespan += ""; } insertquotespan += "
"; str = "

"+insertquotespan+"
"; return $(str); } function xQuoteSkeleton_mbt(quote){ $('#quoteInfoDiv').remove(); $('#clearlink').show(); var curtext = quote.quote_html; var qparams = quote.params ? quote.params : ""; var infospan = xQuoteInfoSkeleton_mbt(quote); var dellink = ""; var str = ""; str = "
"; str += "
"+dellink+""+infospan+"
"; str += "

"; str = str + curtext; str += "

"; str += "
"+dellink+"
"; str += "
"; str += "
"; return str; } function xQuoteInfoSkeleton_mbt(quote){ curuser = xobor.mbt.skeletons.userdiv_small(quote); var uname = (typeof quote.username !== 'undefined') ? quote.username : "Gast"; /* var curuser = " ";} curuser += uname; if(quote.user_link){curuser += "";} curuser += ""; */ curtime = ""; /* if(quote.timestamp){ date = dateFormat(quote.timestamp*1000,"d.m. H:i"); curtime = " | " + date + ""; }*/ return ""+curuser+""+"von "+uname+"" + curtime; } maxquotesfunction = function(){ var hidequotes = 0 if(quotes_loaded && $('.xQuotesMain').find('.xquote').length == 0){hidequotes = 1;} if(!hidequotes){ $(this).unbind('click'); $('.xQuotes.minimized').removeClass('minimized'); } if(!quotes_loaded){xgetQuotes();} } closeselfunction = function(){ $('body').click(function(event){ curclicked = $(event.target).attr('id'); if(curclicked != xselmenuid){ $(this).unbind('click'); $xselmenu.hide(); } } );} selfunction = function(event){ $xselmenu = $('#'+xselmenuid ); xsel = window.getSelection(); try{ xrange = xsel.getRangeAt(0); xselstart = xrange.startOffset; xselend = xrange.endOffset; xselparent = $(xrange.commonAncestorContainer).closest('.xquoteable')[0]; xselparent_para = $(xrange.commonAncestorContainer).closest('p')[0]; if(!$(xrange.commonAncestorContainer).closest('p').length){ /*Es gibt keinen umgebenden Paragraph, wir nehmen den Text der nächsten Div:*/ xselparent_para = $(xrange.commonAncestorContainer).closest('div')[0]; } }catch(e){xrange = false;} if($(xselparent).length && xrange.collapsed==false){ xselkey = $(xselparent).attr('id').replace("xquoteable_","")+"_s"+xselstart+"e"+xselend + "l" + parseInt(xselend - xselstart); if(!(xselkey == xlast_selection)){ cur_left_offset = xmouseX(event); cur_top_offset = xmouseY(event); xlast_selection = xselkey; $xselmenu.appendTo('body').css({'position':'absolute', 'top': cur_top_offset, 'left':cur_left_offset}).show(); t = setTimeout(closeselfunction,200); } } }; getSelectionHTML = function () { var userSelection; if (window.getSelection) { //non IE userSelection = window.getSelection (); if (userSelection.getRangeAt){ var range = userSelection.getRangeAt (0);} else { var range = document.createRange (); range.setStart (userSelection.anchorNode, userSelection.anchorOffset); range.setEnd (userSelection.focusNode, userSelection.focusOffset); } var clonedSelection = range.cloneContents (); var div = document.createElement ('div'); div.appendChild (clonedSelection); return div.innerHTML; } else if (document.selection) { //IE userSelection = document.selection.createRange (); return userSelection.htmlText; } else { return ''; } }; function savequotefunction(target_id){ var preRange; xsel = window.getSelection(); try{ xrange = xsel.getRangeAt(0); xselstart = xrange.startOffset; xselend = xrange.endOffset; xselparent = $(xrange.commonAncestorContainer).closest('.xquoteable')[0]; }catch(e){xselparent = false;} if(xselparent){ if($(xselparent).data("xselkey")){xselkey = $(xselparent).data("xselkey");} else{xselkey = $(xselparent).attr('id').replace("xquoteable_","");} xselkey += "_s"+xselstart+"e"+xselend + "l" + parseInt(xselend - xselstart); complete = 0; if(xselkey && $(xselparent).length && xrange.collapsed==false){ //get Current Selection HTML: var $next = $(xselparent).next(); var posthtml = $(xselparent).html(); var r_start_offset = xrange.startOffset; var r_end_offset = xrange.endOffset; var r_start_el = xrange.startContainer; var r_end_el = xrange.endContainer; //selection speichern selhtml = getSelectionHTML(); preRange = document.createRange(); preRange.setStart(xselparent, 0); preRange.setEnd(xrange.startContainer, xrange.startOffset); xsel.removeAllRanges(); xsel.addRange(preRange); preselhtml = getSelectionHTML(); //selected paragraph speichern xsel.removeAllRanges(); xrange2 = document.createRange(); xrange2.setStartBefore(r_start_el); xrange2.setEndAfter(r_end_el); xsel.addRange(xrange2); pselhtml = getSelectionHTML(); preRange = document.createRange(); preRange.setStart(xselparent, 0); preRange.setEnd(xrange.startContainer, xrange.startOffset); xsel.removeAllRanges(); xsel.addRange(preRange); ppreselhtml = getSelectionHTML(); xsel.removeAllRanges(); xsel.addRange(xrange); xrange.setStart(r_start_el,r_start_offset); xrange.setEnd(r_end_el,r_end_offset); } } else{ if(target_id){ xselparent = $('#'+target_id).find('.xquoteable')[0]; if($(xselparent).data("xselkey")){xselkey = $(xselparent).data("xselkey");} else{xselkey = $(xselparent).attr('id').replace("xquoteable_","")+"_full"; } selhtml = selpre=preselhtml=pselhtml =ppreselhtml=""; complete = 1; }else{ //no selection, no target id return; } } $.ajax({"type":"post","dataType":"json", url: xselsaveurl,data :{'action':'save', 'key':xselkey,'seltext':convertQuote2entity(selhtml),'selpre':convertQuote2entity(preselhtml),'pseltext':convertQuote2entity(pselhtml),'pselpre':convertQuote2entity(ppreselhtml), 'full':complete},success: function(res){ if(res.done){ if(quotes_loaded){ var qdiv = xQuoteSkeleton(res.quote); $(qdiv).addClass('qnew').prependTo($('#xQuotesBase .xQuotesMain')); curid = res.quote.id; setTimeout("$('#xquote_"+curid+"').removeClass('qnew')",2000); setQuoteBindings(); } setQuoteCount(res.count); if(res.count > 0){$('#xQuotesBase').removeClass('hidden').show();} if(replypage){ $('.qcount').html(res.count); if(quotes_loaded){xgetQuotes(1);} xInsertQuote(null,null,null,1,res.quote); } }else{alert('error');}}}); } function convertQuote2entity(utf8_string) { var html_entity = ""; for(i=0; i<=utf8_string.length; i++) { if(utf8_string.charCodeAt(i)>127){ html_entity += "&#" + utf8_string.charCodeAt(i) + ";"; }else{html_entity += utf8_string.charAt(i);} } return html_entity; }