1 | /******************************************************************/ |
---|
2 | |
---|
3 | var seo_keywords_url = '&dtml-absolute_url;/checkSEOKeywords'; |
---|
4 | var KEYWORDS_IDS = ['seo_keywords',]; |
---|
5 | // var KEYWORDS_REPORT = {}; |
---|
6 | |
---|
7 | // function extractWords(data) { |
---|
8 | // data = data // replace all non-word character with space |
---|
9 | // .replace(/[^a-zA-Z0-9\-\'\u2019\"\`]+/g, ' ') |
---|
10 | // // replace "-" and "'" symbols if it create groups event inside of token |
---|
11 | // .replace(/[\-\'\u2019\"\`]{2,}/g, ' ') |
---|
12 | // // replace all non-word characters and "-", "'" if it stay at word edge |
---|
13 | // .replace(/(?:^|\s+)[^a-zA-Z0-9]+|[^a-zA-Z0-9]+(?:\s+|$)/g, ' ') |
---|
14 | // // strip whitespaces |
---|
15 | // .replace(/^\s*(.*?)\s*$/, '$1'); |
---|
16 | // return data.split(/[^a-zA-Z0-9\-\'\u2019\"\`]+/); |
---|
17 | // } |
---|
18 | // |
---|
19 | // function countTerm(node, word, id) { |
---|
20 | // var contents = extractWords(node.nodeValue.toLowerCase()); |
---|
21 | // var term = word.toLowerCase(); |
---|
22 | // for (var i = 0, w; w = contents[i]; i++) { |
---|
23 | // if (w == term) { |
---|
24 | // KEYWORDS_REPORT[id][word] = 1; |
---|
25 | // return 'found'; |
---|
26 | // } |
---|
27 | // } |
---|
28 | // return false; |
---|
29 | // } |
---|
30 | // |
---|
31 | // function keywordsWalkTextNodes(node, func, data, id) { |
---|
32 | // if (!node) return false; |
---|
33 | // if (KEYWORDS_REPORT[id][data] == 1) return 'found'; |
---|
34 | // if (node.hasChildNodes) { |
---|
35 | // if (node.nodeType == 3) { |
---|
36 | // if (func(node, data, id) == 'found') { |
---|
37 | // return 'found'; |
---|
38 | // } |
---|
39 | // } |
---|
40 | // for (var i = 0; i < node.childNodes.length; i++) { |
---|
41 | // if (keywordsWalkTextNodes(node.childNodes[i], func, data, id) == 'found') { |
---|
42 | // return 'found'; |
---|
43 | // } |
---|
44 | // } |
---|
45 | // } |
---|
46 | // } |
---|
47 | |
---|
48 | // function checkPageKeywords(event) { |
---|
49 | // var event = event ? event:window.event; |
---|
50 | // var target = event.target ? event.target : event.srcElement; |
---|
51 | // if (!target) {return false;}; |
---|
52 | // var id = target.id.replace('_check_keywords', '') |
---|
53 | // KEYWORDS_REPORT[id] = {}; |
---|
54 | // var area = document.getElementById(id); |
---|
55 | // if (area && typeof(area.value) != 'undefined') { |
---|
56 | // var terms = extractWords(area.value); |
---|
57 | // for (var i = 0, term; term = terms[i]; i++) { |
---|
58 | // if (KEYWORDS_REPORT[id][term] == 1) continue; |
---|
59 | // KEYWORDS_REPORT[id][term] = 0; |
---|
60 | // keywordsWalkTextNodes(document.body, countTerm, term, id); |
---|
61 | // } |
---|
62 | // } |
---|
63 | // var report = ''; |
---|
64 | // for (var term in KEYWORDS_REPORT[id]) { |
---|
65 | // if (KEYWORDS_REPORT[id][term] != 1) |
---|
66 | // report += term + ' '; |
---|
67 | // } |
---|
68 | // KEYWORDS_REPORT[id] = {}; |
---|
69 | // if (report != '') { |
---|
70 | // report = 'Next keywords did not appear on the page:\n' + report; |
---|
71 | // } else { |
---|
72 | // report = 'All keywords found on the page!'; |
---|
73 | // } |
---|
74 | // alert(report); |
---|
75 | // return false; |
---|
76 | // } |
---|
77 | |
---|
78 | function checkPageKeywords(event) { |
---|
79 | var event = event ? event:window.event; |
---|
80 | var target = event.target ? event.target : event.srcElement; |
---|
81 | if (!target) {return false;}; |
---|
82 | var id = target.id.replace('_check_keywords', '') |
---|
83 | var area = document.getElementById(id); |
---|
84 | if (area && typeof(area.value) != 'undefined') { |
---|
85 | var req = new XMLHttpRequest(); |
---|
86 | req.open("POST", seo_keywords_url, true); |
---|
87 | req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
---|
88 | req.onreadystatechange = function(request) { |
---|
89 | if (req.readyState == 4) { |
---|
90 | if (req.status == '200') { |
---|
91 | alert(req.responseText); |
---|
92 | } else { |
---|
93 | alert('Error on server!'); |
---|
94 | } |
---|
95 | } |
---|
96 | }; |
---|
97 | req.send("text="+area.value); |
---|
98 | } |
---|
99 | return false; |
---|
100 | } |
---|
101 | |
---|
102 | function addKeywordsButton(event) { |
---|
103 | for (var i = 0, id; id = KEYWORDS_IDS[i]; i++) { |
---|
104 | var area = document.getElementById(id); |
---|
105 | if (!area || (typeof(area.value) == 'undefined')) continue; |
---|
106 | var button = document.createElement('INPUT'); |
---|
107 | button.type = 'button'; |
---|
108 | button.value = 'Check Keywords'; |
---|
109 | button.name = id+'_check_keywords'; |
---|
110 | button.id = id+'_check_keywords'; |
---|
111 | button.className = 'check-keywords-button'; |
---|
112 | area.parentNode.insertBefore(button, area.nextSibling); |
---|
113 | registerEventListener(button, 'click', checkPageKeywords); |
---|
114 | // KEYWORDS_REPORT[id] = {}; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | registerPloneFunction(addKeywordsButton); |
---|