Best JavaScript code snippet using playwright-internal
attachment.js
Source:attachment.js
1if (typeof(font_size)=='undefined')2 var font_size = 16;3if (typeof(ResizeUploaded)=='undefined')4var ResizeUploaded =5{6attachref: null,7filetobedeleted: null,8savedfiletodelete: '',9uploadedattachmen: null,10uploadedresized: false,11pathcode: null,12filename: null,13picwidth: null,14picheight: null,15noattachindex: null,16noattachurl: null,17attachindex:null,18oldattachvalue:null,19alluploaded : '',20timestmp:0,21active:false,22butwidth:Math.round(4.5*font_size),23zip: function(str)24{25 var s = str.replace(/,$/,'').split(/,/);26 if (str.indexOf("|") > 0 || s.length ==1) 27 return str;28 var i=0;29 var l = s[0].lastIndexOf("@");30 while (true)31 {32 for (var j=1; j < s.length; j++)33 {34 var k = s[j].lastIndexOf("@");35 if (i+l+1 == s[0].length || i+k+1 == s[j].length || s[j].charAt(i+k+1) != s[0].charAt(i+l+1)) 36 break; 37 }38 if (j < s.length )39 {40 break;41 }42 else i++;43 }44 var y = s[0] + ",";45 for (var j=1; j < s.length; j++)46 {47 var k = s[j].lastIndexOf("@");48 var i=0;49 while ( i+l+1 < s[0].length && i+k+1 < s[j].length && s[j].charAt(i+k+1) == s[0].charAt(i+l+1)) 50 i++;51 if (i > 0)52 y += s[j].substring(0,k+1) + i + "|" + s[j].substring(i+k+1) + ","; 53 else54 y += s[j] + ",";55 }56 return y;57},58unzip : function(str)59{60 if (str == null) return str;61 if (typeof(str.tagName)!='undefined' && str.tagName.toLowerCase() == 'input')62 {63 str = str.value;64 }65 var s = str.replace(/,$/,'').split(/,/);66 if (str.indexOf("|") < 0 || s.length ==1) 67 return str;68 str = s[0] + ",";69 var l = s[0].lastIndexOf("@");70 for (var j=1; j < s.length; j++)71 {72 var k = s[j].indexOf("|");73 if (k < 0)74 str += s[j] + ","; 75 else76 {77 var m = s[j].lastIndexOf("@");78 var n = parseInt(s[j].substring(m+1,k));79 str += s[j].substring(0,m+1) + s[0].substring(l+1,l+n+1) + s[j].substring(k+1) + ",";80 }81 }82 return str;83}, 84widthnow:0,85heightnow:0,86xnow:0,87ynow:0, 88isimg:true,89fileinexam:null,90uploaded : function (z, fn,atc)91{92 93 var regloc = fn;94 var locat = document.location.toString();95 if (atc != null)96 {97 ResizeUploaded.attachref = atc;98 }99 100 if (z.length > 4)101 {102 regloc = locat.replace(/[^\\/]+$/, "FileOperation?did=" + z.substring(4));103 }104 var imgpath = "FileOperation?did=" + z.substring(4); 105 var tt = fn;106 ResizeUploaded.isimg = false;107 ResizeUploaded.noattachurl = regloc;108 ResizeUploaded.fileinexam = fn + '@'+ z.substring(4);109 if (ResizeUploaded.attachref!=null)110 {111 var xx = ResizeUploaded.unzip(ResizeUploaded.attachref.value); 112 var jj = ("," + xx ).indexOf("," + fn.replace(/@.*/, '@'));113 114 if ( jj < 0 )115 xx = ResizeUploaded.fileinexam + "," + xx;116 ResizeUploaded.attachref.value = ResizeUploaded.zip(xx);117 }118 /*119 //ResizeUploaded.oldattachvalue = ResizeUploaded.attachref.value; 120 ResizeUploaded.attachman(ResizeUploaded.attachref);121 */122 if (typeof(beforeclose)!='undefined') 123 window.onbeforeunload = beforeclose;124 var fen = fn.replace(/@.*/, '');125 var jj = fen.lastIndexOf(".");126 fen = fen.substring(jj + 1).toLowerCase();127 var ss = '';128 ResizeUploaded.pathcode = z.substring(4);129 ResizeUploaded.filename = fn;130 var wordfor = textmsg[1293].split(/@/);131 132 if ((fen == 'jpg' || fen == 'jpeg' || fen == 'gif' || fen == 'png') && z.length > 4 && (z.charAt(3) == '/' ))133 {134 // var hasfile = ResizeUploaded.attachref.value.indexOf("@" + fn.replace(/@.*/, '') + "@");135 var hasfile1 = -1;136 if (ResizeUploaded.attachref!=null)137 hasfile1 = ResizeUploaded.unzip(ResizeUploaded.attachref.value).indexOf("@" + fn.replace(/@.*/, '') + "@");138 139 var cancut = ResizeUploaded.attachref==null || hasfile1< 0;140 ResizeUploaded.isimg = true;141 ResizeUploaded.picwidth = 0;142 ResizeUploaded.picheight = 0;143 var wt = 4*ResizeUploaded.butwidth;144 if (cancut) wt += 3*ResizeUploaded.butwidth + 30;145 ss = "<table class=outset1 style=\"border-radius:3px;border:0px #d0d0d0 outset\" id=uploadinstru cellspacing=2 cellpadding=2 ><tr>";146 var s1 = '';147 var s2 = ''; var ii = 0;148 149 if (cancut) 150 { 151 ss += "<td><select id=resizesel style=\"width:" + ResizeUploaded.butwidth + "px;overflow:hidden;border:1px #b0b0b0 solid;margin:0px 0px 0px 0px;border-radius:3px\" onchange=ResizeUploaded.resizeonly(this,'" + z.substring(4) + "','" + fn + "')><option selected>100%</option>"152 + "<option>5%</option><option>10%</option><option>20%</option><option>25%</option><option>30%</option><option>40%</option><option>50%</option><option>75%</option>"153 + "<option>125%</option><option>150%</option><option>200%</option></select></td>";154 155 ss += "<td style=\"background-color:orange;color:white;border:1px #b0b0b0 outset;width:"+ ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.swapproc(this)\"><nobr>"+ textmsg[1295] + "</nobr></td>";156 157 //ss += "<td style=\"background-color:#BBBB00;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.cropshow(null)\"><nobr>"+ textmsg[1632] + "</nobr></td>";158 ss += "<td style=\"background-color:#BBBB00;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.cropuse()\"><nobr>"+ textmsg[1357] + "</nobr></td>";159 }160 161 ss += "<td style=\"background-color:#b0b0b0;color:white;border:1px #808080 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=ResizeUploaded.cropuse(1)><nobr>"+ textmsg[1359] + "</nobr></td>";162 ss += "<td style=\"background-color:white;color:black;border:1px #808080 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=ResizeUploaded.readbw()><nobr>"+ textmsg[1630] + "</nobr></td>";163 ss += "<td style=\"background-color:red;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.deleteit()\"><nobr>" + textmsg[69] + "</nobr></td>";164 if (document.location.toString().indexOf('talkpage.jsp')<0 && document.location.toString().indexOf('webfolder.jsp')<0 && typeof(Play)=='undefined')165 ss += "<td style=\"background-color:#BBBB00;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.cropuse(3)\"><nobr>" + textmsg[1303] + "</nobr></td>";166 ss += "<td style=\"background-color:#BBBB00;color:white;border:1px #b0b0b0 outset;font-weight:700;border-radius:3px;cursor:pointer\" align=center ><img height=" + (font_size + 4) + " src=image/nophoto.jpg onclick=\"ResizeUploaded.detectface()\"></td>";167 if (cancut && (ResizeUploaded.attachref==null ||ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(new RegExp(",[0-9][0-9]?@"+fn.replace(/@.*/,'')),"")== ResizeUploaded.unzip(ResizeUploaded.attachref.value))) 168 {169 ss += "<td><input id=rotatesel style=\"width:" + ResizeUploaded.butwidth + "px;overflow:hidden;border:1px #b0b0b0 solid;margin:0px 0px 0px 0px;border-radius:3px;width:30px\" onchange=ResizeUploaded.rotateonly(this,'" + z.substring(4) + "','" + fn + "') value=0 ></td><td>°</td>";170 } 171 else 172 {173 ss += "<td></td>";174 }175 ss += "</tr></table><img id=\"imgwork\" src=\"" + imgpath + "&tcode=" + (new Date()).getTime()%1000000000 + "\" style=\"margin:0px 0px 0px 0px\" onload=ResizeUploaded.goodposition(this)>";176 closeprompt();177 178 myprompt(ss, null, null, textmsg[1296]);179 if (promptwin!=null && promptwin.getElementsByTagName('table')!=null && promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')!=null)180 {181 promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[1].cells[0].style.padding = "0px 0px 0px 0px";182 promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[0].cells[0].getElementsByTagName('img')[0].onclick183 = function(){var b = document.getElementById("dragcropbox"); if (b!=null) document.body.removeChild(b);ResizeUploaded.cropuse();} 184 }185 //if (isu) ResizeUploaded.cropshow(document.getElementById('cropfield'));186 }187 else188 {189 190 ss = "<table class=outset1 style=\"border-radius:3px;border:0px #d0d0d0 outset\" id=uploadinstru cellspacing=2 cellpadding=2 ><tr>";191 ss += "<td style=\"background-color:#BBBB00;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.docuse()\">"+ textmsg[1357] + "</td>";192 ss += "<td style=\"background-color:red;color:white;border:1px #b0b0b0 outset;width:" + ResizeUploaded.butwidth + "px;font-weight:700;border-radius:3px\" align=center onclick=\"ResizeUploaded.deleteit()\"><nobr>" + textmsg[69] + "</nobr></td></tr>";193 ss += "</table>";194 myprompt(ss, null, null, wordfor[0]);195 promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[0].cells[0].getElementsByTagName('img')[0].onclick196 = function(){ResizeUploaded.docuse();}197 if (typeof (showattachment) != 'undefined') 198 {199 showattachment(ResizeUploaded.attachref.value);200 }201 202 //ResizeUploaded.alluploaded += ResizeUploaded.filename + '@' + ResizeUploaded.pathcode + ','; 203 }204 205},206detectface : function()207{208 /* var savedredourl = "UploadFace?pathcode=" + ResizeUploaded.pathcode + "&tcode=" + ResizeUploaded.filename.replace(/^[^@]+@/,"");209 if (typeof(startface) != 'undefined')210 savedredourl += "&CourseId=" + currentcid + "&Session=" + (numRows>0?mat[0][0]:defaultRecord[0]);211 window.open(savedredourl,'w'+tstmp);*/212 var xmlhttp;213 if (window.XMLHttpRequest)214 {215 xmlhttp = new XMLHttpRequest();216 }217 else218 {219 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");220 }221 xmlhttp.onreadystatechange = function()222 {223 if (xmlhttp.readyState == 4 && xmlhttp.status == 200)224 {225 var y = xmlhttp.responseText;226 if (y!=null && y!='')227 { 228 229 if (y.indexOf('<html>') > 0 && y.indexOf('<body ')>0)230 {231 var x= window.open('', 'w' + tstmp);232 x.document.write(y);233 }234 else eval(y);235 }236 }237 }238 var f = new FormData();239 f.append('pathcode',ResizeUploaded.pathcode);240 241 if (typeof(startface) != 'undefined' )242 { 243 f.append('CourseId', currentcid);244 f.append('Session', (numRows>0?mat[0][0]:defaultRecord[0]) );245 }246 xmlhttp.open('POST', "UploadFace", true);247 xmlhttp.send(f);248 249}, 250facedim : function (alln)251{252 var r = new RegExp(",[0-9]+@");253 var s = ResizeUploaded.unzip(ResizeUploaded.attachref.value);254 var k = 0;255 var m;256 var j = 0;257 while ( (m = r.exec(s.substring(k))) != null)258 {259 j = parseInt(m.toString().replace(/[^0-9]/g, ''));260 k += m.index + m.toString().length;261 }262 if (alln == '') return;263 var ns = alln.replace(/,$/,'').split(/,/) ;264 var imgs = '<table><tr>';265 var ww = 0; 266 var had = false;267 for (var i=0; i <= ns.length-4; i+=4)268 {var w = parseInt( ns[i+2]);var h = parseInt( ns[i+3])269 var x = parseInt( ns[i]) - Math.round(0.13*w);270 var y = parseInt( ns[i+1]) - Math.round(0.25*h);271 w += Math.round(0.26*w);272 h += Math.round(0.5*h);273 ww += w;274 if (ww > 720){imgs += '</tr></table><table><tr>'; ww = w;had = true;} 275 imgs += '<td><table><tr height=' + h + '><td width=' +w +' style="background-image:url(FileOperation?did='+276 ResizeUploaded.pathcode + ');background-position:-' + x + 'px -' + y + 'px" > </td></tr></table></td>';277 s = s + (++j) + "@" + ResizeUploaded.filename.replace(/@.*/,'') + "@" + x + "_" + y + "_" + w + "_" + h + ",";278 }279 ResizeUploaded.attachref.value = ResizeUploaded.zip(s);280 myprompt(imgs + '</tr></table>');281 if (had)282 promptwin.style.width = '740px';283 else 284 promptwin.style.width = (ww+30) + 'px';285 //ResizeUploaded.attachman(ResizeUploaded.attachref);286},287goodposition:function(im)288{289 290 if (ResizeUploaded.ynow + im.height + 60 > ResizeUploaded.heightnow)291 {292 ResizeUploaded.ynow = ResizeUploaded.heightnow - im.height - 60;293 if (ResizeUploaded.ynow < 0) ResizeUploaded.ynow = 0;294 }295 296 if (ResizeUploaded.xnow + im.width + 5 > ResizeUploaded.widthnow)297 {298 ResizeUploaded.xnow = ResizeUploaded.widthnow - im.width - 5;299 if (ResizeUploaded.xnow < 0) ResizeUploaded.xnow = 0;300 }301 302 promptwin.style.top = document.body.scrollTop + 'px';// ResizeUploaded.ynow + 'px';303 promptwin.style.left = ResizeUploaded.xnow + 'px'; 304},305deleteit : function()306{307 var usefield = document.getElementById("usefield");308 if (usefield!=null)309 {310 usefield.selectedIndex = 0;311 }312 var url = "UploadChangePic?pathcode=" + ResizeUploaded.pathcode + "&tcode=" + (ResizeUploaded.filename.replace(/^[^@]+@/,""));313 314 postopen(url,"w" + tstmp);315 //closeprompt();316 317},318readbw : function()319{320 321 var pic = document.getElementById('imgwork');322 var p = pic.parentNode;323 p.insertBefore(document.createTextNode(textmsg[1631]),pic);324 var btn = document.createElement('input');325 btn.className = 'OrangeButton';326 btn.style.cssText = 'width:' + ResizeUploaded.butwidth + 'px;align:center';327 btn.type='button';328 btn.value = textmsg[848];329 btn.onclick = function(){ResizeUploaded.cropuse(2)};330 p.insertBefore(btn,pic);331 btn = document.createElement('input');332 btn.className = 'GreenButton';333 btn.style.cssText = 'width:' + ResizeUploaded.butwidth + 'px;align:center';;334 btn.type='button';335 btn.value = textmsg[849];336 btn.onclick = function(){var pic = document.getElementById('imgwork');var p = pic.parentNode;p.removeChild(pic.previousSibling);p.removeChild(pic.previousSibling);p.removeChild(pic.previousSibling);};337 p.insertBefore(btn,pic);338 ///myprompt(textmsg[1631], null, "if(v) ResizeUploaded.cropuse(2)", textmsg[1630]); 339},340docuse : function()341{342 //if (typeof(showattachment)!='undefined')343 // showattachment(ResizeUploaded.zip(ResizeUploaded.alluploaded)); 344 closeprompt();345},346dosplitnow: false,347cropuse : function(bw)348 {349 //if (typeof(showattachment)!='undefined') showattachment(allentries);350 ResizeUploaded.dosplitnow = false;351 if (bw!=null && bw==3)352 {353 ResizeUploaded.dosplitnow = true;354 bw =null;355 }356 357 var needsubmit = (bw!=null);358 var url = "UploadChangePic?pathcode=" + ResizeUploaded.pathcode + "&tcode=" + ResizeUploaded.filename.replace(/^[^@]+@/,"");359 var b = null;360 361 var pic = document.getElementById('imgwork');362 var XY = findPositionnoScrolling(pic);363 var w = pic.offsetWidth;364 var h = pic.offsetHeight;365 //needsubmit = false; 366 if (ResizeUploaded.uploadedresized)367 {368 needsubmit = true;369 url += "&rwidth=" + w + "&rheight=" + h;370 }371 b = document.getElementById("dummycenter");372 if ( b != null)373 {374 var cw = b.offsetWidth;375 var ch = b.offsetHeight;376 var xy = findPositionnoScrolling(b);377 xy[0] -= XY[0];378 xy[1] -= XY[1];379 if (xy[0] < 0)380 xy[0] = 0;381 if (xy[1] < 0)382 xy[1] = 0;383 if (cw < w && ch < h)384 { 385 url += "&cropx=" + xy[0] + "&cropy=" + xy[1] + "&cwidth=" + cw + "&cheight=" + ch;386 needsubmit = true;387 }388 }389 if (typeof(showattachment)!='undefined')390 showattachment(ResizeUploaded.attachref.value);391 if (typeof(beforeclose)!='undefined') 392 window.onbeforeunload = beforeclose;393 394 if (needsubmit) 395 {396 if (bw!=null) url += "&whiteblack="+bw;397 398 savedredourl = url;399 window.open(url, "w" + tstmp);400 }401 402 403 404 if ( b!= null) 405 b.parentNode.removeChild(b);406 if (!needsubmit && ResizeUploaded.dosplitnow) 407 {408 ResizeUploaded.cutoff(); 409 }410 else411 closeprompt();412 },413 414 415resizeonly : function (sel )416{417 418 var box = document.getElementById("dragcropbox");419 420 if (sel.selectedIndex < 0)421 return;422 var p = parseInt(sel.options[sel.selectedIndex].text.replace(/%/, ''));423 var pic = document.getElementById('imgwork');424 if (ResizeUploaded.picwidth == 0 || ResizeUploaded.picheight == 0) 425 {426 ResizeUploaded.picwidth = pic.width;427 ResizeUploaded.picheight = pic.height;428 }429 var w = Math.round(p * ResizeUploaded.picwidth / 100);430 var h = Math.round(p * ResizeUploaded.picheight / 100);431 432 pic.style.width = w + 'px';433 pic.width = w;434 pic.style.height = h + 'px';435 pic.height = h;436 437 var w0 = document.getElementById("uploadinstru").offsetWidth;438 setRoundedSize(promptwin, (w0>w?w0:w), h+40) ;439 ResizeUploaded.uploadedresized = (p!=100);440 441},442rotateonly : function (edt,z,fn)443{444 if(typeof(rdapname)=='undefined') var rdapname = 'assign';445 var url = "UploadChangePic?pathcode=" + z + "&rdap=" + rdapname + "&tcode=" + fn.replace(/^[^@]+@/,"");446 url += "&rwidth=-1&rheight=" + (edt.value);447 savedredourl = url;448 window.open(url, "w" + tstmp);449},450swapproc : function(td)451{452 453 var tr = td.parentNode;454 var tds = tr.cells;455 var len = tds.length;456 457 if (td.innerHTML.replace(/<[^>]+>/g,'') == textmsg[1295])458 {459 460 ResizeUploaded.cropshow(td);461 462 td.innerHTML = "<nobr>" + textmsg[1645] + "</nobr>";463 464 for (var j = len - 1; j > len - 6; j--)465 {466 if (tds[j].innerHTML.replace(/<[^>]+>/g,'') == textmsg[1357])467 break;468 tds[j].style.visibility = 'hidden';469 }470 }471 else472 {473 td.innerHTML = "<nobr>" + textmsg[1295] + "</nobr>";474 var box = document.getElementById("dragcropbox");475 if (box != null) document.body.removeChild(box);476 for (var j = len - 1; j > len - 6; j--)477 {478 if (tds[j].innerHTML.replace(/<[^>]+>/g,'') == textmsg[1357]) break;479 tds[j].style.visibility = 'visible';480 }481 }482},483cropshow : function (sel)484{485 var box = document.getElementById("dragcropbox");486 if (box != null)487 document.body.removeChild(box);488 var k = -1;489 if (sel!=null && sel.tagName.toUpperCase()=='SELECT') 490 k = parseInt(sel.options[sel.selectedIndex].value);491 var w = 100, h =100;492 if (k > -1)493 {494 w = parseInt('' + fsize[k]);495 if (''+w == 'NaN') w = 100;496 if (ffsize[k] == null || ffsize[k] == '' || isNaN(ffsize[k]))497 {498 h = w;499 }500 else501 {502 h = parseInt('' + ffsize[k]);503 }504 }505 else506 {507 var pic = document.getElementById('imgwork');508 if (pic!=null && pic.width >0 && pic.height > 0)509 { 510 w = Math.round(pic.width * 0.7);511 h = Math.round(pic.height * 0.7);512 } 513 }514 515 if (k>=0 && k < numCols)516 {517 var usefield = document.getElementById("usefield");518 if (usefield!=null)519 {520 for (var i=0; i < usefield.options.length; i++)521 if (usefield.options[i].value == k)522 {523 usefield.selectedIndex = i;524 break;525 } 526 }527 }528 ResizeUploaded.showframe(w, h );529},530showframe : function(w, h )531{532 533 var pic = document.getElementById('imgwork');534 var xy = findPositionnoScrolling(pic);535 if (1==2 && (h > pic.offsetHeight && pic.offsetHeight > 0 || w > pic.offsetWidth && pic.offsetWidth>0 ))536 {537 var ro = (h / pic.offsetHeight);538 if (ro < w / pic.offsetWidth)539 ro = w / pic.offsetWidth;540 var ww = Math.ceil(ro * pic.offsetWidth + 2);541 var hh = Math.ceil(ro * pic.offsetHeight + 2);542 pic.height = hh;543 pic.width = ww;544 pic.style.height = hh + 'px';545 pic.style.width = ww + 'px';546 547 }548 var z = 21;549 if (typeof (promptwin.style.zIndex) != 'undefined')550 z = promptwin.style.zIndex;551 if (typeof (pic.style.zIndex) != 'undefined' && z < pic.style.zIndex)552 z = pic.style.zIndex;553 var box = document.createElement("div");554 box.id = "dragcropbox";555 box.style.cssText = "position:absolute;left:" + xy[0] + "px;top:" + xy[1]556 + "px;z-index:" + (z + 1) + ";background-color:transparent;border:1px #909090 broken;align:center;vertial-align:middle";557 box.innerHTML = round1('100%') + "<div id=dummycenter style=\"background-color:#eee;opacity:0.3;width:" + w + "px;height:" + h + "px;border-radius:3px\"></div>" + round2 ;558 document.body.appendChild(box);559 box.getElementsByTagName('table')[0].cellPadding='0';560 box.getElementsByTagName('table')[0].cellSpacing='0';561 box.getElementsByTagName('table')[0].rows[2].cells[2].innerHTML = "<div><img src=image/diskbg.png></div>"562 new ResizeRounded(box,ResizeUploaded.resizeblank);563 Drag.init(box.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('div')[0], box);564},565 566moveTo :function(r)567{568 var box = document.getElementById("dragcropbox");569 var pic = document.getElementById("imgwork");570 var dox = document.getElementById("dummycenter");571 var w0 = dox.offsetWidth;572 var h0 = dox.offsetHeigh;573 if (w0 > r[2])574 {575 dox.style.width = ( r[2]) + 'px';576 dox.parentNode.width = r[2];577 dox.parentNode.parentNode.parentNode.width = ( r[2]+24);578 box.style.width = ( r[2]+24) + 'px'; 579 }580 else581 {582 box.style.width = ( r[2]+24) + 'px'; 583 dox.parentNode.parentNode.parentNode.width = ( r[2]+24);584 dox.parentNode.width = r[2];585 dox.style.width = ( r[2]) + 'px';586 }587 if (h0 > r[3])588 {589 dox.style.height = ( r[3]) + 'px';590 dox.parentNode.parentNode.height = r[3];591 592 box.style.height = ( r[3]+24) + 'px'; 593 }594 else595 {596 box.style.height = ( r[3]+24) + 'px'; 597 dox.parentNode.parentNode.height = ( r[3]);598 dox.style.height = ( r[3]) + 'px';599 }600 601 var xy = findPositionnoScrolling(pic);602 box.style.left = (xy[0] + r[0]) + 'px';603 box.style.top = (xy[1] + r[1]) + 'px';604 605},606resizeblank : function(td, dx, dy)607{608 var b = document.getElementById('dummycenter');609 var d = document.getElementById('dragcropbox');610 if (dx > 0)611 {612 d.style.width = (d.offsetWidth + dx) + 'px';613 b.style.width = (b.offsetWidth + dx) + 'px';614 }615 else616 {617 b.style.width = (b.offsetWidth + dx) + 'px';618 d.style.width = (d.offsetWidth + dx) + 'px';619 }620 621 if (dy > 0)622 {623 d.style.height = (d.offsetHeight + dy) + 'px';624 b.style.height = (b.offsetHeight + dy) + 'px';625 }626 else627 {628 b.style.height = (b.offsetHeight + dy) + 'px';629 d.style.height = (d.offsetHeight + dy) + 'px';630 }631 632},633updatepic : function()634{635 var pic = document.getElementById('imgwork');636 if (pic!=null)637 {638 var s = pic.src;639 pic.src = s;640 }641},642setattachref : function(x)643{644 if( x != ResizeUploaded.attachref)645 ResizeUploaded.attachref = x;646},647getattachref : function ()648{649 return ResizeUploaded.attachref;650},651setfiletobedel : function (filename)652{653 ResizeUploaded.filetobedeleted = filename;654},655updateattch : function ()656{657 658 if ( ResizeUploaded.filetobedeleted ==null) return;659 660 if (ResizeUploaded.attachref != null )661 {662 var x = ResizeUploaded.unzip(ResizeUploaded.attachref.value);663 if (x.indexOf('@')<0) x = '';664 var x0 = ResizeUploaded.attachref.value;665 var j = x.indexOf(ResizeUploaded.filetobedeleted + ",");666 var k = ResizeUploaded.filetobedeleted.length + 1;667 if (ResizeUploaded.attachref.value.replace(/[^,]/g,'').length < 2 && k>1)668 {669 ResizeUploaded.attachref.value = ''; 670 }671 else672 {673 if (j> 0)674 x = x.substring(0,j) + x.substring(j+k);675 else if(j == 0)676 x = x.substring(k);677 if (ResizeUploaded.ifdelfilealso) 678 {679 var y = '@' + ResizeUploaded.filetobedeleted.replace(/@.*/,'') + "@";680 var z = '', j =0, k =0;681 while ( (k = x.indexOf(y)) > 0)682 {683 x = x.substring(0,k) + ( k+y.length < x.length? x.substring(k+y.length) : '');684 }685 x = x.replace(/,[0-9|_]+,/g,',').replace(/^[0-9|_]+,$/g,',');686 }687 ResizeUploaded.ifdelfilealso = false;688 ResizeUploaded.attachref.value = ResizeUploaded.zip(x);689 }690 691 } 692 693 x = ResizeUploaded.unzip(ResizeUploaded.attachref.value);694 695 var j = x.indexOf(ResizeUploaded.filetobedeleted + ",");696 var k = ResizeUploaded.filetobedeleted.length + 1;697 if (j> 0)698 x = x.substring(0,j) + x.substring(j+k);699 else if (j == 0)700 x = x.substring(k);701 ResizeUploaded.attachref.value = ResizeUploaded.zip(x);702 703 if (typeof(showattachment)!='undefined')704 showattachment(x);705 ResizeUploaded.filetobedeleted = null;706},707openmid : function(url,x,y)708{709 if (x==null) 710 x= '300';711 else 712 x = Math.round(x);713 if (y == null) 714 y = '300';715 else716 y = Math.round(y);717 myprompt('<iframe src="' + url + '" width=' + x + " height=" + y + " />");718 //window.open(url,'winname', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+x +',height=' +y +',top=' +(screen.height-y)/2+',left=' + (screen.width-x)/2);719 720},721refreshatt : function()722{723 closeprompt();724 ResizeUploaded.updateattch();725 ResizeUploaded.attachman(ResizeUploaded.attachref);726},727ifdelfilealso : false,728 729deleteAttachedFile : function (file)730{731 732 var xs = file.split(/@/);733 ResizeUploaded.setfiletobedel(file);734 if (xs.length==2 && xs[1].indexOf('http')==0)735 {736 var parse = new CSVParse(ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(/,$/,''),"'", "@",",").nextMatrix();737 var ss = '';738 for (var i=0; i < parse.length; i++)739 if (parse[i].length==2 && parse[i][0]==xs[0] && parse[i][1].indexOf('http')==0740 ||parse[i].length==3 && !isNaN(parse[i][0])&& parse[i][1]==xs[0]&& parse[i][2].replace(/[0-9]/g,'')=='___')741 ;742 else if (parse[i].length == 3)743 ss += parse[i][0] + '@' + parse[i][1] + '@' + parse[i][2] + ',';744 else 745 ss += parse[i][0] + '@\'' + parse[i][1] + '\',';746 ResizeUploaded.attachref.value = ResizeUploaded.zip(ss);747 ResizeUploaded.attachman(ResizeUploaded.attachref);748 }749 else if (xs[2] ==null || xs[2].length < 2 || xs[1] == null || xs[1].replace(/[0-9]/g,'')!='')750 {751 syn('del',xs[2]);752 }753 else754 {755 ResizeUploaded.ifdelfilealso = false;756 ResizeUploaded.savedfiletodelete ="UploadChangePic?pathcode=" + xs[2] + '&tcode=' + xs[1];757 var mm = textmsg[809] + "?";758 if (xs[0].toLowerCase().indexOf('.jpg') >0 || xs[0].toLowerCase().indexOf('.png') >0 || xs[0].toLowerCase().indexOf('.gif') >0759 || xs[0].toLowerCase().indexOf('.pdf') >0)760 mm += "<br><input type=checkbox name=ifdeletefile onclick=\"ResizeUploaded.ifdelfilealso=this.checked\">" + textmsg[1601];761 myprompt(mm,null,"ResizeUploaded.delgoahead(v)");762 }763 764},765showback : function()766{767 ResizeUploaded.attachman(ResizeUploaded.attachref);768},769delgoahead : function(v)770{771 772 if (v == false) 773 ResizeUploaded.showback();774 else775 {776 savedredourl = ResizeUploaded.savedfiletodelete;777 nav1 = window.open(ResizeUploaded.savedfiletodelete,'w' + tstmp);778 }779 closeprompt();780},781openAttachedFile : function(codedpath, filename)782{783 var fn= filename.toLowerCase();784 var dd = (fn.indexOf('.gif')>=0 || fn.indexOf('.jpg')>=0 || fn.indexOf('.jpeg')>=0 || fn.indexOf('.png')>=0);785 if(dd == false)786 {787 var fsnd1 = document.getElementById("openfileform_id");788 if ( fsnd1 == null)789 {790 fsnd1 = document.createElement("form");791 fsnd1.name = "openfileform";792 fsnd1.id = "openfileform_id";793 if (codedpath.indexOf('http://') == 0 || codedpath.indexOf('https://') == 0)794 formnewaction(fsnd1,codedpath);795 else796 formnewaction(fsnd1,"FileOperation");797 fsnd1.method = 'post';798 fsnd1.target = "_blank" ;799 fsnd1.innerHTML = "<input type=hidden name=did><input type=hidden name=operation value=open>";800 document.body.appendChild(fsnd1);801 }802 fsnd1.did.value = codedpath;803 formnewaction(fsnd1);804 805 visual(fsnd1);806 fsnd1.submit();807 }808 else 809 {810 var showarea = document.getElementById('codeshow');811 showarea.style.padding = "0px 0px 0px 0px";812 showarea.innerHTML = "<img src=" + ResizeUploaded.goodopenurl(codedpath,false) + " onload=\"ResizeUploaded.fitting(this)\" style=\"margin:0px 0px 0px 0px\" >";813 var tbl = document.getElementById('attachaction');814 815 for (var k=1; k <= 4; k++)816 tbl.rows[0].cells[k].width = ResizeUploaded.butwidth + 'px';817 tbl.rows[0].cells[0].width = '120px';818 //openpicorfile(codedpath}, filename);819 }820},821tobewritten:'',822fitting: function(im)823{824 if (promptwin.offsetWidth < im.width + 21)825 promptwin.style.width = (im.width + 21) + 'px'; 826},827goodopenurl:function(codepath,tail)828{829 if (codepath.indexOf('http://') == 0 || codepath.indexOf('https://') == 0)830 {831 return codepath;832 }833 else834 {835 var st= "FileOperation?did=" + codepath;836 if (tail==null||tail==true) st += "&tcode=" + (new Date()).getTime()%1000000000;837 return st;838 } 839},840gettobewritten : function()841{842 return ResizeUploaded.tobewritten; 843 844}, 845showwfhint : function ()846{847 document.getElementById('codeshow').innerHTML = textmsg[1667];848},849folder0:null,850sort:function(files, timest, urls, codedpath)851{852 var a = [];853 for (var j=0; j < files.length; j++)854 {855 if (!isNaN(timest[j]) && urls[j] == null && codedpath[j] !=null && codedpath[j].length>14)856 {857 a[a.length] = [files[j], timest[j], codedpath[j]];858 for (var k=0; k < files.length; k++)859 {860 if (timest[k] == files[j] && !isNaN(files[k]) &&codedpath[k]!=null && !isNaN(codedpath[k].replace(/_/,'')) )861 a[a.length] = [files[k], timest[k], codedpath[k]];862 }863 }864 }865 for (var j=0; j < files.length; j++)866 {867 if ( timest[j] == null && urls[j] != null && codedpath[j] ==null )868 {869 a[a.length] = [files[j],null, urls[j]];870 for (var k=0; k < files.length; k++)871 {872 if (timest[k] == files[j] && !isNaN(files[k]) && codedpath[k]!=null && !isNaN(codedpath[k].replace(/_/,'')) )873 a[a.length] = [files[k], timest[k], codedpath[k]];874 }875 }876 }877 for (var i=0; i < a.length; i++)878 {879 files[i] = a[i][0];880 timest[i] = a[i][1];881 codedpath[i] = a[i][2];882 }883},884attachman : function(attach_h)885{886 if (ResizeUploaded.folder0!=null) 887 {888 ResizeUploaded.initfolder = ResizeUploaded.folder0;889 ResizeUploaded.folder0 = null;890 ResizeUploaded.selicon();891 return;892 }893 if (attach_h !=null) 894 ResizeUploaded.attachref = attach_h;895 else896 attach_h =ResizeUploaded.attachref;897 var dbgcolor = "lightyellow", ibgcolor="teal", bbgcolor = "grey", tbgcolor="white";898 if (typeof(DBGCOLOR) != "undefined")899 dbgcolor = DBGCOLOR;900 if (typeof(IBGCOLOR) != "undefined")901 ibgcolor = IBGCOLOR;902 if (typeof(BBGCOLOR) != "undefined")903 bbgcolor = BBGCOLOR;904 if (typeof(TBGCOLOR) != "undefined")905 tbgcolor = TBGCOLOR;906 907 var encoding1 = "utf-8";908 if (typeof(encoding) != "undefined")909 encoding1 = encoding;910 911 var selectedfiles = "";912 913 var ss = "";914 var nav = null;915 var allentries = ResizeUploaded.unzip(attach_h.value);916 917 918 if (allentries.replace(/ /g,'').length < 2)919 {920 var tt = "";921 if (typeof(uploadfile) == 'function') tt = ". <a href=javascript:uploadfile() >" + textmsg[294] + "</a>";922 ss = "<center>";923 if (ResizeUploaded.initfolder!=null)924 ss += "<a href=\"javascript:ResizeUploaded.selicon()\">" + textmsg[675] + "</a> "; 925 ss += "<a href=\"javascript:ResizeUploaded.asraw()\"> " + textmsg[1614].replace(/[^:]+:/,'') +" </a> <a href=javascript:ResizeUploaded.showwfhint()><!--[?]--></a></center>" + textmsg[89]+ tt + "<br><div id=codeshow></div>";926 myprompt(ss,null,null,textmsg[787]);927 //if (typeof(showattachment)!='undefined') showattachment('');928 return;929 }930 931 var fparse = new CSVParse(allentries.replace(/,$/,''),"'","@", ",").nextMatrix();932 var files = new Array();933 var timest = new Array();934 var urls = new Array(); 935 var codedpath = new Array();936 for (var i=0; i < fparse.length; i++)937 {938 files[i] = fparse[i][0];939 if (fparse[i].length==2)940 {941 urls[i] = fparse[i][1];942 }943 else 944 {945 timest[i] = fparse[i][1];946 codedpath[i] = fparse[i][2];947 }948 }949 ResizeUploaded.sort(files, timest, urls, codedpath);950 var maxcols = 3; 951 var wt = 150 + 4*ResizeUploaded.butwidth;952 ss += "<center>"; 953 if (ResizeUploaded.initfolder!=null)954 ss += "<a href=\"javascript:ResizeUploaded.selicon()\">" + textmsg[675] + "</a> "; 955 956 if (typeof(haswebfolder)!='undefined' && haswebfolder || typeof(allShapes)!= 'undefined')957 {958 ss += "<a href=\"javascript:ResizeUploaded.asraw()\">" + textmsg[1614].replace(/[^:]+:/,'') +" </a> <a href=javascript:ResizeUploaded.showwfhint()><!--[?]--></a></center>"; 959 }960 ss += "<form name=form1 style=\margin:0px 0px 0px 0px\"><table id=\"attachaction\" cellpadding=2 cellspacing=2 border=0 class=outset1 style=\"border:0px #b0b0b0 outset;border-radius:3px;margin:3px 3px 3px 3px\" align=center >";961 962 var maps = new Array();963 964 for (i =0; i < files.length; i++)965 {966 if (files[i]==null||files[i]==''||codedpath[i] ==null) continue;967 if (isNaN(files[i]) == false && codedpath[i].replace(/[0-9]/g,"")=="___")968 {969 970 ss += "<tr><td style=\"border:1px #c0c0c0 solid;\"><nobr><a href=\"javascript:";971 ss += "ResizeUploaded.openImagelet('" + timest[i]+ "','" + codedpath[i] + "')\">" + textmsg[1303] + files[i] + "</a></nobr></td>";972 ss+= "<td class=GreenButton style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" align=center onclick=\"";973 ss += "ResizeUploaded.infoImage('" + timest[i] + "','" + codedpath[i] + "')\"><nobr>" + textmsg[1605] +"</nobr></td>";974 var bb = true;//typeof(issubmit)!='undefined' && issubmit == true || rdapname.indexOf( 'grading') >=0 || rdapname == 'assignedit' || rdapname.toLowerCase().indexOf("message") >= 0;975 976 ss+= "<td class=GreenButton style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" align=center onclick=\"";977 ss += "ResizeUploaded.insertImagelet('" + files[i] + "')\"><nobr>" + textmsg[1604] +"</nobr></td>";978 ss+= "<td class=OrangeButton style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" align=center onclick=\"";979 ss += "ResizeUploaded.cutoff('" + maps[timest[i]] + "','" + timest[i] + "','" + codedpath[i] + "'," + files[i] + ")\"><nobr>" + textmsg[1603] +"</nobr></td>";980 ss+= "<td class=RedButton style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" align=center onclick=\"";981 ss += "ResizeUploaded.deleteImagelet('" + files[i] + '@'+timest[i] + "')\"><nobr>" + textmsg[69] +"</nobr></td>";982 ss += "<td></td></tr>";983 }984 else 985 {986 ss += "<TR ><td style=\"border:1px #c0c0c0 solid;\"><nobr><a href=\"javascript:";987 ss += "ResizeUploaded.openAttachedFile('" + codedpath[i] + "','" + files[i] + "')\">" + files[i] + "</a></nobr></td>";988 ss+= "<td class=GreenButton style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" align=center onclick=\"";989 ss += "ResizeUploaded.urlAttachedFile('" + codedpath[i] + "')\"><nobr>" + textmsg[546] +"</nobr></td>";990 var bb = true;//typeof(issubmit)!='undefined' && issubmit == true || rdapname.indexOf( 'grading') >=0 || rdapname == 'assignedit' || rdapname.toLowerCase().indexOf("message") >= 0;991 992 var jj = files[i].lastIndexOf(".");993 var fen = files[i].substring(jj + 1).toLowerCase();994 995 if (fen == 'jpg' || fen == 'jpeg' || fen == 'gif' || fen == 'png') 996 {997 maxcols = 5;998 if (timest[i]!=null ){999 if (allentries.indexOf("@" + files[i] + "@")<0)1000 {1001 ss += "<td style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" class=OrangeButton align=center onclick=\"";1002 ss += "ResizeUploaded.uploaded('web/" + codedpath[i] + "','" + files[i] + '@' + timest[i] + "')\"><nobr>" + textmsg[1294] +"</nobr></td>";1003 }1004 else 1005 {1006 ss += "<td style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" class=OrangeButton align=center onclick=\"";1007 ss += "ResizeUploaded.uploaded('web/" + codedpath[i] + "','" + files[i] + '@' + timest[i] + "')\"><nobr>" + textmsg[1294] +"</nobr></td>";1008 }}1009 else ss += "<td></td>";1010 //// ss += "<td width=" + Math.round(4.5*font_size) +" class=OrangeButton style=\"width:70px\" align=center onclick=\"";1011 // ss += "ResizeUploaded.codeAttachedFile('" + codedpath[i] + "')\"><nobr>" + textmsg[1303] +"</nobr></td>";1012 ss += "<td style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" class=OrangeButton align=center onclick=\"";1013 ss += "ResizeUploaded.cutoff('" + codedpath[i] + "','" + files[i]+ "')\"><nobr>" + textmsg[1303] +"</nobr></td>"; 1014 maps[files[i]] = codedpath[i];1015 }1016 else1017 {1018 if (typeof(DBGCOLOR) == 'undefined') DBGCOLOR = "white";1019 ss += "<td colspan=2 style=background-color:" + DBGCOLOR +"></td>"; 1020 }1021 if (timest[i]!=null)1022 {1023 ss+= "<td style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" class=RedButton align=center onclick=\"";1024 ss += "ResizeUploaded.deleteAttachedFile('" + files[i] + '@'+timest[i] +'@' + codedpath[i] + "')\"><nobr>" + textmsg[69] +"</nobr></td>";1025 }1026 else1027 {1028 ss+= "<td style=\"width:" + ResizeUploaded.butwidth + "px !important;border-radius:3px\" class=RedButton align=center onclick=\"";1029 ss += "ResizeUploaded.deleteAttachedFile('" + files[i] + '@' + codedpath[i] + "')\"><nobr>" + textmsg[69] +"</nobr></td>";1030 1031 }1032 ss += "<td></td></tr>" ;1033 }1034 }1035 ss += ("<tr><td colspan=" + (maxcols+1) + " id=codeshow><br></td></tr></table></form>" );1036 1037 1038 {1039 myprompt(ss,null,null, textmsg[787] );1040 if (promptwin!=null) 1041 {1042 var zz = promptwin.getElementsByTagName('table')[0];1043 if (zz!=null && zz.rows.length > 1)1044 {1045 zz = zz.rows[1].cells[1].getElementsByTagName('table')[0];1046 if (zz.rows!=null && zz.rows.length > 1)1047 {1048 zz.rows[1].cells[0].style.padding = "0px 0px 0px 0px";1049 }1050 }1051 1052 }1053 }1054 ResizeUploaded.xnow = parseInt(promptwin.style.left.replace(/px/,''));1055 ResizeUploaded.ynow = parseInt(promptwin.style.top.replace(/px/,''));1056 ResizeUploaded.widthnow = document.body.scrollWidth;1057 ResizeUploaded.heightnow = document.body.scrollHeight;1058 1059},1060 1061updatecell:function()1062{1063 var p = new CSVParse(ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(/,$/,''), '\'', '@',',');1064 var y = p.nextMatrix(true);1065 var tbl = document.getElementById('celledit');1066 for (var i=0; i < tbl.rows.length; i++)1067 { 1068 var bb = (document.getElementById('CE' + i + '_2')!=null);1069 for (var j=0; j < (bb?3:2); j++)1070 { 1071 if (bb)1072 {1073 var ij = document.getElementById('CE' + i + '_' + j);1074 if (ij != null) 1075 {1076 if (i >= y.length)1077 y[i] = ['','',''];1078 y[i][j] = ij.value.replace(/ /g,'');1079 if (j==2) y[i][j] = y[i][j].replace(/@/g, escape('@')).replace(/,/g, escape(','));1080 1081 }1082 }1083 else1084 {1085 var ij = document.getElementById('CE' + i + '_' + j);1086 if (ij != null && ij.value!='') 1087 {1088 if (i >= y.length)1089 y[i] = ['',''];1090 y[i][j] = ij.value.replace(/ /g,'');1091 }1092 }1093 }1094}1095 var z = '';1096 for (i=0; i < y.length; i++)1097 {1098 if (y[i].length==3) 1099 for (var j=0; j < 3; j++)1100 {1101 if (y[i][0].replace(/ /g,'')=='' || y[i][1].replace(/ /g,'')==''|| y[i][2]=='')continue;1102 if (y[i][2].length>18 && isNaN(y[i][1]) && y[i][2].replace(/[0-9]/g,'')!="___")1103 y[i][1] = parseTime(y[i][1]);1104 z += y[i][j] + "@";1105 }1106 else1107 for (var j=0; j < 2; j++)1108 {1109 if (y[i][0]=='' || y[i][1]=='')continue;1110 z += (j==0?'':"'") + y[i][j] + (j==0?'':"'") + "@";1111 } 1112 z = z.replace(/@$/,','); 1113 }1114 1115 ResizeUploaded.attachref.value = ResizeUploaded.zip(z);1116},1117dontdel : '',1118asraw : function()1119{1120 var ck = localStorage['fileurlbuf'];1121 localStorage.removeItem('fileurlbuf');1122 var hasone = false;1123 if (ck == null || ck == 'null') 1124 ck = '';1125 else1126 ResizeUploaded.dontdel += ck;1127 ck = ck + ResizeUploaded.unzip(ResizeUploaded.attachref.value);1128 var p = new CSVParse(ck.replace(/,$/,''), '\'', '@',',');1129 var y = p.nextMatrix(true); 1130 if (ck == '') 1131 {1132 y[0] = ['','','']; 1133 y[1] = ['',''];1134 }1135 else 1136 {1137 y[y.length] = ['','',''];1138 y[y.length] = ['',''];1139 }1140 var z = "<table id=celledit border=1 style=border-collapse:collapse style=\"border:1px #dddddd solid;background-color:white\">";1141 var sizes = [16,16,50];1142 var xs = textmsg[1850].split(/@/);1143 // z += "<tr bgcolor=lightblue><td align=left>" + xs[0] + "</td><td>"+ xs[1] +"</td><td>"+ xs[2] +"</td></tr>";1144 for (var i=0; i < y.length ; i++)1145 {1146 z += "<tr>";1147 if (y[i].length==3)1148 for (var j=0; j < 3; j++)1149 {1150 if (y[i][j] == null) y[i][j] = '';1151 var len = 20; if (y[i][j]!=null) len = y[i][j].length;1152 if (len < sizes[j]) len = sizes[j];1153 if (len > sizes[j] + 2) len = sizes[j] + 2; 1154 len = Math.round(7.5*len);1155 1156 z += "<td align=left style=\"background-color:white;font-size:" + font_size + "px;\"><input id=CE" + i + '_' + j + " value=\"" + y[i][j] + "\" style=\"background-color:white;color:black;border:0px;width:" + len+ "px;font-size:" + font_size + "px\"></td>";1157 }1158 else1159 for (var j=0; j < 2; j++)1160 {1161 if (y[i][j] == null) y[i][j] = '';1162 var len = 20; if (y[i][j]!=null) len = y[i][j].length;1163 if (len < sizes[j]) len = sizes[j];1164 if (len > sizes[j] + 2) len = sizes[j] + 2; 1165 if (y[i][1]=='') y[i][1] = "http...";1166 z += "<td align=left colspan=" + (j==0?"1":"2") + " style=\"background-color:white;font-size:" + font_size + "px;\"><input id=CE" + i + '_' + j + " value=\"" + y[i][j] + "\" style=\"background-color:white;color:" +(y[i][1]==''?'black':'grey') + ";border:0px;width:100%;font-size:" + font_size + "px\" " + (j==0?"":" onchange=ResizeUploaded.fillfilename(this," + i +") ") + "></td>";1167 } 1168 z += "</tr>";1169 }1170 1171 z += "</table><br><center><input type=button style=\"background:url(image/addopt.png);width:18px;height:18px;background-position:-2px -2px;cursor:pointer\" onclick=\"ResizeUploaded.updatecell();ResizeUploaded.asraw()\"> <input name=send type=button value=\"" + textmsg[225] + "\" class=OrangeButton style=width:" + Math.round(4.5*font_size) + "px onclick=\"ResizeUploaded.updatecell();ResizeUploaded.attachman(ResizeUploaded.attachref)\"><input name=cancel value=\"" + textmsg[18] + "\" type=button class=GreenButton style=width:" + Math.round(4.5*font_size) + "px onclick=closeprompt()></center>";1172 1173 var ss = '<center>';1174 if (ResizeUploaded.initfolder!=null)1175 ss += "<a href=\"javascript:ResizeUploaded.selicon()\">" + textmsg[675] + "</a> "; 1176 ss += '<a href="javascript:ResizeUploaded.attachman(ResizeUploaded.attachref)">' 1177 + textmsg[1614].replace(/:.*/,'') + '</a></center>' + z;1178 myprompt(ss,null,null,textmsg[787] );1179},1180fillfilename:function(tb,i)1181{1182 var j = tb.value.lastIndexOf('/');1183 if (j==-1) return;1184 var t1 = document.getElementById( "CE" + i + '_0');1185 if (t1.value=='') 1186 {1187 var fn = tb.value.substring(j+1);1188 if (fn.length>16) fn = fn.substring(fn.length-16);1189 t1.value = fn;1190 }1191},1192initfolder: null,1193iframewin:null,1194getIFrameSelected:function()1195{1196 var s = ResizeUploaded.iframewin.selected();1197 ResizeUploaded.attachref.value = ResizeUploaded.zip(ResizeUploaded.unzip(ResizeUploaded.attachref.value)+ s);1198},1199selicon: function()1200{1201 if (ResizeUploaded.initfolder!=null)1202 myprompt(1203 ""//<center><input name=send type=button value=\"" + textmsg[1600] + "\" class=OrangeButton style=width:" + Math.round(4.5*font_size) + "px onclick=\"ResizeUploaded.getIFrameSelected();ResizeUploaded.attachman(ResizeUploaded.attachref)\"><input name=cancel value=\"" + textmsg[18] + "\" type=button class=GreenButton style=width:" + Math.round(4.5*font_size) + "px onclick=closeprompt()></center><br>" 1204 + "<iframe style=border:0px id=filebrowse src=Thumbs?folder=" + ResizeUploaded.initfolder + " width=450 height=550 />",null,null,ResizeUploaded.initfolder); 1205},1206addAnentry : function(fn, tm, code)1207{1208 var x = ResizeUploaded.unzip(ResizeUploaded.attachref.value);1209 if (x.indexOf(code) < 0)1210 {1211 x += fn + '@' + tm + '@' + code + ',';1212 }1213 ResizeUploaded.attachref.value = ResizeUploaded.zip(x);1214 if (typeof(showattachment)!='undefined') showattachment(x);1215},1216deleteByCode : function(c)1217{1218 var x = ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(/,$/,'');1219 var y = (new CSVParse(x,'\'',"@", ",")).nextMatrix();1220 var str = '';1221 for (var i=0; i < y.length; i++)1222 {1223 if (y[i][2]!=c)1224 str += y[i][0] + '@' + y[i][1] + '@' + y[i][2] + ',';1225 }1226 ResizeUploaded.attachref.value = ResizeUploaded.zip(str);1227 if (typeof(showattachment)!='undefined') showattachment(str);1228}, 1229deleteImagelet : function(filename)1230{1231 var v = ',' + ResizeUploaded.unzip(ResizeUploaded.attachref.value); var v0=v;1232 var k = v.indexOf(','+filename + '@');1233 if (k < 0) return;1234 v = v.substring(0,k) + v.substring(k + filename.length + 2).replace(/[^,]+/,'');1235 1236 ResizeUploaded.attachref.value = ResizeUploaded.zip(v.replace(/^,/,''));1237 ResizeUploaded.attachman(ResizeUploaded.attachref);1238},1239insertImagelet : function(j)1240{1241 var sa = document.getElementById("codeshow");1242 var ss = textmsg[311].replace(new RegExp("("+textmsg[1303]+ ")","ig"),"$1" + j) ;1243 var dic = textmsg[1613].split(/@/);1244 var associatedtxt = textareatobesearch;1245 if ( associatedtxt != null && typeof(caretPos)!='undefined') 1246 {1247 ResizeUploaded.oldonclick = associatedtxt.onclick;1248 associatedtxt.onclick = function()1249 {1250 ResizeUploaded.caretpos = caretPos(associatedtxt);1251 1252 if (ResizeUploaded.oldonclick!=null) 1253 ResizeUploaded.oldonclick();1254 }1255 ss += ",<br>" + textmsg[312];1256 for (var k=0; k < 3; k++)1257 ss += " <a href=\"javascript:ResizeUploaded.goinsert(" + j + "," + k + ")\">" + dic[k] + "</a> ";1258 }1259 1260 sa.innerHTML = ss ;1261},1262oldonclick : null,1263caretpos:0, 1264goinsert : function(n,k)1265{1266 var j = ResizeUploaded.caretpos;1267 var associatedtxt = textareatobesearch;1268 if ( associatedtxt == null || j == 0)1269 { 1270 var sa = document.getElementById('codeshow');1271 if (sa!=null)1272 sa.innerHTML = sa.innerHTML + "<br>" + textmsg[1606];1273 return;1274 }1275 1276 var m = '';1277 if (k==0) m=':1';else if (k==2) m= ':2'; 1278 associatedtxt.value = associatedtxt.value.substring(0,j) + "[Imagelet" + n + m+ "]" + associatedtxt.value.substring(j); 1279 1280},1281infoImage : function(fn, dim) 1282{1283 var sa = document.getElementById("codeshow");1284 var ds = dim.split(/_/);1285 sa.innerHTML = fn + ", x=" + ds[0] + ", y=" + ds[1] + ", w=" + ds[2] + ", h=" + ds[3]1286},1287openImagelet : function(filename, dim)1288{1289 var v = ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(/,$/,'');1290 var mt = (new CSVParse(v, "'", "@", ",")).nextMatrix(true);1291 for (var i=0; i < mt.length; i++)1292 {1293 if (filename == mt[i][0]) break;1294 }1295 if (i == mt.length) return;1296 if (mt[i].length==3)1297 var url = ResizeUploaded.goodopenurl(mt[i][2]);1298 else1299 url = ResizeUploaded.goodopenurl(mt[i][1]);1300 var sa = document.getElementById("codeshow");1301 var ns = dim.split(/_/);1302 1303 sa.innerHTML = '<div style="background-image:url('+ url + ');background-position:-' + ns[0] + "px -" + ns[1] + "px;width:" + ns[2] + "px;height:" + ns[3] + 'px" >  </div>';1304 1305},1306urlAttachedFile : function(pathcode)1307{1308 var showarea = document.getElementById('codeshow');1309 showarea.style.border = "1px #b0b0b0 outset";1310 if (pathcode.indexOf('http://')==0 || pathcode.indexOf('https://')==0)1311 showarea.innerHTML = pathcode;1312 else 1313 showarea.innerHTML = document.location.toString().replace( /[^\\/]+$/, ResizeUploaded.goodopenurl(pathcode,false ));1314 1315},1316activetextarea : function(x)1317{1318 return null;1319},1320setformat2html : function()1321{1322 1323},1324picfilename : null, 1325 1326cutoff : function(pathcode,fn,dim, num) 1327{1328 if (pathcode==null)1329 {1330 pathcode = ResizeUploaded.pathcode.replace(/@.*/,'');1331 fn = ResizeUploaded.filename.replace(/@.*/,'');1332 }1333 1334 ResizeUploaded.picfilename = fn; 1335 var x = textmsg[1602] + "<input type=button class=GreenButton style=width:" + Math.round(4.5*font_size) + "px value=\"" + textmsg[16] + "\" onclick=\"ResizeUploaded.selectit(" + (num==null?'':num)+ ")\"><div style=display:inline id=selectlet></div>";1336 myprompt(x +"<img id=imgwork src=\"" + ResizeUploaded.goodopenurl(pathcode) + "\" onload=\"ResizeUploaded.goodposition(this);ResizeUploaded.cropshow(null);" + (dim==null?'':("ResizeUploaded.moveTo(["+dim.replace(/_/g,',')+"]);")) + "\" style=\"margin:0px 0px 0px 0px\" >",1337 null, null, (num==null? (textmsg[1600]+ textmsg[1303]) : (textmsg[1603] + " " + textmsg[1303] + num)) );1338 1339 promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[1].cells[0].style.padding = "0px 0px 0px 0px";1340 promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[0].cells[0].getElementsByTagName('img')[0].onclick1341 = function()1342 {1343 var b = document.getElementById("dragcropbox"); 1344 if (b!=null) document.body.removeChild(b);1345 closeprompt();1346 } 1347},1348 1349selectit : function(j)1350{1351 var pic = document.getElementById('imgwork');1352 var XY = findPositionnoScrolling(pic);1353 var w = pic.offsetWidth;1354 var h = pic.offsetHeight;1355 var b = document.getElementById("dummycenter");1356 var cw, ch;1357 if (b==null) return; 1358 if ( b != null)1359 {1360 cw = b.offsetWidth;1361 ch = b.offsetHeight;1362 1363 var xy = findPositionnoScrolling(b);1364 xy[0] -= XY[0];1365 xy[1] -= XY[1];1366 if (xy[0] < 0)1367 xy[0] = 0;1368 if (xy[1] < 0)1369 xy[1] = 0;1370 } 1371 var mt = (new CSVParse(ResizeUploaded.unzip(ResizeUploaded.attachref.value).replace(/,$/,''),"'","@",",")).nextMatrix();1372 if (j == null || j=='' || isNaN(j)) 1373 {1374 j = 0;1375 for (var i=0; i < mt.length; i++)1376 {1377 if (mt[i].length==3 && !isNaN(mt[i][0]) && mt[i][2].replace(/[0-9]/g,'')=='___') 1378 {1379 var k = parseInt(mt[i][0]);1380 if (k > j) j = k;1381 }1382 }1383 j++;1384 var xx = ResizeUploaded.unzip(ResizeUploaded.attachref.value) + (j) + "@" + ResizeUploaded.picfilename.replace(/@.*/,'') + "@" + xy[0] + "_" + xy[1] + "_" + cw + "_" + ch + ",";1385 ResizeUploaded.attachref.value = ResizeUploaded.zip(xx);1386 var x = promptwin.getElementsByTagName('table')[0].rows[1].cells[1].getElementsByTagName('table')[0].rows[0].cells[2];1387 b.style.left = XY[0] + 'px'; b.style.top = XY[1] + 'px';1388 1389 var zt = document.getElementById('selectlet');1390 zt.innerHTML = zt.innerHTML.replace(new RegExp(textmsg[1611] + ".*$"),'') + '✓' + textmsg[1611] + "<input type=button class=GreenButton style=width:" + Math.round(4.5*font_size) + "px name=t1 value=\"" + textmsg[1612] + "\" onclick=\"ResizeUploaded.attachman(ResizeUploaded.attachref)\">";1391 }1392 else1393 {1394 var y= ',' + ResizeUploaded.unzip(ResizeUploaded.attachref.value);1395 var w = "," + j + "@" + ResizeUploaded.picfilename + "@";1396 var w1 = w + xy[0] + "_" + xy[1] + "_" + cw + "_" + ch;1397 if(typeOf(imagelet2wh) != 'undefined' && typeOf(pagenum) != 'undefined' )1398 {1399 imagelet2wh['imagelet' + j + '_' + pagenum] = (parseInt(''+cw)/2) + "px/" + (parseInt(''+ch)/2) + 'px';1400 }1401 var k = y.indexOf(w); 1402 if (k>=0)1403 {1404 y = y.substring(0,k) + w1 + y.substring(k + w.length).replace(/^[0-9|_]+/,'');1405 ResizeUploaded.attachref.value = ResizeUploaded.zip(y.replace(/^,/,''));1406 document.body.removeChild(document.getElementById('dragcropbox'));1407 closeprompt();1408 } 1409 }1410 1411 1412 if (typeof(showattachment)!='undefined') showattachment(ResizeUploaded.attachref.value);1413 // url += "&cropx=" + xy[0] + "&cropy=" + xy[1] + "&cwidth=" + cw + "&cheight=" + ch;1414},1415codeAttachedFile : function(pathcode)1416{1417 var showarea = document.getElementById('codeshow');1418 showarea.style.border = "1px #b0b0b0 outset";1419 showarea.innerHTML = "<img src=\"" + ResizeUploaded.goodopenurl(pathcode,false) + "\" >";1420 var ta = ResizeUploaded.activetextarea(pathcode);1421 if (ta != null)1422 {1423 var j = caretPos(ta);1424 ta.value = ta.value.substring(0,j) + "<img src=\"" + ResizeUploaded.goodopenurl(pathcode) + "\" style=display:inline;float:right >" + ta.value.substring(j); 1425 1426 ResizeUploaded.setformat2html();1427 myprompt(textmsg[794]);1428 }1429} 1430}1431function failupload(err,leng,newfilename,js)1432{1433 1434 if (err == null || err == '')1435 {1436 1437 }1438 else if (typeof(err) == 'number')1439 {1440 var y = ResizeUploaded.filename;1441 1442 ResizeUploaded.filename = newfilename+ '@' + err;1443 if (ResizeUploaded.attachref!=null)1444 {1445 var z = ResizeUploaded.unzip( ResizeUploaded.attachref.value );1446 1447 var j = z.indexOf(y);1448 if (j >-1)1449 { 1450 var k = j + y.length;1451 while (k < z.length && z.charAt(k) != ',') k++;1452 var w = z.substring(0,j) + ResizeUploaded.filename + '@' + js;1453 if (k < z.length) w += z.substring(k); 1454 1455 ResizeUploaded.attachref.value = ResizeUploaded.zip(w);1456 }1457 }1458 1459 if (ResizeUploaded.dosplitnow)1460 {1461 ResizeUploaded.cutoff();1462 ResizeUploaded.dosplitnow = false;1463 }1464 }1465 else1466 myprompt(err);1467 1468 1469}1470 1471function viewattachment(t)1472{1473 1474 if (t == null || t =='') return '';1475 var attarr = ResizeUploaded.unzip(t).replace(/,$/,'').split(/,/);1476 var tmptxt = '';1477 for (var i = 0; i < attarr.length; i++)1478 {1479 var xs = attarr[i].split(/@/);1480 if (tmptxt!='') tmptxt += ", "; 1481 tmptxt += '<span style=color:blue;cursor:pointer onclick="openpicorfile(\''+ xs[2].replace(/^[ ]+/,'') + '\',\'' + xs[0] + '\',this)">' + xs[0] + '</span>';1482 }1483 return tmptxt;1484}...
TooltipsExamplesPage.js
Source:TooltipsExamplesPage.js
1import React from "react";2import {3 Button,4 Overlay,5 Tooltip,6 OverlayTrigger,7 ButtonToolbar8} from "react-bootstrap";9import {Notice, KTCodeExample} from "../../../_metronic/_partials/controls";10class Example extends React.Component {11 constructor(...args) {12 super(...args);13 this.attachRef = target => this.setState({ target });14 this.state = { show: false };15 }16 render() {17 const { show, target } = this.state;18 return (19 <>20 <Button21 ref={this.attachRef}22 onClick={() => this.setState({ show: !show })}23 >24 Click me!25 </Button>26 <Overlay target={target} show={show} placement="right">27 {props => (28 <Tooltip id="overlay-example" {...props}>29 My Tooltip30 </Tooltip>31 )}32 </Overlay>33 </>34 );35 }36}37export default class TooltipsExamplesPage extends React.Component {38 render() {39 return (40 <>41 <Notice icon="flaticon-warning font-primary">42 <span>43 A tooltip component for a more stylish alternative to that anchor44 tag <code>title</code> attribute.45 </span>{" "}46 <span>47 For more info please check the components's official{" "}48 <a49 target="_blank"50 className="font-weight-bold"51 rel="noopener noreferrer"52 href="https://react-bootstrap.github.io/components/overlays/#tooltips"53 >54 demos & documentation55 </a>56 </span>57 </Notice>58 <div className="row">59 <div className="col-md-6">60 <KTCodeExample jsCode={jsCode1} beforeCodeTitle="Basic Example">61 <span>62 You can pass the <code>Overlay</code> injected props directly to63 the Tooltip component.64 </span>65 <div className="separator separator-dashed my-7"></div>66 <Example />67 </KTCodeExample>68 </div>69 <div className="col-md-6">70 <KTCodeExample jsCode={jsCode2} beforeCodeTitle="Trigger">71 <span>72 Or pass a Tooltip element to <code>OverlayTrigger</code>{" "}73 instead.74 </span>75 <div className="separator separator-dashed my-7"></div>76 <ButtonToolbar>77 {["top", "right", "bottom", "left"].map(placement => (78 <span key={placement}>79 <OverlayTrigger80 placement={placement}81 overlay={82 <Tooltip id={`tooltip-${placement}`}>83 Tooltip on <strong>{placement}</strong>.84 </Tooltip>85 }86 >87 <Button variant="secondary">88 Tooltip on {placement}89 </Button>90 </OverlayTrigger>91 <span> </span>92 </span>93 ))}94 </ButtonToolbar>95 </KTCodeExample>96 </div>97 </div>98 </>99 );100 }101}102const jsCode1 = `103class Example extends React.Component {104 constructor(...args) {105 super(...args);106 this.attachRef = target => this.setState({ target });107 this.state = { show: false };108 }109 render() {110 const { show, target } = this.state;111 return (112 <>113 <Button114 ref={this.attachRef}115 onClick={() => this.setState({ show: !show })}116 >117 Click me!118 </Button>119 <Overlay target={target} show={show} placement="right">120 {props => (121 <Tooltip id="overlay-example" {...props}>122 My Tooltip123 </Tooltip>124 )}125 </Overlay>126 </>127 );128 }129}130render(<Example />);131`;132const jsCode2 = `133<ButtonToolbar>134 {['top', 'right', 'bottom', 'left'].map(placement => (135 <OverlayTrigger136 key={placement}137 placement={placement}138 overlay={139 <Tooltip id={\`tooltip-\${placement}\`}>140 Tooltip on <strong>{placement}</strong>.141 </Tooltip>142 }143 >144 <Button variant="secondary">Tooltip on {placement}</Button>145 </OverlayTrigger>146 ))}147</ButtonToolbar>...
attachPopupGallery.js
Source:attachPopupGallery.js
1// This file is part of the Resultra project.2//3// This Source Code Form is subject to the terms of the Mozilla Public4// License, v. 2.0. If a copy of the MPL was not distributed with this5// file, You can obtain one at https://mozilla.org/MPL/2.0/.6function initAttachmentContainerPopupGallery($attachContainer) {7 $attachContainer.magnificPopup({8 delegate: 'a',9 type: 'image',10 gallery: { enabled: true },11 mainClass: 'attachmentPopupGallery',12 image: {13 tError: 'The image could not be loaded.',14 titleSrc: function(item) {15 var $attachContainer = $(item.el)16 var attachRef = $attachContainer.data("attachRef")17 return attachmentTitleAndCaptionHTML(attachRef)18 }19 },20 inline: {21 markup: '<div class="attachmentListInlineItem well">'+22 '<div class="mfp-close"></div>'+23 '<div>'+24 '<a class="attachDownloadLink" target="new">'+25 '<i class="attachmentThumbnailIcon glyphicon glyphicon-file"></i> '+26 '<span class="attachmentListLinkText">TBD</span>'+27 '</a>' + 28 '</div>' +29 '<div class="attachCaption"></div>'+30 '<div class="mfp-counter marginTop10"></div>'+31 '</div>'32 },33 callbacks : {34 markupParse: function($template, values, item) {35 36 if (item.type === "inline") {37 var $attachContainer = $(item.el)38 var attachRef = $attachContainer.data("attachRef")39 40 var $linkText = $template.find(".attachmentListLinkText")41 $linkText.text(attachRef.attachmentInfo.title)42 43 var $attachLink = $template.find(".attachDownloadLink")44 $attachLink.attr("href",attachRef.url)45 $attachLink.attr("target","new")46 47 var $attachCaption = $template.find(".attachCaption")48 $attachCaption.empty()49 $attachCaption.append( attachmentCaptionHTML(attachRef))50 51 }52 // Triggers each time when content of popup changes53 console.log('Parsing:', $template, values, item);54 },55 }56 });57 58 setTimeout(function() {59 // IMPORTANT NOTE: There is a conflict between document event handling for 60 // magnific popup and Bootstrap. When setting the z-index of the Magnific61 // popup container, a stack overflow is caused in Javascript. The problem and 62 // potential workarounds are described here:63 // 64 // https://github.com/dimsemenov/Magnific-Popup/issues/79665 //66 67 $(document).off('focusin');68 },200)69}70function initSingleAttachmentImagePopupLink($parentContainer,$link,attachmentID) {71 if (attachmentID !== null) {72 var getRefParams = { attachmentID: attachmentID }73 jsonAPIRequest("attachment/getReference", getRefParams, function(attachRef) {74 $link.text(attachRef.attachmentInfo.title)75 $link.attr("href",attachRef.url)76 $link.data("attachRef",attachRef)77 $link.addClass("mfp-image") 78 initAttachmentContainerPopupGallery($parentContainer)79 }) 80 } else {81 $link.text("")82 $link.attr("href","")83 $link.attr("attachRef",null) 84 }85 86}87function initSingleAttachmentImagePopupThumbnail($parentContainer,$link,attachmentID,maxWidth,maxHeight) {88 if (attachmentID !== null) {89 var getRefParams = { attachmentID: attachmentID }90 jsonAPIRequest("attachment/getReference", getRefParams, function(attachRef) {91 $link.attr("href",attachRef.url)92 $link.data("attachRef",attachRef)93 $link.addClass("mfp-image")94 95 var $thumbnailImage = $('<img class="attachmentThumbnailImage">')96 $thumbnailImage.attr("src",attachRef.url)97 98 // Allow the thumbnail to resize to the given proportions, but keep the aspect ratio.99 // https://stackoverflow.com/questions/12991351/css-force-image-resize-and-keep-aspect-ratio100 // Other CSS for thumbnail sizing and positino is set on the attachmentThumbnailImage class.101 $thumbnailImage.css("max-width",maxWidth+"px")102 $thumbnailImage.css("max-height",maxHeight+"px") 103 $link.find('img').remove()104 $link.append($thumbnailImage )105 106 initAttachmentContainerPopupGallery($parentContainer)107 }) 108 } else {109 $link.text("")110 $link.attr("href","")111 $link.attr("attachRef",null) 112 113 $link.find('img').remove()114 }115 ...
ReactOwner.js
Source:ReactOwner.js
...73 invariant(74 ReactOwner.isValidOwner(owner),75 'addComponentAsRefTo(...): Only a ReactOwner can have refs.'76 );77 owner.attachRef(ref, component);78 },79 /**80 * Removes a component by ref from an owner component.81 *82 * @param {ReactComponent} component Component to dereference.83 * @param {string} ref Name of the ref to remove.84 * @param {ReactOwner} owner Component on which the ref is recorded.85 * @final86 * @internal87 */88 removeComponentAsRefFrom: function(component, ref, owner) {89 invariant(90 ReactOwner.isValidOwner(owner),91 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs.'92 );93 // Check that `component` is still the current ref because we do not want to94 // detach the ref if another component stole it.95 if (owner.refs[ref] === component) {96 owner.detachRef(ref);97 }98 },99 /**100 * A ReactComponent must mix this in to have refs.101 *102 * @lends {ReactOwner.prototype}103 */104 Mixin: {105 /**106 * Lazily allocates the refs object and stores `component` as `ref`.107 *108 * @param {string} ref Reference name.109 * @param {component} component Component to store as `ref`.110 * @final111 * @private112 */113 attachRef: function(ref, component) {114 invariant(115 component.isOwnedBy(this),116 'attachRef(%s, ...): Only a component\'s owner can store a ref to it.',117 ref118 );119 var refs = this.refs || (this.refs = {});120 refs[ref] = component;121 },122 /**123 * Detaches a reference name.124 *125 * @param {string} ref Name to dereference.126 * @final127 * @private128 */129 detachRef: function(ref) {130 delete this.refs[ref];...
settingsReducers.test.js
Source:settingsReducers.test.js
...30 expect(shouldThrow).toThrow(new Error('CMF/Settings: Reference \'myref\' not found'));31 });32 it('should not do anything if obj parameter is not an object', () => {33 const testFunction = () => '';34 expect(attachRef({}, 'string')).toEqual('string');35 expect(attachRef({}, 1)).toEqual(1);36 expect(attachRef({}, true)).toEqual(true);37 expect(attachRef({}, testFunction)).toEqual(testFunction);38 expect(attachRef({}, undefined)).toEqual(undefined);39 expect(attachRef({}, null)).toEqual(null);40 expect(attachRef({}, [])).toEqual([]);41 });42 it('should try to resolve _ref if obj is an object', () => {43 const ref = { stuff: 'res' };44 expect(attachRef(ref, { _ref: 'stuff' })).toEqual(45 { 0: 'r', 1: 'e', 2: 's' }46 );47 });48});49describe('CMF settinsReducers', () => {50 it('should expose defaultState', () => {51 expect(defaultState).not.toBe(undefined);52 expect(typeof defaultState).toBe('object');53 });54 it('should expose one reducer as default', () => {55 expect(reducer).not.toBe(undefined);56 expect(typeof reducer).toBe('function');57 });58 it('should understand REQUEST_OK', () => {...
attachmentInfo.js
Source:attachmentInfo.js
1// This file is part of the Resultra project.2//3// This Source Code Form is subject to the terms of the Mozilla Public4// License, v. 2.0. If a copy of the MPL was not distributed with this5// file, You can obtain one at https://mozilla.org/MPL/2.0/.6function initAttachmentThumbnailContainer($parentContainer, attachRef) {7 8 var $thumbnailContainer = $parentContainer.find(".attachmentThumbnailContainer")9 10 var $thumbnailImage = $thumbnailContainer.find(".attachmentThumbnailImage")11 var $thumbnailIcon = $thumbnailContainer.find(".attachmentThumbnailIcon")12 var $thumbnailText = $thumbnailContainer.find(".attachmentThumbnailText")13 $thumbnailContainer.attr("href",attachRef.url)14 if(attachRef.dataType === "image") {15 $thumbnailImage.attr("src",attachRef.url)16 $thumbnailImage.attr("alt",attachRef.attachmentInfo.origFileName)17 $thumbnailIcon.hide()18 $thumbnailText.hide()19 } else {20 $thumbnailImage.hide()21 $thumbnailText.text(attachRef.extension)22 }23}24function initAttachmentTitleInput($parentContainer,attachRef) {25 26 var $titleInput = $parentContainer.find('.attachmentThumbnailTitle')27 28 $titleInput.val(attachRef.attachmentInfo.title)29 $titleInput.unbind("blur")30 $titleInput.bind("blur",function() {31 var setTitleParams = {32 attachmentID: attachRef.attachmentInfo.attachmentID,33 title: $titleInput.val()34 }35 jsonAPIRequest("attachment/setTitle", setTitleParams, function(updateAttachment) {36 })37 })38 39}40function initAttachmentCaptionInput($parentContainer,attachRef) {41 42 var $captionTextArea = $parentContainer.find(".attachmentCaptionTextArea")43 44 $captionTextArea.val(attachRef.attachmentInfo.caption)45 46 $captionTextArea.unbind("blur")47 $captionTextArea.bind("blur",function() {48 var setCaptionParams = {49 attachmentID: attachRef.attachmentInfo.attachmentID,50 caption: $captionTextArea.val()51 }52 jsonAPIRequest("attachment/setCaption", setCaptionParams, function(updateAttachment) {53 })54 })55 56}57function initAttachmentInfo($parentContainer,attachRef) {58 initAttachmentThumbnailContainer($parentContainer,attachRef)59 initAttachmentTitleInput($parentContainer,attachRef)60 initAttachmentCaptionInput($parentContainer,attachRef) ...
attachmentList.js
Source:attachmentList.js
1// This file is part of the Resultra project.2//3// This Source Code Form is subject to the terms of the Mozilla Public4// License, v. 2.0. If a copy of the MPL was not distributed with this5// file, You can obtain one at https://mozilla.org/MPL/2.0/.6function populateAttachmentList($attachmentListContainer,attachmentList) {7 8 var getRefParams = { attachmentIDs: attachmentList }9 jsonAPIRequest("attachment/getReferences", getRefParams, function(attachRefs) {10 $attachmentListContainer.empty()11 for(var refIndex = 0; refIndex < attachRefs.length; refIndex++) {12 var attachRef = attachRefs[refIndex]13 14 var $attachListItem = $('#attachmentListItemTemplate').clone()15 $attachListItem.attr("id","")16 17 var $attachLink = $attachListItem.find(".attachmentListItemLink")18 19 $attachLink.text(attachRef.attachmentInfo.title)20 21 $attachLink.data("attachRef",attachRef)22 if(attachRef.dataType === "image") {23 $attachLink.addClass("mfp-image")24 $attachLink.attr("href",attachRef.url)25 } else {26 $attachLink.addClass("mfp-inline")27 }28 29 $attachmentListContainer.append($attachListItem)30 }31 initAttachmentContainerPopupGallery($attachmentListContainer)32 33 })34 35 ...
HookTimerWithRef.js
Source:HookTimerWithRef.js
1import React,{useState,useEffect,useRef} from 'react'2export default function HookTimerWithRef() {3 const [timer, setTimer] = useState(0)4 const attachref = useRef(null)5 6 useEffect(() =>7 {8 attachref.current = setInterval(() => {9 setTimer(prevTimer => prevTimer +1)10 },1000)11 return (() => 12 {clearInterval(attachref.current)})13 },[])14 const continueInterval = () =>15 {16 attachref.current = setInterval(() => {17 setTimer(prevTimer => prevTimer +1)18 },1000)19 }20 return (21 <div>22 Time - {timer}23 <button onClick={() =>{clearInterval(attachref.current)}}>Stop Timer</button>24 <button onClick={continueInterval}> continue counting</button>25 </div>26 )...
Using AI Code Generation
1const { chromium } = require('playwright');2const { attachRef } = require('playwright/lib/server/frames');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const ref = await page.evaluateHandle(() => document.body);8 const element = await attachRef(page, ref);9 console.log(element);10 await browser.close();11})();12ElementHandle {13 _context: BrowserContext {14 _options: {15 },16 _permissions: {},17 _timeoutSettings: TimeoutSettings {18 },19 _browser: Browser {20 },21 _pageBindings: Map(0) {},22 _workers: Set(0
Using AI Code Generation
1const { attachRef } = require('playwright/lib/server/dom');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('input');8 await attachRef(page, element, 'myElement');9 await page.evaluate(() => {10 console.log(myElement);11 });12 await browser.close();13})();14const page = await createPageInContext(page, url, name, options);15await attachFrame(page, frame, name);16const { createPageInContext, attachFrame } = require('playwright/lib/server/dom');17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await attachFrame(page, newPage.mainFrame(), 'myFrame');23 await page.evaluate(() => {24 console.log(myFrame);25 });26 await browser.close();
Using AI Code Generation
1const { attachRef } = require('playwright-core/lib/server/injected/injectedScript');2const { ElementHandle } = require('playwright-core/lib/server/injected/elementHandle');3const { JSHandle } = require('playwright-core/lib/server/injected/jsHandle');4const { Page } = require('playwright-core/lib/server/page');5const { Frame } = require('playwright-core/lib/server/frame');6const { chromium } = require('playwright-core');7const { expect } = require('chai');8(async () => {9 const browser = await chromium.launch();10 const page = await browser.newPage();11 const elementHandle = await page.$('input[name="q"]');12 const jsHandle = await elementHandle.evaluateHandle((element) => {13 return element;14 });15 const frame = await page.mainFrame();16 const elementHandle2 = await frame.$('input[name="q"]');17 const jsHandle2 = await elementHandle2.evaluateHandle((element) => {18 return element;19 });20 const elementHandle3 = await page.$('input[name="q"]');21 const jsHandle3 = await elementHandle3.evaluateHandle((element) => {22 return element;23 });24 const elementHandle4 = await page.$('input[name="q"]');25 const jsHandle4 = await elementHandle4.evaluateHandle((element) => {26 return element;27 });28 const jsHandle5 = await page.evaluateHandle(() => {29 return document.querySelector('input[name="q"]');30 });31 const jsHandle6 = await page.evaluateHandle(() => {32 return document.querySelector('input[name="q"]');33 });34 const jsHandle7 = await page.evaluateHandle(() => {35 return document.querySelector('input[name="q"]');36 });37 const jsHandle8 = await page.evaluateHandle(() => {38 return document.querySelector('input[name="q"]');39 });40 const jsHandle9 = await page.evaluateHandle(() => {41 return document.querySelector('input[name="q"]');42 });43 const jsHandle10 = await page.evaluateHandle(() => {44 return document.querySelector('input[name="q"]');45 });46 const jsHandle11 = await page.evaluateHandle(() => {47 return document.querySelector('input[name="q"]');48 });49 const jsHandle12 = await page.evaluateHandle(() => {50 return document.querySelector('input[name="q"]');51 });
Using AI Code Generation
1const { attachRef } = require('playwright/lib/server/chromium/crBrowser');2const browser = await chromium.launch({ headless: false });3const context = await browser.newContext();4const page = await context.newPage();5attachRef(browser, page);6await page.evaluate(() => {7 const browser = window.browser;8 browser.close();9});
Using AI Code Generation
1const { attachRef } = require('@playwright/test/lib/server/frames');2const { Page } = require('@playwright/test/lib/server/page');3const { attachRef } = require('@playwright/test/lib/server/frames');4const { Page } = require('@playwright/test/lib/server/page');5const { test, expect } = require('@playwright/test');6test('test', async ({ page }) => {7 attachRef(page, 'page');8 attachRef(page, 'page');9 const element = await page.waitForSelector('input[name="q"]');10 await element.fill('Hello World!');11 await element.press('Enter');12 await page.waitForSelector('text=Hello World!');13 await page.screenshot({ path: `example.png` });14});
Using AI Code Generation
1const { attachRef } = require('playwright/lib/server/frames');2const page = await browser.newPage();3const frame = await page.frame({ name: 'frame' });4const elementHandle = await frame.$('element');5attachRef(elementHandle, 'element', 'element');6const { attachRef } = require('playwright/lib/server/frames');7const page = await browser.newPage();8const frame = await page.frame({ name: 'frame' });9const elementHandle = await frame.$('element');10attachRef(elementHandle, 'element', 'element');11const { attachRef } = require('playwright/lib/server/frames');12const page = await browser.newPage();13const frame = await page.frame({ name: 'frame' });14const elementHandle = await frame.$('element');15attachRef(elementHandle, 'element', 'element');16const { attachRef } = require('playwright/lib/server/frames');17const page = await browser.newPage();18const frame = await page.frame({ name: 'frame' });19const elementHandle = await frame.$('element');20attachRef(elementHandle, 'element', 'element');21const { attachRef } = require('playwright/lib/server/frames');22const page = await browser.newPage();23const frame = await page.frame({ name: 'frame' });24const elementHandle = await frame.$('element');25attachRef(elementHandle, 'element', 'element');26const { attachRef } = require('playwright/lib/server/frames');27const page = await browser.newPage();28const frame = await page.frame({ name: 'frame' });29const elementHandle = await frame.$('element');30attachRef(elementHandle, 'element', 'element');
Using AI Code Generation
1const { attachRef } = require('playwright/lib/client/selectorEngine');2const el = await attachRef(page, 'myRef');3await el.click();4const { attachRef } = require('playwright/lib/client/selectorEngine');5const el = await attachRef(page, 'myRef');6await el.click();7const { attachRef } = require('playwright/lib/client/selectorEngine');8const el = await attachRef(page, 'myRef');9await el.click();10const { attachRef } = require('playwright/lib/client/selectorEngine');11const el = await attachRef(page, 'myRef');12await el.click();13const { attachRef } = require('playwright/lib/client/selectorEngine');14const el = await attachRef(page, 'myRef');15await el.click();16const { attachRef } = require('playwright/lib/client/selectorEngine');17const el = await attachRef(page, 'myRef');18await el.click();19const { attachRef } = require('playwright/lib/client/selectorEngine');20const el = await attachRef(page, 'myRef');21await el.click();22const { attachRef } = require('playwright/lib/client/selectorEngine');23const el = await attachRef(page, 'myRef');24await el.click();25const { attachRef } = require('playwright/lib/client/selectorEngine');26const el = await attachRef(page, 'myRef');27await el.click();28const { attachRef } = require('playwright/lib/client/selectorEngine');29const el = await attachRef(page, 'myRef');30await el.click();31const { attachRef } = require('playwright/lib/client/selectorEngine');
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const page = await browser.newPage();5 const selector = 'text="Get started"';6 const element = await page.$(selector);7 await element.click();8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch({ headless: false });13 const page = await browser.newPage();14 const selector = 'text="Get started"';15 const element = await page.$(selector);16 await element.click();17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch({ headless: false });22 const page = await browser.newPage();23 const selector = 'text="Get started"';24 const element = await page.$(selector);25 await element.click();26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch({ headless: false });31 const page = await browser.newPage();32 const selector = 'text="Get started"';33 const element = await page.$(selector);34 await element.click();35 await browser.close();36})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!