| 1390 | |
| 1391 | |
| 1392 | void NBrowserWindow::insertLinkButtonPressed() { |
| 1393 | QString text = editor->selectedText().trimmed(); |
| 1394 | if (text == "" && currentHyperlink == "") |
| 1395 | return; |
| 1396 | |
| 1397 | InsertLinkDialog dialog(insertHyperlink); |
| 1398 | |
| 1399 | // If we have a link already highlighted, set it to the dialog. |
| 1400 | if (text.startsWith("http://", Qt::CaseInsensitive) || |
| 1401 | text.startsWith("https://", Qt::CaseInsensitive) || |
| 1402 | text.startsWith("ftp://", Qt::CaseInsensitive) || |
| 1403 | text.startsWith("mailto:", Qt::CaseInsensitive)) { |
| 1404 | dialog.setUrl(text); |
| 1405 | } |
| 1406 | |
| 1407 | if (currentHyperlink != NULL && currentHyperlink != "") { |
| 1408 | dialog.setUrl(currentHyperlink); |
| 1409 | } |
| 1410 | dialog.exec(); |
| 1411 | if (!dialog.okButtonPressed()) { |
| 1412 | return; |
| 1413 | } |
| 1414 | |
| 1415 | // Take care of inserting new links |
| 1416 | if (insertHyperlink) { |
| 1417 | QString selectedText = editor->selectedText().replace("'","\\'"); |
| 1418 | if (dialog.getUrl().trimmed() == "") |
| 1419 | return; |
| 1420 | QString durl = dialog.getUrl().trimmed().replace("'","\\'"); |
| 1421 | QString url = QString("<a href=\"%1\" title=\"%2\">%3</a>").arg(durl,durl,selectedText); |
| 1422 | QString script = QString("document.execCommand('insertHtml', false, '%1')").arg(url); |
| 1423 | editor->page()->mainFrame()->evaluateJavaScript(script); |
| 1424 | return; |
| 1425 | } |
| 1426 | |
| 1427 | QString x = dialog.getUrl(); |
| 1428 | // Edit existing links |
| 1429 | QString js = "function getCursorPos() {" |
| 1430 | "var cursorPos;" |
| 1431 | "if (window.getSelection) {" |
| 1432 | " var selObj = window.getSelection();" |
| 1433 | " var selRange = selObj.getRangeAt(0);" |
| 1434 | " var workingNode = window.getSelection().anchorNode.parentNode;" |
| 1435 | " while(workingNode != null) { " |
| 1436 | " if (workingNode.nodeName.toLowerCase()=='a') workingNode.setAttribute('href','"; |
| 1437 | js = js + dialog.getUrl() +QString("');") |
| 1438 | +QString(" workingNode = workingNode.parentNode;") |
| 1439 | +QString(" }") |
| 1440 | +QString("}") |
| 1441 | +QString("} getCursorPos();"); |
| 1442 | editor->page()->mainFrame()->evaluateJavaScript(js); |
| 1443 | |
| 1444 | if (dialog.getUrl().trimmed() != "" ) { |
| 1445 | contentChanged(); |
| 1446 | return; |
| 1447 | } |
| 1448 | |
| 1449 | // Remove URL |
nothing calls this directly
no test coverage detected