1if("undefined" === typeof fw) { 2 // define our own container to avoid collisions 3 var fw = {}; 4} 5 6fw.parseJSON = function(ajaxResult) { 7 try { 8 json = $.parseJSON(ajaxResult); 9 } catch (error) { 10 json = null; 11 } 12 return json; 13}; 14 15fw. get_wn = function (word, section, title) { 16 console. info ("fw. get_wn_" + section + " ()"); 17 function process (resp) { 18 if (resp != '') { 19 $ ('#wn-' + section). append (resp). before ('<h2>' + title + '</h2>'); 20 if (section == 'prons') { 21 $ ('.speaker'). click (function (event) { 22 event. preventDefault (); 23 document. getElementsByTagName ('audio') [0]. play (); 24 }); 25 } 26 $ ('#wn-' + section). append ('<div class="wright"><img src="/img/provided_by.php?src=' + (section == 'prons' ? '11' : '10') + '"></div><br><br>'); 27 } 28 } 29 $. ajax ({ 30 url: BASE_URL + "lib/ajax.php", 31 type: "GET", 32 data: "get_wn_" + section + "=1&word=" + word, 33 cache: false, 34 success: process 35 }); 36} 37 38fw. get_hist_pop = function (word) { 39 console. info ("fw. get_hist_pop ()"); 40 var theIframe = '<iframe name="ngram_chart" src="https://books.google.com/ngrams/interactive_chart?content=' + encodeURIComponent (word) + '&year_start=1800&year_end=2000&corpus=15&smoothing=3&share=&direct_url=t1%3B%2C' + encodeURIComponent (word) + '%3B%2Cc0" width=900 height=300 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></iframe>'; 41 $ ('#hist-pop'). append (theIframe). before ('<h2>Historical Popularity</h2>'); 42 $ ('#hist-pop'). append ('<div class="wright"><img src="/img/provided_by.php?src=4"></div><br><br>'); 43} 44 45fw.get_related_news = function(word) { 46 console.info("fw.get_related_news()"); 47 48 function process(resp) { 49 var json = fw.parseJSON(resp); 50 51 if (json) { 52 var news = []; 53 $.each(json, function(key,val) { 54 news.push('<div><a target="_blank" href="'+val.Url+'"><!--<img src="'+val.Img+'" />-->'+val.Title+'</a></div>'); 55 }); 56 57 var num_per_li = 3; 58 var slides = []; 59 var divs = ""; 60 61 $.each(news, function(key,val) { 62 divs += val; 63 if ((key + 1) == num_per_li) { 64 slides.push('<li>'+divs+'</li>'); 65 divs = ""; 66 num_per_li = num_per_li + 3; 67 } 68 }); 69 70 $("#bing-news").append('<ul>'+slides.join('')+'</ul>').unslider({ 71 speed: 500, 72 delay: false, 73 dots: true, 74 fluid: true 75 }).before('<h2>News</h2>'); 76 77 $("#bing-news").append('<div class="wright"><img src="/img/provided_by.php?src=2"></div>'); 78 79 } else { 80 console.warn('get_related_news scrap failed'); 81 console.dir(resp); 82 $("#bing-news").hide(); 83 } 84 } 85 86 $.ajax({ 87 url: BASE_URL + "lib/ajax.php", 88 type: "GET", 89 data: "get_related_news=1&word=" + word, 90 cache: false, 91 success: process 92 }); 93}; // get_related_news ends 94 95 96fw.get_related_images = function(word) { 97 // TODO finish implementing, see BB issue #38 98 console.info("fw.get_related_images()"); 99 100 function process(resp) { 101 var json = fw.parseJSON(resp); 102 103 if (json) { 104 console.info('get_related_images not fully implemented, we got:'); 105 console.dir(resp); 106 } else { 107 console.warn('get_related_images scrap failed, we got:'); 108 console.dir(resp); 109 } 110 } 111 112 $.ajax({ 113 url: BASE_URL + "lib/ajax.php", 114 type: "GET", 115 data: "get_related_images=1&word=" + word, 116 cache: false, 117 success: process 118 }); 119}; // get_related_images ends 120 121 122fw.get_related_wiki = function(word) { 123 console.info("fw.get_related_wiki()"); 124 125 function process(resp) { 126 var json = fw.parseJSON(resp); 127 128 if (json) { 129 var article = []; 130 131 $.each(json.text, function(key,val) { 132 var img = null; 133 var link = null; 134 135 if (0 === key && json.img) { 136 img = '<img src="http://'+json.img+'" />'; 137 } else { 138 img = ""; 139 } 140 141 if ((key + 1) == json.text.length) { 142 link = '<strong>Source → <a href="http://'+json.url+'" target="_blank">Wiki</a></strong>'; 143 } else { 144 link = ""; 145 } 146 147 article.push('<p>'+img+val+link+'</p>'); 148 }); 149 150 $("#wiki").append(article.join('') + '<a href="#" id="show-more-wiki">Show more</a>').before('<h2>Wikipedia</h2>'); 151 $("#wiki").append('<div class="wright"><img src="/img/provided_by.php?src=1"></div><br><br>'); 152 153 var wiki_open = false;
154 $("#show-more-wiki").on("click", function(event) { 155 var wiki_container = null; 156 157 if (false === wiki_open) { 158 wiki_container = $(this).parent(); 159 wiki_container.animate({'max-height':wiki_container[0].scrollHeight},"slow"); 160 $(this).css({"background-image":"url(../img/up.png)"}); 161 wiki_open = true; 162 163 } else if (true === wiki_open) { 164 wiki_container = $(this).parent(); 165 wiki_container.animate({'max-height':100},"slow"); 166 $(this).css({"background-image":"url(../img/down.png)"}); 167 wiki_open = false; 168 } 169 170 return false; 171 }); 172 } else { 173 console.error('get_related_wiki scrap failed, we got:'); 174 console.dir(resp); 175 $("#wiki").hide(); 176 } 177 } 178 179 $.ajax({ 180 url: BASE_URL + "lib/ajax.php", 181 type: "GET", 182 data: "get_related_wiki=1&word=" + word, 183 cache: false, 184 success: process 185 }); 186}; // get_related_wiki ends 187 188 189fw.get_related_tweets = function(word) { 190 console.info("fw.get_related_tweets()"); 191 192 function process(resp) { 193 var json = fw.parseJSON(resp); 194 195 if (json) { 196 var tweets = []; 197 198 $.each(json, function(key,val) { 199 var name = '<a href="'+val.profile_url+'" target="_blank">'+val.name+'</a>'; 200 var profile_img = '<img src="'+val.profile_img+'" />'; 201 var text = '<p>'+val.text+'</p>'; 202 tweets.push('<li><div>'+profile_img+name+text+'</div></li>'); 203 }); 204 205 $("#tweets").append('<ul>'+tweets.join('')+'</ul>').unslider({ 206 speed: 500, 207 delay: false, 208 dots: true, 209 fluid: false 210 }).before('<h2>Tweets</h2>'); 211 212 $("#tweets").append('<div class="wright"><img src="/img/provided_by.php?src=3"></div>'); 213 214 } else { 215 console.error('get_related_tweets scrap failed, we got:'); 216 console.dir(resp); 217 $("#tweets").hide(); 218 } 219 } 220 221 $.ajax({ 222 url: BASE_URL + "lib/ajax.php", 223 type: "GET", 224 data: "get_related_tweets=1&word=" + word, 225 cache: false, 226 success: process 227 }); 228}; // get_related_tweets ends 229 230 231fw.get_dictionary_def = function(word) { 232 // See BB issue #37 regarding this unused scrap 233 console.info("fw.get_dictionary_def()"); 234 235 function process(resp) { 236 var json = fw.parseJSON(resp); 237 238 if (json) { 239 var def = []; 240 241 $.each(json.definitions, function(key,val) { 242 var exmpl = []; 243 if (val.examples) { 244 $.each(val.examples, function(key,val) { 245 exmpl.push('<li>'+val+'</li>'); 246 }); 247 } 248 249 var examples = ""; 250 if (exmpl.length > 0) { 251 examples = '<ul>'+exmpl.join('')+'</ul>'; 252 } 253 254 def.push('<li><div>'+val.def+'</div>'+examples+'</li>'); 255 }); 256 257 var data = '<h2>' + json.word + '<span>' + json.what + '</span></h2>' + 258 '<a href="javascript:;" id="play">play</a><a href="javascript:;" id="pause">pause</a>' + 259 '<div id="jquery_jplayer" class="jp-jplayer"></div>' + 260 '<div id="dictionary-examples"><ul>' + def.join('') + '</ul></div>'; 261 262 $("#dictionary").append(data); 263 $("#dictionary").append('<div class="wright"><img src="/img/provided_by.php?src=4"></div>'); 264 265 var say_word = json.sound; 266 $("#jquery_jplayer").jPlayer({ 267 ready: function () { 268 $(this).jPlayer("setMedia", { 269 mp3: say_word 270 }); 271 }, 272 swfPath: '../js/plugins/jQuery.jPlayer.2.5.0/Jplayer.swf', 273 solution: 'html, flash', 274 supplied: 'mp3', 275 cssSelectorAncestor: "", 276 cssSelector: { 277 play: "#play", 278 pause: "#pause" 279 }, 280 errorAlerts: false, 281 warningAlerts: false 282 }); 283 284 $("#dictionary-examples").unslider({ 285 speed: 500, 286 delay: false, 287 dots: true, 288 fluid: true 289 }); 290 291 } else { 292 console.error('get_dictionary_def scrap failed, we got:'); 293 console.dir(resp); 294 $("#dictionary").hide(); 295 } 296 } 297 298 $.ajax({ 299 url: BASE_URL + "lib/ajax.php", 300 type: "GET", 301 data: "get_dictionary_def=1&word=" + word, 302 cache: false, 303 success: process 304 }); 305}; // get_dictionary_def ends 306 307 308fw.get_amazon_product = function(word) { 309 console.info("fw.get_amazon_product()"); 310 311 function process(resp) { 312 var json = fw.parseJSON(resp); 313 314 if (json) { 315 var books = []; 316 317 $.each(json, function(key,val) { 318 var img = ""; 319 if (val.img) { 320 img = '<img height="160" src="'+val.img+'" />'; 321 } 322 323 var price = ""; 324 if (val.price) { 325 price = '<span>'+val.price+'</span>'; 326 } 327 328 var review = ""; 329 if (val.review) { 330 review = '<p>'+val.review+'</p>'; 331 } 332 333 books.push('<li><div><a target="_blank" href="'+val.url+'">'+img+'<h3>'+val.title+price+'</h3><p><strong>Author: '+val.author+'</strong></p>'+review+'</a></div></li>'); 334 }); 335 336 $("#amazon-books").append('<ul>'+books.join('')+'</ul>').unslider({ 337 speed: 500,
338 delay: false, 339 dots: true, 340 fluid: true 341 }).before('<h2>Books</h2>'); 342 343 $("#amazon-books").append('<div class="wright"><img src="/img/provided_by.php?src=5"></div>'); 344 345 } else { 346 console.error('get_amazon_product scrap failed, we got:'); 347 console.dir(resp); 348 $("#amazon-books").hide(); 349 } 350 } 351 352 $.ajax({ 353 url: BASE_URL + "lib/ajax.php", 354 type: "GET", 355 data: "get_amazon_product=1&cat=Books&word=" + word, 356 cache: false, 357 success: process 358 }); 359}; // get_amazon_product ends 360 361 362fw.get_related_videos = function(word) { 363 console.info("fw.get_related_videos()"); 364 365 function process(resp) { 366 var json = fw.parseJSON(resp); 367 368 if (json) { 369 var videos = []; 370 371 $.each(json, function(key,val) { 372 videos.push('<div><iframe width="180" height="150" src="//www.youtube.com/embed/'+val.url+'" frameborder="0" allowfullscreen></iframe></div>'); 373 }); 374 375 var num_per_li = 3; 376 var slides = []; 377 var divs = ""; 378 379 $.each(videos, function(key,val) { 380 divs += val; 381 if ((key + 1) == num_per_li) { 382 slides.push('<li>'+divs+'</li>'); 383 divs = ""; 384 num_per_li = num_per_li + 3; 385 } 386 }); 387 388 $("#youtube").append('<ul>'+slides.join('')+'</ul>').unslider({ 389 speed: 500, 390 delay: false, 391 dots: true, 392 fluid: true 393 }).before('<h2>Videos</h2>'); 394 395 $("#youtube").append('<div class="wright"><img src="/img/provided_by.php?src=6"></div>'); 396 397 } else { 398 console.error('get_related_videos scrap failed, we got:'); 399 console.dir(resp); 400 $("#youtube").hide(); 401 } 402 } 403 404 $.ajax({ 405 url: BASE_URL + "lib/ajax.php", 406 type: "GET", 407 data: "get_related_videos=1&word=" + word, 408 cache: false, 409 success: process 410 }); 411}; // get_related_videos ends 412 413 414fw.get_technorati_bposts = function(word) { 415 // TODO this one isn't working on production site, so it needs to be verified 416 console.info("fw.get_technorati_bposts()"); 417 418 function process(resp) { 419 var json = fw.parseJSON(resp); 420 421 if (json) { 422 var blogs = []; 423 424 $.each(json, function(key,val) { 425 blogs.push('<div><a target="_blank" href="'+val.Url+'"><img src="'+val.Thumb+'" />'+val.Title+'</a></div>'); 426 }); 427 428 var num_per_li = 3; 429 var slides = []; 430 var divs = ""; 431 432 $.each(blogs, function(key,val) { 433 divs += val; 434 if ((key + 1) == num_per_li) { 435 slides.push('<li>'+divs+'</li>'); 436 divs = ""; 437 num_per_li = num_per_li + 3; 438 } 439 }); 440 441 $("#technorati-posts").append('<ul>'+slides.join('')+'</ul>').unslider({ 442 speed: 500, 443 delay: false, 444 dots: true, 445 fluid: true 446 }).before('<h2>Blogs</h2>'); 447 448 $("#technorati-posts").append('<div class="wright"><img src="/img/provided_by.php?src=7"></div>'); 449 450 } else { 451 console.error('get_technorati_bposts scrap failed, we got:'); 452 console.dir(resp); 453 $("#technorati-posts").hide(); 454 } 455 } 456 457 $.ajax({ 458 url: BASE_URL + "lib/ajax.php", 459 type: "GET", 460 data: "get_technorati_bposts=1&word=" + word, 461 cache: false, 462 success: process 463 }); 464}; // get_technorati_bposts ends 465 466 467fw.get_profiles_with = function(word) { 468 console.info("fw.get_profiles_with()"); 469 470 function process(resp) { 471 var json = fw.parseJSON(resp); 472 473 if (json) { 474 var profiles = []; 475 476 $.each(json, function(key,val) { 477 var avatar = BASE_URL + "avatars/no-avatar-dark.png"; 478 if (null !== val.avatar) { 479 avatar = BASE_URL + "avatars/" + val.avatar; 480 } 481 482 var owner = ('' !== val.owner)? ' class="owner"' : ''; 483 var avatar_size = ('' !== val.owner)? '100' : '74'; 484 485 profiles.push('<article' + owner + '><a href="'+ 'https://slova.ru/' + 'public/' + val.user_id + '"><img src="' + 486 avatar + '" width="' + avatar_size + '" alt="' + val.name_surname + '" title="' + val.name_surname + '" height="' + avatar_size + '" /><h3>' + val.name_surname + 487 '</h3>' + val. owner + '</a></article>'); 488 }); 489 490 $("#profiles-word").append(profiles.join('') + '<a href="#" id="show-more-profiles">Show more</a>').before('<h2>Members who favor this Word</h2>'); 491 492 var profiles_open = false; 493 $("#show-more-profiles").on("click", function(event) { 494 var profiles_container = null; 495 496 if (false === profiles_open) { 497 profiles_container = $(this).parent(); 498 profiles_container.animate({'max-height':profiles_container[0].scrollHeight},"slow"); 499 $(this).css({"background-image":"url(../img/up.png)"}); 500 profiles_open = true; 501 } else if (true === profiles_open) { 502 profiles_container = $(this).parent(); 503 profiles_container.animate({'max-height':160},"slow"); 504 $(this).css({"background-image":"url(../img/down.png)"}); 505 profiles_open = false;
506 } 507 508 return false; 509 }); 510 511 if (profiles.length <= 5) { 512 $("#show-more-profiles").hide(); 513 $("#profiles-word").css({"padding-bottom":0,"max-height":160}); 514 } 515 516 } else { 517 console.error('get_profiles_with failed, we got:'); 518 console.dir(resp); 519 $("#profiles-word").hide(); 520 } 521 } 522 523 $.ajax({ 524 url: BASE_URL + "lib/ajax.php", 525 type: "GET", 526 data: "get_profiles_with=1&word=" + word, 527 cache: false, 528 success: process 529 }); 530}; // get_profiles_with ends 531 532 533fw.get_owner_notes = function(word) { 534 console.info("fw.get_owner_notes()"); 535 function process(data) { 536 var p = ''; 537 if(data.status) { 538 $("#owner-notes").append(data.result).before('<h2>Notes</h2>'); 539 540 } else { 541 p += '<p>' + data.message + '</p>'; 542 $("#owner-notes").append(p).before('<h2>Notes</h2>'); 543 } 544 } 545 546 $.ajax({ 547 url: BASE_URL + "lib/ajax.php", 548 type: "GET", 549 data: "get_owner_notes=1&word="+word, 550 dataType: "json", 551 cache: false, 552 success: function(data, textStatus, jqXHR) { 553 process(data); 554 } 555 }); 556}; // get_owner_notes ends 557 558 559fw.getFlickrPhotos = function(word) { // Flickr direct AJAX call 560 var flickr_cache = document. getElementById ('flickr_cache'). value; 561 if (flickr_cache == '0') { 562 apiKey = '2e2d0dcc21d92900189bc927126b8c16'; 563 perPage = '12'; 564 var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + apiKey + 565 '&text=' + word + 566 '&per_page=' + perPage + 567 '&format=json&nojsoncallback=1'; 568 console.info('Getting photos from Flicker: ', url); 569 570 $.ajax({ 571 dataType: "json", 572 url: url, 573 timeout: 60000, 574 success: function(data, textStatus, jqXHR) { 575 process(data, word, true); 576 } 577 }); 578 } else { 579 //get from db 580 $.ajax({ 581 url: BASE_URL + "lib/ajax.php", 582 type: "GET", 583 data: "get_flickr=1&word=" + word, 584 cache: false, 585 success: function (data) { 586 process (data, word, false); 587 } 588 }); 589 } 590 591 function process(data, word, cache) { 592 var data = (typeof data == "string") ? jQuery. parseJSON (data) : data; 593 if('undefined' !== data.stat && data.stat === 'ok') { // we got Flickr photos 594 var flickr = []; 595 596 $.each(data.photos.photo, function(key,val) { 597 flickr.push('<a href="http://www.flickr.com/photos/' + 598 val.owner + '/' + val.id + '" target="_blank"><img src="http://farm' + 599 val.farm + '.static.flickr.com/' + val.server + '/' + val.id + '_' + 600 val.secret + '_q.jpg" alt="' + val.title + '" /></a>'); 601 }); 602 603 $("#flickr-photos").append(flickr.join('')).before('<h2>Photos</h2>'); 604 $("#flickr-photos").append('<div class="wright"><img src="/img/provided_by.php?src=8"></div><br><br>'); 605 606 if (cache) { 607 //cache to db 608 $.ajax({ 609 url: BASE_URL + "lib/ajax.php", 610 type: "POST", 611 data: "cache_flickr=1&data=" + encodeURIComponent (JSON. stringify (data)) + "&word=" + word, 612 cache: false, 613 success: function (resp) { 614 console. info ('Cached flickr successfully.'); 615 } 616 }); 617 } 618 619 } else { 620 console.error('get_flickr_photos scrap failed. Check error codes at https://www.flickr.com/services/api/flickr.photos.search.html'); 621 console.error('Error code: ', data); 622 $("#flickr-photos").hide(); 623 } 624 } 625}; 626 627 628//////////////////////////////////////////////////////////////////////////////// 629// main 630//////////////////////////////////////////////////////////////////////////////// 631 632$(document).ready(function() { 633 var word = null; 634 635 if ($("#wow").length > 0) { 636 // get searched word 637 word = $("#wow .userviewFull").data("word"); 638 639 } else { 640 // console.error("Couldn't find a word to scrap"); 641 return; 642 } 643 644 $ (document). on ('click', '#buyword-button', function () { 645 var favors = $ ("#wow .userviewFull"). data ("favors"); 646 var word_id = $ ("#wow .userviewFull"). data ("word_id"); 647 if (! favors) { 648 if (confirm ('Add "' + word + '" to your words?')) { 649 // add word 650 $. ajax ({ 651 url: BASE_URL + 'lib/ajax.php', 652 type: 'POST', 653 data: 'add_existing_word=1&word_id=' + word_id, 654 cache: false, 655 success: function (r) { 656 window. location. href = '/buysell/' + word. toString (). replace(/\s+/g, '-').toLowerCase(); 657 } 658 }); 659 } else { 660 return; 661 } 662 } 663 window. location. href = '/buysell/' + word. toString (). replace(/\s+/g, '-').toLowerCase(); 664 }); 665 666 fw.get_profiles_with(word); 667 fw.get_owner_notes(word); 668 fw.get_related_wiki(word); 669 670 fw. get_wn (word, 'defs', 'Definitions'); 671 fw. get_wn (word, 'etys', 'Etymologies'); 672 fw. get_wn (word, 'prons', 'Pronunciations'); 673 fw. get_wn (word, 'same', 'Same context'); 674 fw. get_wn (word, 'rhym', 'Rhymes'); 675 fw. get_wn (word, 'tags', 'Tags'); 676 677// aborted scraps: (these are no working on production site, so we leave them off here too) 678// fw.get_related_images 679// fw.get_dictionary_def 680//fw.get_technorati_bposts (word); 681 682 /* social locker */ 683 setTimeout(function(){ 684 $ ('.content'). sociallocker ({ 685 locker: { close: true },
686 content: { 687 url: BASE_URL + "lib/ajax.php", 688 success: function () { 689 fw.getFlickrPhotos(word); 690 fw.get_related_videos(word); 691 fw.get_related_news(word); 692 fw.get_related_tweets(word); 693 fw.get_amazon_product(word); 694 fw. get_hist_pop (word); 695 } 696 } 697 }); 698 },20000); 699 700});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.