var UserTagCache = {}; function LJUser(textArea) { var editor_frame = $(textArea + '___Frame'); if (!editor_frame) return; if (! FCKeditor_LOADED) return; if (! FCKeditorAPI) return; var oEditor = FCKeditorAPI.GetInstance(textArea); if (! oEditor) return; var html = oEditor.GetXHTML(false); if (html) html = html.replace(/<\/(lj|user)>/, ''); var regexp = /<(?:lj|user)( (?:user|name|site)=[^/>]+)\/?>\s?(?:<\/(?:lj|user)>)?\s?/g; var attrs_regexp = /(user|name|site)=['"]([.\w-]+?)['"]/g; var userstr; var users = []; var username; while ((users = regexp.exec(html))) { var attrs = []; var postData = { 'username': '', 'site': '' }; while (( attrs=attrs_regexp.exec(users[1]) )) { if (attrs[1] == 'user' || attrs[1] == 'name') postData.username = attrs[2]; else postData[attrs[1]] = attrs[2]; } var url = window.parent.Site.siteroot + "/tools/endpoints/ljuser"; var gotError = function(err) { alert(err+' '+username); return; } // trim any trailing spaces from the userstr // so that we don't get rid of them when we do the replace below var userStrToReplace = users[0].replace(/\s\s*$/, ''); var gotInfo = (function (userstr, username, site) { return function(data) { if (data.error) { alert(data.error+' '+username); return; } if (!data.success) return; if ( site ) data.ljuser = data.ljuser.replace(//,'
'); else data.ljuser = data.ljuser.replace(//,'
'); data.ljuser = data.ljuser.replace(/<\/span>\s?/,'
'); UserTagCache[username + "_" + site] = data.ljuser; html = html.replace(userstr,data.ljuser); oEditor.SetData(html); oEditor.Focus(); }})(userStrToReplace, postData.username, postData.site); if ( UserTagCache[postData.username+"_"+postData.site] ) { html = html.replace( userStrToReplace, UserTagCache[postData.username+"_"+postData.site] ); oEditor.SetData(html); oEditor.Focus(); } else { var opts = { "data": window.parent.HTTPReq.formEncoded(postData), "method": "POST", "url": url, "onError": gotError, "onData": gotInfo }; window.parent.HTTPReq.getJSON(opts); } } } function useRichText(textArea, statPrefix) { if ( $("switched_rte_on").value == '1' ) return; var rte = new FCKeditor(); var t = rte._IsCompatibleBrowser(); if (!t) return; if ($("insobj")) { $("insobj").className = 'on'; } if ($("jrich")) { $("jrich").className = 'on'; } if ($("jplain")) { $("jplain").className = ''; } if ($("htmltools")) { $("htmltools").style.display = 'none'; } var entry_html = $(textArea).value; entry_html = convertToHTMLTags(entry_html, statPrefix); if ($("event_format") && !$("event_format").checked) { entry_html = entry_html.replace(/\n/g, '
'); } var editor_frame = $(textArea + '___Frame'); // Check for RTE already existing. IE will show multiple iframes otherwise. if (!editor_frame) { var oFCKeditor = new FCKeditor(textArea); oFCKeditor.BasePath = statPrefix + "/fck/"; oFCKeditor.Height = 350; oFCKeditor.ToolbarSet = "Update"; $(textArea).value = entry_html; oFCKeditor.ReplaceTextarea(); } else { if (! FCKeditorAPI) return; var oEditor = FCKeditorAPI.GetInstance(textArea); editor_frame.style.display = "block"; $(textArea).style.display = "none"; oEditor.SetData(entry_html); oEditor.Focus(); // Hack for handling submitHandler oEditor.switched_rte_on = '1'; } // Need to pause here as it takes some time for the editor // to actually load within the browser before we can // access it. setTimeout("LJUser('" + textArea + "')", 2000); $("switched_rte_on").value = '1'; return false; // do not follow link } function usePlainText(textArea) { if ( $("switched_rte_on").value == '0' ) return; if (! FCKeditorAPI) return; var oEditor = FCKeditorAPI.GetInstance(textArea); if (! oEditor) return; var editor_frame = $(textArea + '___Frame'); var html = oEditor.GetXHTML(false); html = convertToTags(html); if ($("event_format") && !$("event_format").checked) { html = html.replace(/\
/g, '\n'); html = html.replace(/\(.*?)\<\/p\>/g, '$1\n'); html = html.replace(/ /g, ' '); } $(textArea).value = html; oEditor.Focus(); if ($("insobj")) $("insobj").className = ''; if ($("jrich")) $("jrich").className = ''; if ($("jplain")) $("jplain").className = 'on'; editor_frame.style.display = "none"; $(textArea).style.display = "block"; $('htmltools').style.display = "block"; $("switched_rte_on").value = '0'; // Hack for handling submitHandler oEditor.switched_rte_on = '0'; return false; } function convert_post(textArea) { if ( $("switched_rte_on").value == '0' ) return; var oEditor = FCKeditorAPI.GetInstance(textArea); var html = oEditor.GetXHTML(false); var tags = convert_poll_to_tags(html, true); $(textArea).value = tags; oEditor.SetData(tags); } function convert_to_draft(html) { if ( $("switched_rte_on").value == '0' ) return html; var out = convert_poll_to_tags(html, true); out = out.replace(/\n/g, ''); return out; } function convert_poll_to_tags (html, post) { var tags = html.replace(/
[^\b]*?<\/div>/gm, function (div, id){ return generate_poll(id, post) } ); return tags; } function generate_poll(pollID, post) { var poll = LJPoll[pollID]; var tags = poll.outputPolltags(pollID, post); return tags; } function convert_poll_to_HTML(plaintext) { var html = plaintext.replace(/<(?:lj-)?poll name=['"].*['"] id=['"]poll(\d+?)['"].*>[^\b]*?<\/(?:lj-)?poll>/gm, function (ljtags, id){ return generate_pollHTML(ljtags, id) } ); return html; } function generate_pollHTML(ljtags, pollID) { try { var poll = LJPoll[pollID]; } catch (e) { return ljtags; } var tags = "
"; tags += poll.outputHTML(); tags += "
"; return tags; } // Constant used to check if FCKeditorAPI is loaded var FCKeditor_LOADED = false; function FCKeditor_OnComplete( editorInstance ) { editorInstance.Events.AttachEvent( 'OnAfterLinkedFieldUpdate', doLinkedFieldUpdate) ; FCKeditor_LOADED = true; } function doLinkedFieldUpdate(oEditor) { var html = oEditor.GetXHTML(false); var tags = convertToTags(html); $('draft').value = tags; } function convertToTags(html) { // no site html = html.replace(/
.+?(\w+?)<\/b><\/a><\/div>/g, ''); // with site html = html.replace(/.+?(\w+?)<\/b><\/a><\/div>/g, ''); html = html.replace(/
(.+?)<\/div>/g, '$1'); html = html.replace(/
(.*?)<\/div>/gi, '$3'); html = html.replace(/(.*?)<\/div>/gi, '$3'); html = html.replace(/
(.+?)<\/div>/g, '$2'); html = html.replace(/
(.+?)<\/div>/g, '$2'); html = html.replace(/
(.+?)<\/div>/g, '$1'); html = convert_poll_to_tags(html); return html; } function convertToHTMLTags(html, statPrefix) { html = html.replace(/<(lj-)?cut text=['"](.+?)['"]>([\S\s]+?)<\/\1cut>/gm, '
$3
'); html = html.replace(/<(lj-)?cut>([\S\s]+?)<\/\1cut>/gm, '
$2
'); html = html.replace(/<(lj-raw|raw-code)>([\w\s]+?)<\/\1>/gm, '
$2
'); // Match across multiple lines and extract ID if it exists html = html.replace(/<(lj|site)-embed\s*(id="(\d*)")?\s*>\s*(.*)\s*<\/\1-embed>/gim, '
$4
'); html = convert_poll_to_HTML(html); return html; }