1;(function(_public) { 2 3 var modules = []; 4 5 _public.register = function(selector, fn, data, name, init, post, filter) { 6 if (arguments.length === 1 && is.plain(selector)) { 7 fn = selector.builder; 8 data = selector.data; 9 name = selector.name; 10 init = selector.init; 11 post = selector.post; 12 filter = selector.filter; 13 selector = selector.selector; 14 } 15 if (!is.callable(fn)) { 16 console.error("missing builder"); 17 return; 18 } 19 modules.push({ 20 selector: selector, 21 fn: fn, 22 data: data, 23 name: name, 24 init: init, 25 post: post, 26 filter: filter 27 }); 28 }; 29 30 _public.exclude = function(module, selector) { 31 if (is.string(selector)) { 32 selector = query(selector); 33 } 34 if (is.string.blank(module)) { 35 return; 36 } 37 set.data(selector, "exclude-" + module, true); 38 }; 39 40 function getModule(name) { 41 for (let i = 0; i < modules.length; i++) { 42 let module = modules[i]; 43 if (!module.name || 44 module.name !== name) { 45 continue; 46 } 47 return module; 48 } 49 } 50 51 function getMatches(module, matches, context) { 52 context = context || window; 53 var matched = []; 54 if (is.string(matches)) { 55 matches = find.all(matches); 56 } else if (!is.bound(matches) && module.selector) { 57 matches = find.all(module.selector); 58 } 59 if (!matches || !matches.length) { 60 return matched; 61 } 62 var suffix = module.name ? "-" + module.name : ""; 63 var attrDone = "done" + suffix; 64 var attrExclude = "exclude" + suffix; 65 for (let j = 0; j < matches.length; j++) { 66 var match = matches[j]; 67 if (has.data(match, attrExclude)) { 68 continue; 69 } 70 var done = get.data(match, attrDone); 71 if (done === "true") { 72 continue; 73 } 74 set.data(match, attrDone, true); 75 matched.push(match); 76 } 77 return matched; 78 } 79 80 function execute(module, matches, context) { 81 if (matches.length && is.callable(module.init)) { 82 module.init.call(context, matches); 83 module.init = null; 84 } 85 every.when(matches, 86 function(context, match) { 87 this.fn.call(context, match, module.data); 88 }.bind(module, context)) 89 .then( 90 function(context, matches) { 91 if (!is.callable(this.post)) { 92 return; 93 } 94 this.post.call(context, matches); 95 }.bind(module, context, matches)); 96 } 97 98 _public.scan = function(context) { 99 if (is.string(context)) { 100 context = find.id(context); 101 } 102 if (!is.element(context)) { 103 context = document.body; 104 } 105 on.document.ready( 106 function() { 107 var matches = query( 108 "[data-syw]:not([data-syw-done])", context); 109 for (var i1 = 0; i1 < matches.length; i1++) { 110 parse(matches[i1]); 111 } 112 /* builders */ 113 matches = find.all("[data-builder]"); 114 if (matches.length) { 115 for (var i2 = 0; i2 < matches.length; i2++) { 116 var callback = remove.data(matches[i2], "builder"); 117 setTimeout( 118 function(match, context, callback) { 119 callback = callback.split(","); 120 for (let i = 0; i < callback.length; i++) { 121 var module = getModule(callback[i]); 122 if (module) { 123 matches = getMatches(module, [ match ]); 124 execute(module, matches, context); 125 continue; 126 } 127 var fn = get.callable(callback[i]); 128 if (fn) { 129 fn.call(context, match); 130 } 131 } 132 }, 0, matches[i2], context, callback); 133 } 134 } 135 136 /* modules */ 137 for (var i3 = 0; i3 < modules.length; i3++) { 138 let module = modules[i3]; 139 if (is.callable(module.filter) && 140 module.filter.call(module, context) === false) { 141 continue; 142 } 143 matches = getMatches(module, module.selector, context); 144 if (!matches.length) { 145 continue; 146 } 147 execute(module, matches, context); 148 } 149 150 /* actions */ 151 let actions = find.all("[data-action]"); //23923 falfe? 152 remove.data(actions, "action"); 153 if (actions.length) { 154 every(actions, doAction); 155 } 156 157 /* moves */ 158 let append = find.all("[data-append]"); //23923 159 if (append.length) { 160 every(append, function(match) { 161 let selector = get.data(match, "append"); 162 let where = find(selector); 163 if (!where) { 164 return; 165 } 166 node.append(where, match); 167 node.show(match); 168 }); 169 } 170 }); 171 }; 172 173 _public.parse = function(e) { 174 parse(e); 175 }; 176 177 function parse(match) { 178 if (has.data(match, "syw-done")) { 179 return; 180 } 181 var type = get.data(match, "syw"); 182 var attrs = get.attr(match); 183 if (is.string.blank(type)) { 184 if (match.nodeName === "DIV" && 185 has.className(match, "permalink")) { 186 type = "permalink"; 187 } else if ( 188 match.nodeName === "INPUT") { 189 if (attrs.type === "date") { 190 type = "input-date"; 191 } 192 if (attrs.type === "text") { 193 type = "input-text"; 194 } 195 } else { 196 var truncate = get.data(match, "truncate"); 197 if (truncate) { 198 type = "truncate"; 199 } 200 } 201 } 202 if (is.string.blank(type)) { 203 console.warn("No type for " + match); 204 return; 205 } 206 try { 207 switch (type) { 208 case "input-text": 209 doInputText(match); 210 break; 211 case "input-date": 212 doInputDate(match, attrs); 213 break; 214 case "truncate": 215 doTruncate(match); 216 break; 217 case "icon-help": 218 doIconHelp(match); 219 break; 220 case "mobile-menu": 221 MobileMenu(match); 222 break; 223 case "permalink": 224 doPermalink(match); 225 break; 226 case "rating": 227 doRating(match); 228 break; 229 case "rating-news": 230 doRatingNews(match); 231 break; 232 case "rating-cmsitem": 233 doRatingCmsitem(match); 234 break; 235 case "tabset": 236 TabSetUtils.create(null, match); 237 break; 238 case "picbox": 239 var elements = $(match).find("a[data-type='image']:not(.escludiPicBox)"); 240 PicBoxUtils.create(elements); 241 break; 242 case "mirador": 243 doMirador(match); 244 break; 245 case "mirador0": 246 doMirador0(match); 247 break; 248 } 249 } catch (e) { 250 console.error(e); 251 } 252 remove.data(match, "syw"); 253 set.data(match, "syw-done", type); 254 } 255 256 function doMirador(match) { 257 var elements = $(match).find("a[data-type='image']"); 258 if(elements.length == 1) {
259 set.event(elements[0], "click", 260 function(ev) { 261 SYMirador.open(elements[0].href) 262 ev.preventDefault(); 263 }); 264 } 265 } 266 267 function doMirador0(match) { 268 var elements = $(match).find("a[data-type='image']"); 269 if(elements.length == 1) { 270 if(elements[0].getAttribute("data-progr") == null) { 271 set.event(elements[0], "click", 272 function(ev) { 273 SYMirador.open(elements[0].href) 274 ev.preventDefault(); 275 } 276 ); 277 } else { 278 var fromDoc = $("#fromdoc").val(); 279 var toDoc = $("#todoc").val(); 280 set.event(elements[0], "click", 281 function(ev) { 282 SYMirador.page(elements[0].getAttribute("data-progr"), fromDoc, toDoc); 283 ev.preventDefault(); 284 } 285 ); 286 } 287 288 } 289 } 290 291 function doAction(match) { 292 if (!match.hasAttributes()) { 293 return; 294 } 295 for (let i = 0; i < match.attributes.length; i++) { 296 let attr = match.attributes[i]; 297 if (attr.name === "data-append") { 298 let e = find(attr.value); 299 if (e === null) { 300 return; 301 } 302 node.append(e, match); 303 } else if (attr.name === "data-once") { 304 if (match.nodeName === "A" 305 && !has.attr(match, "href")) { 306 set.attr(match, "href", "javascript:;"); 307 } 308 let callback = function(ev) { 309 new Function(attr.value) 310 .call(match); 311 remove.event(match, "click", callback); 312 }; 313 set.event(match, "click", callback); 314 } else if (attr.name === "data-toggle") { 315 let e = retrieveActionElement(attr.value, match); 316 if (e === null) { 317 return; 318 } 319 set.event(match, "click", 320 function() { 321 node.toggle(e); 322 }); 323 } else if (attr.name === "data-hide") { 324 let e = retrieveActionElement(attr.value, match); 325 if (e === null) { 326 return; 327 } 328 set.event(match, "click", 329 function() { 330 node.hide(e); 331 }); 332 } else if (attr.name === "data-prevent") { 333 set.event(match, "click", 334 function(ev) { 335 ev.preventDefault(); 336 }); 337 } 338 } 339 } 340 341 function retrieveActionElement(value, match) { 342 let e; 343 if (is.string.blank(value) || value === "self") { 344 e = match; 345 } else if (value === "next") { 346 e = nav.next(match); 347 } else if (value === "parent") { 348 e = nav.parent(match); 349 } else { 350 e = find(value); 351 } 352 return e || null; 353 } 354 355 function doInputText(match) { 356 if (Modernizr.input.placeholder) { 357 return; 358 } 359 var placeholder = get.attr(match, "placeholder"); 360 if (is.string.blank(placeholder)) { 361 return; 362 } 363 if (is.string.blank(match.value)) { 364 match.value = placeholder; 365 add.className(match, "placeholder-blur"); 366 } 367 set.event(match, "click,focus", function() { 368 if (match.value === placeholder) { 369 match.value = ""; 370 } 371 remove.className(match, "placeholder-blur"); 372 }); 373 set.event(match, "blur", function() { 374 if (is.string.blank(match.value)) { 375 match.value = placeholder; 376 add.className(match, "placeholder-blur"); 377 } else if (match.value === placeholder) { 378 add.className(match, "placeholder-blur"); 379 } 380 }); 381 } 382 383 function doInputDate(match, attrs) { 384 // il browser supporta il tipo date 385 if (Modernizr.inputtypes.date) { 386 return; 387 } 388 var min, max, def; 389 if (!is.string.blank(attrs.min)) { 390 min = new Date( 391 Dates.fromString(attrs.min, "yyyy-MM-dd")); 392 } 393 if (!is.string.blank(attrs.max)) { 394 max = new Date( 395 Dates.fromString(attrs.max, "yyyy-MM-dd")); 396 } 397 if (!is.string.blank(attrs.value)) { 398 def = new Date( 399 Dates.fromString(attrs.value, "yyyy-MM-dd")); 400 } 401 var minYearRange = "c-10"; 402 var maxYearRange = "c+10"; 403 if (min) { 404 minYearRange = min.getFullYear(); 405 } 406 if (max) { 407 maxYearRange = max.getFullYear(); 408 } 409 var yearRange = minYearRange + ":" + maxYearRange; 410 411 var name = match.name; 412 if (is.string.blank(name)) { 413 name = match.id; 414 } 415 if (is.string.blank(name)) { 416 name = get.random.string(10); 417 } 418 remove.attr(match, "id"); 419 remove.attr(match, "name"); 420 421 var input = create.element("input", { 422 name: name, 423 type: "hidden", 424 value: attrs.value 425 }); 426 input.required = match.required; 427 node.insert.after(match, input); 428 $(match) 429 .datepicker({ 430 altFormat : "yy-mm-dd", 431 altField : input, 432 dateFormat : "dd/mm/yy", 433 changeMonth : true, 434 changeYear : true, 435 yearRange: yearRange, 436 defaultDate : def, 437 minDate : min, 438 maxDate : max 439 }).datepicker( "option", $.datepicker.regional[SebinaYou.language] ); 440 // errore del datepicker, parte con il format sbagliato 441 if (def) { 442 match.value = Dates.format(def, "dd/MM/yyyy"); 443 } 444 } 445 446 function doTruncate(match) { 447 var text = get.text(match); 448 var max = get.data(match, "truncate"); 449 if (is.string.numeric(max)) { 450 max = parseInt(max, 10); 451 } else { 452 max = 120; 453 } 454 // aggiungo un 20% per evitare stringhe troncate per qualche carattere 455 var pad = (max / 100) * 20; 456 if (text.length <= max + pad) { 457 return; 458 }
459 var pos = text.indexOf(".", max - pad); 460 if (pos < 0 || pos > max) { 461 pos = text.indexOf(" ", max); 462 } 463 if (pos < 0 || pos > max) { 464 pos = max; 465 } 466 467 match.title = i18n.js_truncate_open; 468 469 var text1 = text.slice(0, pos); 470 set.text(match, text1); 471 add.className(match, ["ellipsis", "closed"]); 472 473 var text2 = text.slice(pos); 474 var span = create.element("span"); 475 span.className = "truncate-remainder"; 476 set.text(span, text2); 477 node.append(match, span); 478 479 set.event(match, "click", function() { 480 if (has.className(match, "closed")) { 481 match.title = i18n.js_truncate_close; 482 remove.className(match, "closed"); 483 } else { 484 match.title = i18n.js_truncate_open; 485 add.className(match, "closed"); 486 } 487 return false; 488 }); 489 } 490 491 function doIconHelp(match) { 492 if (!is.element(match)) { 493 return; 494 } 495 set.event(match, "click", function() { 496 FLOATER.toggle(match, 497 match.id || get.data(match, "id"), 498 get.data(match, "content") || match); 499 }); 500 node.show(match); 501 } 502 503 function doPermalink(match) { 504 var button = find("button", match); 505 var input = find("input", match); 506 var clipboard = new ClipboardJS(button, { 507 target: function(trigger) { 508 return input; 509 }, 510 text: function(trigger) { 511 if (!is.string.blank(input.value)) { 512 return input.value; 513 } 514 var uri = get.data(button, "uri"); 515 input.value = is.string.blank(uri) ? location.href : uri; 516 return input.value; 517 } 518 }); 519 520 clipboard.on('success', function(e) { 521 fire.event(button, "floated:show"); 522 }); 523 524 clipboard.on('error', function(e) { 525 526 }); 527 } 528 529 function doRating(match) { 530 var editable = get.data(match, "editable"); 531 if (!editable) { 532 console.log("star-rating: not editable"); 533 return; 534 } 535 536 var stars = nav.childs(match); 537 538 var rating = get.data(match, "rating"); 539 var ratingUser = get.data(match, "rating-user"); 540 541 on(match) 542 .enter( 543 function(ev) { 544 set.timeout(function() { 545 remove.className(stars, "on"); 546 if (ratingUser) { 547 add.className(stars.slice(0, ratingUser), "on"); 548 } 549 }, 300); 550 }) 551 .leave( 552 function(ev) { 553 set.timeout(function() { 554 remove.className(stars, "on"); 555 add.className(stars.slice(0, rating), "on"); 556 }, 300); 557 }) 558 .click( 559 function(ev) { 560 var star = ev.source; 561 var indexUser = get.data(ev.source, "index"); 562 563 var idOpac = get.data(match, "name"); 564 W.rate(idOpac, indexUser, function(indexTito) { 565 rating = indexTito; 566 ratingUser = indexUser; 567 remove.className(stars, "on"); 568 add.className(stars.slice(0, indexUser), "on"); 569 }); 570 }); 571 } 572 573 function doRatingNews(match) { 574 var editable = get.data(match, "editable"); 575 if (!editable) { 576 console.log("star-rating-user: not editable"); 577 return; 578 } 579 580 var stars = nav.childs(match); 581 var divAverage = $("div.star-rating") 582 var starsAverage = divAverage.children("span"); 583 584 var rating = get.data(match, "rating"); 585 var ratingUser = get.data(match, "rating-user"); 586 587 on(match) 588 .enter( 589 function(ev) { 590 set.timeout(function() { 591 remove.className(stars, "on"); 592 if (ratingUser) { 593 add.className(stars.slice(0, ratingUser), "on"); 594 } 595 }, 300); 596 }) 597 .leave( 598 function(ev) { 599 set.timeout(function() { 600 remove.className(stars, "on"); 601 remove.className(starsAverage, "on"); 602 add.className(stars.slice(0, ratingUser), "on"); 603 add.className(starsAverage.slice(0, rating), "on"); 604 }, 300); 605 }) 606 .click( 607 function(ev) { 608 var star = ev.source; 609 var indexUser = get.data(ev.source, "index"); 610 611 var idOpac = get.data(match, "name"); 612 W.rateNews(idOpac, indexUser, function(ris) { 613 let indexTito = ris["indexTito"]; 614 let indexUser = ris["indexUser"]; 615 rating = indexTito; 616 ratingUser = indexUser; 617 remove.className(stars, "on"); 618 remove.className(starsAverage, "on"); 619 add.className(stars.slice(0, indexUser), "on"); 620 add.className(starsAverage.slice(0, indexTito), "on"); 621 $("#div-rating-average").removeAttr("hidden"); 622 }); 623 }); 624 } 625 626
627 function doRatingCmsitem(match) { 628 var editable = get.data(match, "editable"); 629 if (!editable) { 630 console.log("star-rating-user: not editable"); 631 return; 632 } 633 634 var stars = nav.childs(match); 635 var divAverage = $("div.star-rating") 636 var starsAverage = divAverage.children("span"); 637 638 var rating = get.data(match, "rating"); 639 var ratingUser = get.data(match, "rating-user"); 640 641 on(match) 642 .enter( 643 function(ev) { 644 set.timeout(function() { 645 remove.className(stars, "on"); 646 if (ratingUser) { 647 add.className(stars.slice(0, ratingUser), "on"); 648 } 649 }, 300); 650 }) 651 .leave( 652 function(ev) { 653 set.timeout(function() { 654 remove.className(stars, "on"); 655 remove.className(starsAverage, "on"); 656 add.className(stars.slice(0, ratingUser), "on"); 657 add.className(starsAverage.slice(0, rating), "on"); 658 }, 300); 659 }) 660 .click( 661 function(ev) { 662 var star = ev.source; 663 var indexUser = get.data(ev.source, "index"); 664 665 var idOpac = get.data(match, "name"); 666 W.rateCmsitem(idOpac, indexUser, function(ris) { 667 let indexTito = ris["indexTito"]; 668 let indexUser = ris["indexUser"]; 669 rating = indexTito; 670 ratingUser = indexUser; 671 remove.className(stars, "on"); 672 remove.className(starsAverage, "on"); 673 add.className(stars.slice(0, indexUser), "on"); 674 add.className(starsAverage.slice(0, indexTito), "on"); 675 $("#div-rating-average").removeAttr("hidden"); 676 }); 677 }); 678 } 679 680 681 function MobileMenu(match) { 682 683 var handler = match; 684 685 var id = get.data(handler, "content"); 686 var content = find.id(id); 687 if (!content || is.string.blank(content.innerHTML)) { 688 remove.node(handler, content); 689 return; 690 } 691 692 add.className(match, "mobile-menu-button"); 693 match.tabindex = 0; 694 aria.attr(handler, { 695 "haspopup": true, 696 "controls": content.id 697 }); 698 699 add.className(content, "mobile-menu-content"); 700 content.id = content.id || get.random.string(10); 701 702 function show(ev) { 703 content.style.visibility = "visible"; 704 var iPos = get.offset(handler); 705 set.style(content, { 706 top: iPos.top + "px" 707 }); 708 set.event(document.body, "click", hide); 709 set.event(document.body, "keyup", keyup); 710 set.event(window, "resize", hide); 711 aria.attr(handler, "expanded", true); 712 713 var focusable = find.focusable(content); 714 if (!focusable) { 715 content.tabIndex = 0; 716 focusable = content; 717 } 718 focusable.focus(); 719 } 720 721 function keyup(ev) { 722 ev = get.event(ev); 723 if (ev.keyCode === Chars.ESCAPE) { 724 hide(); 725 } 726 } 727 728 function hide(ev) { 729 if (ev && (content === ev.srcElement || is.ancestor(content, ev.srcElement))) { 730 return; 731 } 732 remove.event(document.body, "click", hide); 733 remove.event(document.body, "keyup", keyup); 734 remove.event(window, "resize", hide); 735 aria.attr(handler, "expanded", false); 736 content.style.visibility = "hidden"; 737 handler.focus(); 738 } 739 740 on(match) 741 .keyup(function(ev) { 742 if (ev.keyCode === Chars.DOWN || 743 ev.keyCode === Chars.SPACE) { 744 show(); 745 return false; 746 } 747 }) 748 .keydown(function(ev) { 749 if (ev.keyCode === Chars.DOWN || 750 ev.keyCode === Chars.SPACE) { 751 return false; 752 } 753 }) 754 .click(function(ev) { 755 if (is.visible(content)) { 756 hide(ev); 757 } else { 758 show(); 759 } 760 return false; 761 }); 762 } 763 764})(window.Builder = {});
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.