1/* eslint-disable */ 2/** 3 * @author Riccardo Strobbia 4 * @version 1.4 5 * @revision 18/01/2016 17:08 6 */ 7//Backbone.Model Overrides 8 9window.Toolset = window.Toolset || {}; 10 11//Backbone.View Overrides 12if (Backbone && Backbone.View) { 13 Backbone.View.prototype.eventDispatcher = _.extend({}, Backbone.Events); 14} 15 16 17if (typeof WPV_Toolset == 'undefined') { 18 var WPV_Toolset = {}; 19 WPV_Toolset.message = {}; 20 WPV_Toolset.message.container = null; 21} 22 23if (typeof WPV_Toolset.Utils == 'undefined') WPV_Toolset.Utils = {}; 24 25WPV_Toolset.Utils.eventDispatcher = _.extend({}, Backbone.Events); 26 27WPV_Toolset.Utils.restoreEventPropagation = function (event) { 28 if (event.isImmediatePropagationStopped() === false && event.isPropagationStopped() === false) { 29 return event; 30 } 31 32 if (typeof event.originalEvent === undefined) { 33 return event; 34 } 35 36 var refEvent = event.originalEvent; 37 38 try { 39 refEvent.cancelBubble = false; 40 refEvent.defaultPrevented = false; 41 refEvent.returnValue = true; 42 refEvent.timeStamp = ( new Date() ).getTime(); 43 } catch (e) { 44 // console.log(e.message ); 45 return event; 46 } 47 48 49 if (event.target.dispatchEvent) { 50 51 try { 52 event.target.dispatchEvent(refEvent); 53 } catch (e) { 54 55 return; 56 } 57 } else if (event.target.fireEvent) { 58 59 event.target.fireEvent(refEvent); 60 } 61 62 return refEvent; 63}; 64 65WPV_Toolset.Utils.do_ajax_post = function (params, callback_object) { 66 jQuery.post(ajaxurl, params, function (response) { 67 68 if ((typeof(response) !== 'undefined') && response !== null && ( response.message || response.Data || response.data )) { 69 70 if (callback_object && callback_object.success && typeof callback_object.success == 'function') 71 callback_object.success.call(this, response, params); 72 WPV_Toolset.Utils.eventDispatcher.trigger('on_ajax_success_' + params.action, response, params); 73 } 74 else if ((typeof(response) !== 'undefined') && response !== null && response.error) { 75 76 if (callback_object && callback_object.error && typeof callback_object.error == 'function') 77 callback_object.error.call(this, response, params); 78 WPV_Toolset.Utils.eventDispatcher.trigger('on_ajax_error_' + params.action, response, params); 79 } 80 }, 'json') 81 .fail(function (jqXHR, textStatus, errorThrown) { 82 console.log('Ajax call failed', textStatus, errorThrown) 83 if (callback_object && callback_object.fail && typeof callback_object.fail == 'function') 84 callback_object.fail.call(this, errorThrown); 85 WPV_Toolset.Utils.eventDispatcher.trigger('on_ajax_fail_' + params.action, textStatus, errorThrown, params); 86 }) 87 .always(function () { 88 //console.log( arguments ); 89 if (callback_object && callback_object.always && typeof callback_object.always == 'function') 90 callback_object.always.call(this, arguments); 91 WPV_Toolset.Utils.eventDispatcher.trigger('on_ajax_complete_' + params.action, arguments, params); 92 }); 93}; 94 95;(function ($, window, document, undefined) { 96 97 // Create the defaults once 98 var pluginName = "wpvToolsetMessage", 99 dataPlugin = "plugin_" + pluginName, 100 defaults = { 101 text: "Enter a customized text to be displayed", 102 type: '', 103 inline: false, 104 position: "after", 105 header: false, 106 headerText: false, 107 close: false, 108 use_this: true, 109 fadeIn: 100, 110 fadeOut: 100, 111 stay: false, 112 onClose: false, 113 onOpen: false, 114 onDestroy: false, 115 dontShowAgain: null, 116 dontShowAgainText: '', 117 args: [], 118 referTo: null, 119 offestX: -20, 120 offsetY: 0, 121 classname: '', 122 stay_for: 1200, // Ignored when 'msPerCharacter is given.
123 msPerCharacter: 50 // Ignered when 'stay_for' is given. This value is multiplied by the number of defaults.text characters count. 124 }, 125 has_stay = false, 126 is_open = false, 127 prev = null, 128 prev_text = ''; 129 130 // The actual plugin constructor 131 function Plugin(element, options) { 132 var self = this; 133 134 self.container = $(element); 135 136 self.prms = $.extend({}, defaults, options); 137 self._defaults = defaults; 138 self._name = pluginName; 139 140 self.box = null; 141 self.header = null; 142 self.remove = null; 143 self.tag = self.prms.inline ? 'span' : 'p'; 144 self.bool = false; 145 146 if (typeof (options.stay_for) === 'undefined' && typeof(self.prms.msPerCharacter) === 'number') { // If stay_for parameter wasn't passes when the plugin wass called AND msPerCharacter has correct type 147 self.prms.stay_for = self.prms.text.length * self.prms.msPerCharacter; 148 } 149 150 } 151 152 Plugin.prototype = { 153 init: function () { 154 var self = this; 155 156 if (self.container.data('has_message')) { 157 self.destroy(); 158 } 159 160 if (self.container.children().length > 0) { 161 self.container.children().each(function (i) { 162 if ($(this).text() == self.prms.text) { 163 self.bool = true; 164 } 165 }); 166 } 167 168 if (self.bool) return; 169 170 if (has_stay) { 171 if (prev) { 172 var rem = prev; 173 prev = null; 174 has_stay = false; 175 is_open = false; 176 rem.fadeTo(0, 0, function () { 177 rem.remove(); 178 rem = null; 179 }); 180 } 181 } 182 183 if (self.prms.header && self.prms.headerText) { 184 self.box = $('<div class="toolset-alert toolset-alert-' + self.prms.type + ' ' + self.prms.classname + '" />'); 185 self.header = $('<h2 class="toolset-alert-self.header" />'); 186 self.box.append(self.header); 187 self.header.text(self.prms.headerText); 188 self.box.append('<' + self.tag + '></' + self.tag + '>'); 189 self.box.find(self.tag).html(self.prms.text); 190 } 191 else { 192 self.box = $('<' + self.tag + ' class="toolset-alert toolset-alert-' + self.prms.type + ' ' + self.prms.classname + '" />'); 193 self.box.html(self.prms.text); 194 } 195 196 if (self.prms.dontShowAgain && typeof self.prms.dontShowAgain === 'function' && self.prms.dontShowAgainText !== '') { 197 self.$dontContainer = $('<span class="dont-wrap"></span>') 198 self.$dont_show = $('<input type="checkbox" class="toolset-alert-not-again js-icon-not-again">'); 199 self.$dont_label = $('<label class="toolset-alert-not-again-label" for="toolset-alert-not-again"></label>'); 200 self.$dont_label.text(self.prms.dontShowAgainText); 201 self.$dontContainer.append(self.$dont_show, self.$dont_label); 202 self.box.append(self.$dontContainer); 203 204 self.prms.dontShowAgain.call(self.$dont_show, self, self.prms.args); 205 } 206 207 if (self.prms.close) { 208 self.remove = $('<i class="toolset-alert-close fa fa-times-circle icon-remove-sign js-icon-remove-sign"></i>'); 209 self.box.append(self.remove); 210 self.remove.on('click', function (event) { 211 self.wpvMessageRemove(); 212 }); 213 } 214 215 216 //if( is_open ) self.wpvMessageRemove(); 217 if (self.prms.position == 'before') { 218 self.container.prepend(self.box); 219 } else { 220 self.container.append(self.box); 221 } 222 self.container.data('has_message', true); 223 self.box.hide(); 224 225 if (null !== self.prms.referTo) { 226 self.box.css({ 227 "position": "absolute", 228 "z-index": 10000, 229 "top": self.prms.referTo.position().top + self.prms.offestY + "px", 230 "left": self.prms.referTo.position().left + self.prms.referTo.width() + self.prms.offestX + "px" 231 }); 232 } 233 234 self.container.data('message-box', self.box); 235 236 self.box.fadeTo(null != prev ? 0 : self.prms.fadeIn, 1, function () { 237 $(this).trigger('wpv-message-open'); 238 prev = $(this); 239 prev_text = self.prms.text; 240 is_open = true; 241 if (self.prms.onOpen && typeof self.prms.onOpen == 'function') { 242 self.prms.onOpen.apply(self, self.prms.args); 243 } 244 if (self.prms.stay) { 245 has_stay = true; 246 } 247 else { 248 var remove_message = _.bind(self.wpvMessageRemove, self); 249 _.delay(remove_message, self.prms.stay_for); 250 //self.wpvMessageRemove(); 251 } 252 }); 253 254 return self; 255 }, 256 wpvMessageRemove: function () { 257 258 var self = this; 259 260 if (self.box || self.container.data('message-box')) { 261 var box = self.box || self.container.data('message-box'); 262 263 box.fadeTo(self.prms.fadeOut, 0, function () { 264 $(this).trigger('wpv-message-remove'); 265 is_open = false;
266 prev = null; 267 prev_text = ''; 268 has_stay = false; 269 if (self.prms.onClose && typeof self.prms.onClose == 'function') { 270 self.prms.onClose.apply(self, self.prms.args); 271 } 272 273 $(this).remove(); 274 self.container.data('has_message', false); 275 self.container.data('message-box', null); 276 self.box = null; 277 }); 278 } 279 280 return self; 281 }, 282 destroy: function () { 283 $(this).trigger('wpv-message-remove'); 284 this.container.empty(); 285 if (this.prms.onDestroy && typeof this.prms.onDestroy == 'function') { 286 this.prms.onDestroy.apply(this, this.prms.args); 287 } 288 this.box = null; 289 this.container.data('message-box', null); 290 this.container.data('has_message', false); 291 }, 292 has_message: function () { 293 return this.container.data('has_message'); 294 } 295 }; 296 297 298 $.fn[pluginName] = function (arg) { 299 300 return this.each(function () { 301 var args, instance; 302 303 if (!( $(this).data(dataPlugin) instanceof Plugin )) { 304 // if no instance, create one 305 $(this).data(dataPlugin, new Plugin($(this), arg)); 306 } 307 // do not use this one if you want the plugin to be a singleton bound to the DOM element 308 else { 309 // if instance delete reference and do another one 310 $(this).data(dataPlugin, null); 311 $(this).data(dataPlugin, new Plugin($(this), arg)); 312 } 313 314 instance = $(this).data(dataPlugin); 315 316 instance.element = $(this); 317 318 // call Plugin.init( arg ) 319 if (typeof arg === 'undefined' || typeof arg === 'object') { 320 321 if (typeof instance['init'] === 'function') { 322 instance.init(arg); 323 } 324 325 // checks that the requested public method exists 326 } else if (typeof arg === 'string' && typeof instance[arg] === 'function') { 327 328 // copy arguments & remove function name 329 args = Array.prototype.slice.call(arguments, 1); 330 331 // call the method 332 return instance[arg].apply(instance, args); 333 334 } 335 }); 336 }; 337})(jQuery, window, document); 338 339jQuery(function ($) { 340 $.each($('.js-show-toolset-message:not(.js-show-toolset-message-inited)'), function () { 341 $(this) 342 .addClass('js-show-toolset-message-inited') 343 .show() 344 .wpvToolsetHelp(); 345 }); 346}); 347 348if (typeof jQuery.fn.wpvToolsetHelp === 'undefined') { 349 350 /* Help messages */ 351 (function ($) { 352 353 $.fn.wpvToolsetHelp = function (options) { 354 355 var thiz = this; 356 357 var $container = this; 358 var prms = $.extend({ 359 content: ( thiz.contents().length !== 0 ) ? thiz.contents() : "Enter a customized text to be displayed", 360 tutorialButtonText: ( typeof(thiz.data('tutorial-button-text')) !== 'undefined' ) ? thiz.data('tutorial-button-text') : null, 361 tutorialButtonURL: ( typeof(thiz.data('tutorial-button-url')) !== 'undefined' ) ? thiz.data('tutorial-button-url') : null, 362 linkText: ( typeof(thiz.data('link-text')) !== 'undefined' ) ? thiz.data('link-text') : null, 363 linkURL: ( typeof(thiz.data('link-url')) !== 'undefined' ) ? thiz.data('link-url') : null, 364 footer: ( typeof(thiz.data('footer')) !== 'undefined' ) ? thiz.data('footer') : false, 365 classname: ( typeof(thiz.data('classname')) !== 'undefined' ) ? thiz.data('classname') : '', 366 close: ( typeof(thiz.data('close')) !== 'undefined' ) ? thiz.data('close') : true, 367 hidden: ( typeof(thiz.data('hidden')) !== 'undefined' ) ? thiz.data('hidden') : false, 368 onClose: false, 369 args: [] 370 }, options); 371 372 if ( _.isString( prms.content ) ) { 373 prms.content = $('<p>' + prms.content + '</p>'); 374 } 375 376 var $box = $('<div class="toolset-help ' + prms.classname + '"><div class="toolset-help-content"></div><div class="toolset-help-sidebar"></div></div>'); 377
378 var $footer = $('<div class="toolset-help-footer"><button class="js-toolset-help-close js-toolset-help-close-forever button-secondary">' + toolset_utils_texts.wpv_dont_show_it_again + '</button><button class="js-toolset-help-close js-toolset-help-close-once button-primary">' + toolset_utils_texts.wpv_close + '</button></div>'); 379 380 if (prms.footer === true) { 381 $footer.appendTo($box); 382 } 383 384 prms.content.appendTo($box.find('.toolset-help-content')); 385 386 this.wpvHelpRemove = function () { 387 if ($box) 388 $box.fadeOut('fast', function () { 389 // $(this).remove(); 390 if (prms.onClose && typeof prms.onClose === 'function') { 391 prms.onClose.apply($container, prms.args); 392 } 393 }); 394 return this; 395 }; 396 397 if ((prms.tutorialButtonText && prms.tutorialButtonURL) || (prms.linkText && prms.linkURL)) { 398 var $toolbar = $('<p class="toolset-help-content-toolbar"></p>'); 399 $toolbar.appendTo($box.find('.toolset-help-content')); 400 if (prms.tutorialButtonText && prms.tutorialButtonURL) { 401 $('<a href="' + prms.tutorialButtonURL + '" class="btn">' + prms.tutorialButtonText + '</a>').appendTo($toolbar); 402 } 403 if (prms.linkText && prms.linkURL) { 404 $('<a href="' + prms.linkURL + '">' + prms.linkText + '</a>').appendTo($toolbar); 405 } 406 } 407 408 if (prms.close === true) { 409 $('<i class="icon-remove fa fa-times js-toolset-help-close js-toolset-help-close-main"></i>').appendTo($box); 410 } 411 412 // bind close event to all close buttons 413 var $closeButtons = $box.find('.js-toolset-help-close'); 414 if ($closeButtons.length !== 0) { 415 $closeButtons.on('click', function () { 416 $container.wpvHelpRemove(); 417 }); 418 } 419 420 $box.appendTo($container).hide(); 421 if ($container.hasClass('js-show-toolset-message')) { 422 $box.unwrap(); 423 } 424 if (prms.hidden === false) { 425 $box.fadeIn('fast'); 426 } 427 428 return this; 429 }; 430 431 })(jQuery); 432 433} 434 435(function ($) { 436 $.fn.insertAtIndex = function (index, selector) { 437 var opts = $.extend({ 438 index: 0, 439 selector: '<div/>' 440 }, {index: index, selector: selector}); 441 return this.each(function () { 442 var p = $(this); 443 var i = ( ( !isNaN(parseFloat(opts.index)) && isFinite(opts.index) ) ? parseInt(opts.index, 10) : 0); 444 if (i <= 0) 445 p.prepend(opts.selector); 446 else if (i > p.children().length - 1) 447 p.append(opts.selector); 448 else 449 p.children().eq(i).before(opts.selector); 450 }); 451 }; 452})(jQuery); 453 454(function ($) { 455 456 $.fn.loaderOverlay = function (action, options) 457 // action: 'show'|'hide' attributes are optional. 458 // options: fadeInSpeed, fadeOutSpeed, displayOverlay, class. attributes are optional 459 { 460 461 var defaults = { 462 fadeInSpeed: 'fast', 463 fadeOutSpeed: 'fast', 464 displayLoader: true, 465 css: { 466 "opacity": "0.4" 467 }, 468 class: null 469 }; 470 471 var prms = $.extend(defaults, options); 472 var $overlayContainer = this; 473 var $overlayEl = $('<div class="loader-overlay" />'); 474 475 var showOverlay = function () { 476 if (!$overlayContainer.data('has-overlay')) { 477 $overlayEl 478 .appendTo($overlayContainer) 479 .css(prms.css) 480 .hide() 481 .fadeIn(prms.fadeInSpeed, function () { 482 $overlayContainer.data('has-overlay', true); 483 $overlayContainer.data('overlay-el', $overlayEl); 484 if (_.isObject(options) && typeof options.onOpen === 'function') { 485 options.onOpen.call(this, arguments); 486 } 487 }); 488 } 489 }; 490 491 var hideOverlay = function () { 492 if ($overlayContainer.data('has-overlay')) { 493 $overlayContainer.data('overlay-el') 494 .fadeOut(prms.fadeOutSpeed, function () { 495 $overlayEl.detach().remove(); 496 $overlayContainer.data('has-overlay', false); 497 if (options && typeof options.onRemove === 'function') { 498 options.onRemove.call(this, arguments); 499 } 500 }); 501 } 502 }; 503 504 if (prms.class !== null) { 505 $overlayEl.addClass(prms.class); 506 } 507 if (prms.displayLoader) { 508 $('<div class="preloader" />').appendTo($overlayEl); 509 } 510 511 if (typeof(action) !== 'undefined') { // When 'action' parameter is given 512 513 if (action === 'show') { 514 showOverlay(); 515 } 516 else if (action === 'hide') { 517 hideOverlay(); 518 } 519 520 } 521 else { // when the method is called without 'action' parameter 522 523 if ($overlayContainer.data('has-overlay')) { // hide overlay if it's displayed 524 hideOverlay(); 525 } 526 else { // show overlay if not 527 showOverlay(); 528 } 529 530 } 531 532 return this; 533 }; 534 535})(jQuery); 536 537(function ($) { 538 /* 539 Basic usage: 540 $element.ddlWpPointer(); // will show a pointer if it's hidden OR hide a pointer if it's shown 541 542 1. $element have to be valid jQuery selector 543 2. data-toolipt-header HTML attribute is required to display the header 544 3. data-tooltip-content HTML attribute is required to display the content 545 546 Customization: 547 $element.ddlWpPointer('action', // action: 'show' | 'hide' 548 { 549 content: $element // $element have to be valid jQuery selector content element should contain H3 for the header and P for the content. Example: <div><h3>Header</h3><p>Content</p></div> 550 edge: 'left' // 'left' | 'right' | 'top' | 'bottom' 551 align: 'center' // 'center' | 'right' | 'left' 552 offset: 'x y' // example: '0 15' 553 }) 554 555 */ 556 $.fn.ddlWpPointer = function (action, options) { 557 var $el = this; 558 559 //$.jStorage.flush(); 560 561 var defaults = { 562 headerText: function () { 563 var header = $el.data('tooltip-header'); 564 if (header) { 565 return header; 566 } 567 else { 568 return 'use <b>data-tooltip-header="header text"</b> attribute to create a header'; 569 } 570 }, 571 contentText: function () { 572 var content = $el.data('tooltip-content'); 573 if (content) { 574 return content; 575 } 576 else { 577 return 'use <b>data-tooltip-content="content text"</b> attribute to create a content'; 578 } 579 }, 580 content: function () { // returns string by default (data-tooltip-header and data-tooltip-content attibutes), but can be overridden by jQuery obj 581 return '<h3>' + defaults.headerText() + '</h3><p>' + defaults.contentText() + '</p>'; 582 }, 583 edge: 'left', 584 align: 'center', 585 offset: '0 0', 586 stay_hidden: false 587 }; 588 589 var prms = $.extend(defaults, options); 590 591 var showPointer = function () { 592 593 if (!$el.data('has-wppointer')) { 594 595 if( typeof prms.onOpen === 'function' ){ 596 prms.onOpen.call( this, arguments ); 597 } 598 599 $el 600 .pointer({ 601 content: function () { 602 return prms.content; 603 }, 604 pointerClass: 'wp-toolset-pointer wp-toolset-layouts-pointer', 605 position: { 606 edge: prms.edge, 607 align: prms.align, 608 offset: prms.offset 609 }, 610 close: function () { 611 612 $el.data('has-wppointer', false); 613 $el.trigger('help_tooltip_closes', options); 614 } 615 }) 616 .pointer('open'); 617 618 $el.data('has-wppointer', true); 619 620 if( typeof prms.onComplete === 'function' ){ 621 prms.onComplete.call( this, arguments ); 622 } 623 624 } 625 }; 626 627 var hidePointer = function () { 628 629 if ($el.data('has-wppointer')) { 630 631 if( typeof prms.onClose === 'function' ){ 632 prms.onClose.call( this, arguments ); 633 } 634 635 $el.pointer('close'); 636 $el.data('has-wppointer', false); 637 638 } 639 }; 640 641 if (typeof(action) !== 'undefined') { // When 'action' parameter is given 642 643 if (action === 'show' && prms.stay_hidden !== true) { 644 showPointer(); 645 } 646 else if (action === 'hide') { 647 hidePointer(); 648 } 649 650 } 651 else { // when the method is called without 'action' parameter 652 653 if ($el.data('has-wppointer')) { // hide pointer if it's displayed 654 hidePointer(); 655 } 656 else if (prms.stay_hidden !== true) { // show it if not 657 showPointer(); 658 } 659 660 } 661 662 return this; 663 }; 664 665})(jQuery); 666 667WPV_Toolset.Utils.Loader = function () { 668 //fake comment 669 var self = this; 670 671 self.loading = false;
672 self.el = null; 673 674 self.loader = jQuery('<div class="ajax-loader spinner"></div>'); 675 676 self.loadShow = function (el, after) { 677 self.el = el; 678 self.loading = true; 679 680 if (typeof after === 'undefined') { 681 self.loader.prependTo(self.el).css('visibility', 'visible').show(); 682 } 683 else { 684 self.loader.insertAfter(self.el).css('visibility', 'visible').show(); 685 } 686 687 return self.loader; 688 }; 689 self.loadHide = function () { 690 var $completeFlag = jQuery('<i class="fa fa-check" aria-hidden="true"></i>') 691 692 _.each(self.loader[0].attributes, function (attribute) { 693 if (attribute.name === 'style') { 694 $completeFlag.attr(attribute.name, attribute.value); 695 } 696 }); 697 698 var adjustPosition = function( positionName, position ) { 699 position = parseInt(position); 700 701 if (position < 0) { 702 $completeFlag.css(positionName, ''); 703 } else { 704 position += 8; 705 $completeFlag.css(positionName, position.toString() + 'px'); 706 } 707 }; 708 709 adjustPosition( 'left', self.loader.css('left') ); 710 adjustPosition( 'right', self.loader.css('right') ); 711 712 self.loader = $completeFlag.replaceAll(self.loader).css({ 713 color: 'green', 714 fontSize: '22px' 715 }); 716 717 self.loader.fadeOut(1800, function () { 718 self.loader = jQuery('<div class="ajax-loader spinner"></div>').replaceAll( jQuery(this) ); 719 self.loading = false; 720 self.loader.remove(); 721 jQuery(this).remove(); 722 }); 723 724 return self.loader; 725 }; 726}; 727 728if (typeof _ != 'undefined') { 729 WPV_Toolset.Utils.flatten = function (x, result, prefix) { 730 if (_.isObject(x)) { 731 _.each(x, function (v, k) { 732 WPV_Toolset.Utils.flatten(v, result, prefix ? prefix + '_' + k : k) 733 }) 734 } else { 735 result[prefix] = x 736 } 737 return result 738 }; 739 WPV_Toolset.Utils.flatten_filter_by_key = function (x, result, prefix, filter) { 740 var res = [], 741 find = WPV_Toolset.Utils.flatten(x, result, prefix); 742 743 if (!filter) return _.values(find); 744 745 _.each(find, function (element, index, list) { 746 if (index.indexOf(prefix ? prefix + '_' + filter : filter) !== -1 || filter === index) 747 res.push(element); 748 }); 749 750 return res; 751 } 752 WPV_Toolset.Utils.containsObject = function (obj, list) { 753 var res = _.find(list, function (val) { 754 return _.isEqual(obj, val); 755 }); 756 return (_.isObject(res)) ? true : false; 757 }; 758} 759; 760 761 762(function ($) { 763 $.fn.textWidth = function () { 764 var text = this.html() || this.text() || this.val(); 765 return ( $.textWidth(text) ); 766 }; 767 $.textWidth = function (text) { 768 var div = $('#textWidth'); 769 if (div.length === 0) 770 div = $('<div id="textWidth" style="display: none;"></div>').appendTo($('body')); 771 div.html(text); 772 return (div.width()); 773 }; 774})(jQuery); 775 776//Courtesy from http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery 777WPV_Toolset.Utils.escapeHtml = function (str) { 778 if (typeof(str) == "string") { 779 try { 780 var newStr = ""; 781 var nextCode = 0; 782 for (var i = 0; i < str.length; i++) { 783 nextCode = str.charCodeAt(i); 784 if (nextCode > 0 && nextCode < 128) { 785 newStr += "&#" + nextCode + ";"; 786 } 787 else { 788 newStr += "?"; 789 } 790 } 791 return newStr; 792 } 793 catch (err) { 794 } 795 } 796 else { 797 return str; 798 } 799}; 800 801WPV_Toolset.Utils.editor_decode64 = function (input) { 802 var output = "", 803 chr1, chr2, chr3 = "", 804 enc1, enc2, enc3, enc4 = "", 805 i = 0, 806 keyStr = "ABCDEFGHIJKLMNOP" + 807 "QRSTUVWXYZabcdef" + 808 "ghijklmnopqrstuv" +
809 "wxyz0123456789+/" + 810 "="; 811 812 // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 813 var base64test = /[^A-Za-z0-9\+\/\=]/g; 814 if (base64test.exec(input)) { 815 alert("There were invalid base64 characters in the input text.\n" + 816 "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + 817 "Expect errors in decoding."); 818 } 819 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 820 821 do { 822 enc1 = keyStr.indexOf(input.charAt(i++)); 823 enc2 = keyStr.indexOf(input.charAt(i++)); 824 enc3 = keyStr.indexOf(input.charAt(i++)); 825 enc4 = keyStr.indexOf(input.charAt(i++)); 826 827 chr1 = (enc1 << 2) | (enc2 >> 4); 828 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 829 chr3 = ((enc3 & 3) << 6) | enc4; 830 831 output = output + String.fromCharCode(chr1); 832 833 if (enc3 != 64) { 834 output = output + String.fromCharCode(chr2); 835 } 836 if (enc4 != 64) { 837 output = output + String.fromCharCode(chr3); 838 } 839 840 chr1 = chr2 = chr3 = ""; 841 enc1 = enc2 = enc3 = enc4 = ""; 842 843 } while (i < input.length); 844 845 return WPV_Toolset.Utils.editor_utf8_decode(output); 846}; 847 848WPV_Toolset.Utils.editor_utf8_decode = function (utftext) { 849 var string = ""; 850 var i = 0; 851 var c = c1 = c2 = 0; 852 853 while (i < utftext.length) { 854 855 c = utftext.charCodeAt(i); 856 857 if (c < 128) { 858 string += String.fromCharCode(c); 859 i++; 860 } 861 else if ((c > 191) && (c < 224)) { 862 c2 = utftext.charCodeAt(i + 1); 863 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 864 i += 2; 865 } 866 else { 867 c2 = utftext.charCodeAt(i + 1); 868 c3 = utftext.charCodeAt(i + 2); 869 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 870 i += 3; 871 } 872 873 } 874 875 return string; 876}; 877 878// THE TOOLTIP // 879; 880(function ($, window, document, undefined) { 881 882 // Create the defaults once 883 var pluginName = "toolsetTooltip", 884 dataPlugin = "plugin_" + pluginName, 885 undefined, 886 defaults = { 887 top: undefined, 888 text: '', 889 close: null, 890 open: null, 891 additionalClass: '' 892 }; 893 894 // The actual plugin constructor 895 function Plugin(element, options) { 896 897 this.$element = element; 898 this.settings = $.extend({}, defaults, options); 899 this._defaults = defaults; 900 this._name = pluginName; 901 this._remove_tooltip = null; 902 } 903 904 // Avoid Plugin.prototype conflicts 905 $.extend(Plugin.prototype, { 906 init: function () { 907 var self = this; 908 this.$element.on('mouseenter', function (event) { 909 event.stopImmediatePropagation(); 910 self.show(event); 911 jQuery(event.target).trigger('tooltip_show', event); 912 }); 913 this.$element.on('mouseleave', function (event) { 914 event.stopImmediatePropagation(); 915 self.hide(event); 916 jQuery(event.target).trigger('tooltip_hide', event); 917 }); 918 }, 919 show: function (event) { 920 var self = this, 921 $tooltip = $('<div class="toolset-tooltip" />'), 922 offset = self.$element.offset(), 923 offset_top = typeof self.settings.top === 'undefined' ? 20 : self.settings.top; 924 925 if (this.settings.additionalClass) { 926 $tooltip.addClass(this.settings.additionalClass); 927 } 928 929 self._remove_tooltip = $tooltip; 930 931 $tooltip 932 .appendTo('body') 933 .text(this.settings.text || self.$element.data('tooltip-text')) 934 .css({ 935 'top': offset.top - $tooltip.height() - offset_top, 936 'left': offset.left - ($tooltip.outerWidth() / 2) + (self.$element.outerWidth() / 2), 937 'zIndex': '9999999' 938 }) 939 .fadeIn(100); 940 941 // Probably $elem doesn't is removed before 'click' event takes place 942 // So we need to call _manageCellTooltip( $elem, 'hide') somewhere... but i don't know
942where ;) 943 944 self.$element.on('mousedown', function () { 945 946 if (self._remove_tooltip) { 947 self._remove_tooltip.remove(); 948 self._remove_tooltip = null; 949 } 950 }); 951 952 if (self.settings.open !== null && self.settings.open instanceof Function) { 953 self.settings.open.call(self); 954 } 955 956 return $tooltip; 957 }, 958 hide: function (event) { 959 var self = this; 960 961 if (self._remove_tooltip) { 962 if (self.settings.close !== null && self.settings.close instanceof Function) { 963 self.settings.close.call(self); 964 } 965 self._remove_tooltip.remove(); 966 self._remove_tooltip = null; 967 } 968 } 969 }); 970 971 $.fn[pluginName] = function (arg) { 972 973 return this.each(function () { 974 var args, instance; 975 976 if (!( $(this).data(dataPlugin) instanceof Plugin )) { 977 // if no instance, create one 978 $(this).data(dataPlugin, new Plugin($(this), arg)); 979 } 980 981 instance = $(this).data(dataPlugin); 982 instance.element = $(this); 983 984 // call Plugin.init( arg ) 985 if (typeof arg === 'undefined' || typeof arg === 'object') { 986 987 if (typeof instance['init'] === 'function') { 988 instance.init(arg); 989 } 990 991 // checks that the requested public method exists 992 } else if (typeof arg === 'string' && typeof instance[arg] === 'function') { 993 994 // copy arguments & remove function name 995 args = Array.prototype.slice.call(arguments, 1); 996 997 // call the method 998 return instance[arg].apply(instance, args); 999 1000 } 1001 }); 1002 }; 1003 1004})(jQuery, window, document); 1005 1006;(function ($, window, document, undefined) { 1007 /* 1008 1009 highlight v3 !! Modified by Jon Raasch (http://jonraasch.com) to fix IE6 bug !! 1010 1011 Highlights arbitrary terms. 1012 1013 <http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html> 1014 1015 MIT license. 1016 1017 Johann Burkard 1018 <http://johannburkard.de> 1019 <mailto:[email protected]> 1020 1021 */ 1022 var defaults = { 1023 className: 'toolset-highlighted' 1024 }, 1025 options = {}; 1026 1027 jQuery.fn.highlight = function (pat, option) { 1028 1029 options = jQuery.extend(options, defaults, option) 1030 1031 function innerHighlight(node, pat) { 1032 var skip = 0; 1033 1034 if (node.nodeType == 3) { 1035 var pos = node.data.toUpperCase().indexOf(pat); 1036 if (pos >= 0) { 1037 var spannode = document.createElement('span'); 1038 spannode.className = options.className; 1039 var middlebit = node.splitText(pos); 1040 var endbit = middlebit.splitText(pat.length); 1041 var middleclone = middlebit.cloneNode(true); 1042 spannode.appendChild(middleclone); 1043 middlebit.parentNode.replaceChild(spannode, middlebit); 1044 skip = 1; 1045 } 1046 } 1047 else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { 1048 for (var i = 0; i < node.childNodes.length; ++i) { 1049 i += innerHighlight(node.childNodes[i], pat); 1050 } 1051 } 1052 return skip; 1053 } 1054 1055 return this.each(function () { 1056 innerHighlight(this, pat.toUpperCase()); 1057 }); 1058 }; 1059 1060 jQuery.fn.removeHighlight = function () { 1061 function newNormalize(node) { 1062 for (var i = 0, children = node.childNodes, nodeCount = children.length; i < nodeCount; i++) { 1063 var child = children[i]; 1064 if (child.nodeType == 1) { 1065 newNormalize(child); 1066 continue; 1067 } 1068 if (child.nodeType != 3) { 1069 continue; 1070 } 1071 var next = child.nextSibling; 1072 if (next == null || next.nodeType != 3) { 1073 continue; 1074 } 1075 var combined_text = child.nodeValue + next.nodeValue; 1076 new_node = node.ownerDocument.createTextNode(combined_text); 1077 node.insertBefore(new_node, child); 1078 node.removeChild(child); 1079 node.removeChild(next); 1080 i--; 1081 nodeCount--; 1082 } 1083 } 1084 1085 return this.find("span." + options.className).each(function () { 1086 var thisParent = this.parentNode; 1087 thisParent.replaceChild(this.firstChild, this); 1088 newNormalize(thisParent); 1089 }).end(); 1090 }; 1091 1092}(jQuery, window, document)); 1093 1094var waitForFinalEvent = (function () { 1095 var timers = {}; 1096 return function (callback, ms, uniqueId) { 1097 if (!uniqueId) { 1098 uniqueId = "Don't call this twice without a uniqueId"; 1099 } 1100 if (timers[uniqueId]) { 1101 clearTimeout(timers[uniqueId]); 1102 } 1103 1104 timers[uniqueId] = setTimeout(callback, ms); 1105 }; 1106})(); 1107 1108
1109WPV_Toolset.Utils._strip_scripts = function (data) { 1110 1111 if (!data) return ''; 1112 1113 if (_.isString(data) === false) return ''; 1114 1115 data = data.replace(/</g, "|-lt-|"); 1116 data = data.replace(/>/g, "|-gt-|"); 1117 data = data.replace(/&(\w+);/g, "&$1;"); // Preserve entities (rafael.v) 1118 1119 var out = data.replace(/<.*?script.*?>.*?<\/.*?script.*?>/igm, ""); 1120 out = out.replace(/</g, "<"); 1121 out = out.replace(/>/g, ">"); 1122 out = out.replace(/&(\w+);/g, "&$1;"); // Preserve entities (rafael.v) 1123 out = out.replace(/\|-lt-\|/g, '<'); 1124 out = out.replace(/\|-gt-\|/g, '>'); 1125 return out; 1126}; 1127 1128if (!String.prototype.trim) { 1129 (function () { 1130 // Make sure we trim BOM and NBSP 1131 var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; 1132 String.prototype.trim = function () { 1133 return this.replace(rtrim, ''); 1134 }; 1135 })(); 1136} 1137 1138 1139/** 1140 * Strip known tags and escape the rest of the string. 1141 * 1142 * Warning! Since underscore.js 1.2.2 the _.escape() method got dumber and 1143 * now it double-escapes HTML entities (read: https://github.com/jashkenas/underscore/issues/350). 1144 * If you want to avoid double-escaping, you can do it by: 1145 * 1146 * WPV_Toolset.Utils._strip_tags_and_preserve_text(_.unescape(text)) 1147 * 1148 * Note: Although the "_" prefix suggests this function is private, it's also used elsewhere. 1149 * 1150 * @param {string} text 1151 * @returns {string} 1152 * @since unknown 1153 */ 1154WPV_Toolset.Utils._strip_tags_and_preserve_text = function (text) { 1155 var rex = /<\/?(a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdi|bdo|bgsound|big|blink|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|data|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|isindex|kbd|keygen|label|legend|li|link|listing|main|map|mark|marquee|menu|menuitem|meta|meter|nav|nobr|noframes|noscript|object|ol|optgroup|option|output|p|param|plaintext|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|source|spacer|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video|wbr|xmp)\b[^<>]*>/ig 1156 return _.escape(text.replace(rex, "")).trim(); 1157}; 1158 1159 1160/** 1161 * Setup the behaviour of browser when user tries to leave the page. 1162 * 1163 * When user tries to leave the page, check if confirmation is needed, and if so, displays a confirmation message and 1164 * runs custom action. 1165 * 1166 * WARNING: http://stackoverflow.com/a/37782307 1167 * 1168 * @param {function} checkIfConfirmationNeededCallback Should return true if confirmation should be shown (e.g. unsaved data). 1169 * @param {function|null} onBeforeUnloadCallback Will be called before showing the confirmation. 1170 * @param {string} confirmationMessage Confirmation message that should be shown by the browser. 1171 * @since unknown 1172 */ 1173WPV_Toolset.Utils.setConfirmUnload = function (checkIfConfirmationNeededCallback, onBeforeUnloadCallback, confirmationMessage) { 1174 window.onbeforeunload = function (e) { 1175 if (checkIfConfirmationNeededCallback()) { 1176 1177 if(_.isFunction(onBeforeUnloadCallback)) { 1178 onBeforeUnloadCallback(); 1179 } 1180 1181 // For IE and Firefox prior to version 4 1182 if (e) { 1183 e.returnValue = confirmationMessage; 1184 } 1185 return confirmationMessage; 1186 } 1187 }; 1188}; 1189 1190if (typeof _ !== 'undefined' && typeof _.capitalize === 'undefined') { 1191 _.mixin({ 1192 capitalize: function (string) { 1193 return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase(); 1194 } 1195 }); 1196} 1197 1198 1199WPV_Toolset.Utils.has_shortcode = function (string) { 1200 var search = /\[(\[?)(\w*?\-*?\w*?)*?(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/g; 1201 return decodeURIComponent(string).search(search) !== -1; 1202}; 1203 1204 1205/** 1206 * Courtesy from: https://gist.github.com/alexey-bass/1115557 1207 * @param left 1208 * @param right 1209 * @returns int 1210 */ 1211WPV_Toolset.Utils.versionCompare = function (left, right) { 1212 if (typeof left + typeof right != 'stringstring') 1213 return false;
1214 1215 var a = left.split('.') 1216 , b = right.split('.') 1217 , i = 0, len = Math.max(a.length, b.length); 1218 1219 for (; i < len; i++) { 1220 if ((a[i] && !b[i] && parseInt(a[i]) > 0) || (parseInt(a[i]) > parseInt(b[i]))) { 1221 return 1; 1222 } else if ((b[i] && !a[i] && parseInt(b[i]) > 0) || (parseInt(a[i]) < parseInt(b[i]))) { 1223 return -1; 1224 } 1225 } 1226 1227 return 0; 1228}; 1229 1230 1231/** 1232 * Get a query argument value from a URL. 1233 * 1234 * @param {string} name Argument name. 1235 * @param {string} [url] Source URL. Optional. If missing, current page URL will be used. 1236 * @returns {string|null} 1237 * @since 2.1 1238 * @link http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript 1239 */ 1240WPV_Toolset.Utils.getParameterByName = function (name, url) { 1241 1242 if (!url) { 1243 url = window.location.href; 1244 } 1245 1246 name = name.replace(/[\[\]]/g, "\\$&"); 1247 1248 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)", "i"); 1249 1250 var results = regex.exec(url); 1251 1252 if (!results) { 1253 return null; 1254 } 1255 1256 if (!results[2]) { 1257 return ''; 1258 } 1259 1260 return decodeURIComponent(results[2].replace(/\+/g, " ")); 1261}; 1262 1263 1264/** 1265 * Add, update or remove query string argument. 1266 * 1267 * @param {string} key Argument name. 1268 * @param {string} [value] Argument value. Not supplying a value will remove the parameter, supplying one will 1269 * add/update the argument. 1270 * @param {string} [url] If no URL is supplied, it will be grabbed from window.location 1271 * @returns {string} 1272 * @link http://stackoverflow.com/a/11654596/3191395 1273 */ 1274WPV_Toolset.Utils.updateUrlQuery = function (key, value, url) { 1275 if (!url) { 1276 url = window.location.href; 1277 } 1278 var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"); 1279 var hash; 1280 1281 if (re.test(url)) { 1282 if (typeof value !== 'undefined' && value !== null) { 1283 return url.replace(re, '$1' + key + "=" + value + '$2$3'); 1284 } else { 1285 hash = url.split('#'); 1286 url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, ''); 1287 if (typeof hash[1] !== 'undefined' && hash[1] !== null) { 1288 url += '#' + hash[1]; 1289 } 1290 return url; 1291 } 1292 } else { 1293 if (typeof value !== 'undefined' && value !== null) { 1294 var separator = url.indexOf('?') !== -1 ? '&' : '?'; 1295 hash = url.split('#'); 1296 url = hash[0] + separator + key + '=' + value; 1297 if (typeof hash[1] !== 'undefined' && hash[1] !== null) { 1298 url += '#' + hash[1]; 1299 } 1300 return url; 1301 } else { 1302 return url; 1303 } 1304 } 1305}; 1306 1307 1308/** 1309 * Tools for manipulating spinners in a native WP way. 1310 * 1311 * If WP changes the behaviour, we'll need only to update this object. 1312 * 1313 * @type {{create: WPV_Toolset.Utils.Spinner.create, show: WPV_Toolset.Utils.Spinner.show, hide: WPV_Toolset.Utils.Spinner.hide, find: WPV_Toolset.Utils.Spinner.find}} 1314 */ 1315WPV_Toolset.Utils.Spinner = { 1316 create: function () { 1317 return jQuery('<span class="spinner"></span>'); 1318 }, 1319 show: function (spinner, show) { 1320 if (typeof(show) === 'undefined') { 1321 show = true; 1322 } 1323 1324 if (!show) { 1325 WPV_Toolset.Utils.Spinner.hide(spinner); 1326 return; 1327 } 1328 1329 spinner.addClass('is-active'); 1330 }, 1331 hide: function (spinner) { 1332 spinner.removeClass('is-active'); 1333 }, 1334 find: function (parentElement) { 1335 return parentElement.find('.spinner'); 1336 } 1337}; 1338 1339 1340/** 1341 * AJAX call helper. 1342 * 1343 * WIP, to be merged with WPV_Toolset.Utils.do_ajax_post(). 1344 * 1345 * @type {{parseResponse: WPV_Toolset.Utils.Ajax.parseResponse, call: WPV_Toolset.Utils.Ajax.call}} 1346 * @since 2.1 1347 */ 1348WPV_Toolset.Utils.Ajax = { 1349 1350 /** 1351 * Ensure that response is always an object with the success property. 1352 * 1353 * If it's not, return a dummy object indicating a failure. 1354 * 1355 * @param response {*} Response from the AJAX call. 1356 * @returns {{success: boolean}} Sanitized response. 1357 * 1358 * @since 2.1 1359 */ 1360 parseResponse: function (response) { 1361 if (typeof(response.success) === 'undefined') { 1362 console.log("parseResponse: no success value", response); 1363 return {success: false}; 1364 } else { 1365 return response; 1366 } 1367 }, 1368 1369 1370 /** 1371 * Perform an AJAX call on field definitions. 1372 * 1373 * @param {*} data AJAX call parameters. Needs to include 'action' and 'wpnonce'. 1374 * @param {function} successCallback Callback to be used after AJAX call is completed. It will get two parameters, 1375 * the complete AJAX response and the 'data' element for convenience. 1376 * @param {function}
1376 [failCallback] Analogous to successCallback for the case of failure. If missing, 1377 * successCallback will be used instead. 1378 * 1379 * @since 2.1 1380 */ 1381 call: function (data, successCallback, failCallback) { 1382 1383 if (typeof(failCallback) === 'undefined') { 1384 failCallback = successCallback; 1385 } 1386 1387 jQuery.post({ 1388 async: true, 1389 url: ajaxurl, 1390 data: data, 1391 1392 success: function (originalResponse) { 1393 var response = WPV_Toolset.Utils.Ajax.parseResponse(originalResponse); 1394 1395 if (response.success) { 1396 successCallback(response, response.data || {}); 1397 } else { 1398 failCallback(response, response.data || {}); 1399 } 1400 }, 1401 1402 error: function (ajaxContext) { 1403 console.log('Error:', ajaxContext.responseText); 1404 failCallback({success: false, data: {}}, {}); 1405 } 1406 }); 1407 1408 } 1409 1410}; 1411 1412 1413WPV_Toolset.Utils._template = function (template, data, settings) { 1414 var options = _.defaults({}, settings, _.templateSettings), 1415 _template = null; 1416 1417 if (WPV_Toolset.Utils.versionCompare(_.VERSION, '1.7') >= 0) { 1418 _template = _.template(template, options); 1419 return _template(data); 1420 } else { 1421 return _.template(template, data, options); 1422 } 1423}; 1424 1425// override dialog whenever toolset is active and take possession 1426/** 1427 * @todo This should not be here: 1428 * dialogs with specific classnames should get it directly. 1429 * We should not be pre-setting all jQuery UI dialogs dialogClass setting, 1430 * we are not good players here. 1431 */ 1432if (jQuery && jQuery.ui && jQuery.ui.dialog) { 1433 jQuery.extend(jQuery.ui.dialog.prototype.options, { 1434 dialogClass: 'toolset-ui-dialog' 1435 }); 1436} 1437 1438/** 1439 * We do not use this anymore but we need to keep it for backwards compatibility. 1440 * 1441 * All quicktags-related logic belongs now to toolset-quicktags.js 1442 * However, older versions for some plugin might be expecting this to be defined. 1443 * 1444 * We took out the quicktags and wplink dependencies from this script; 1445 * if they exists, the function will do something, otherwise it will do nothing. 1446 * 1447 * This means that although we want all plugins to be updated, 1448 * using an onl version for any of them will not break, 1449 * but it might miss sone functionality. 1450 */ 1451if (typeof Toolset.add_qt_editor_buttons !== 'function') { 1452 Toolset.add_qt_editor_buttons = function (qt_instance, editor_instance) { 1453 if ( 1454 typeof wpLink === 'undefined' 1455 || typeof QTags === 'undefined' 1456 ) { 1457 return; 1458 } 1459 var activeUrlEditor, html; 1460 QTags._buttonsInit(); 1461 var editorInstance = {}; 1462 editorInstance[qt_instance.id] = editor_instance; 1463 1464 for (var button_name in qt_instance.theButtons) { 1465 if (qt_instance.theButtons.hasOwnProperty(button_name)) { 1466 qt_instance.theButtons[button_name].old_callback = qt_instance.theButtons[button_name].callback; 1467 if (qt_instance.theButtons[button_name].id == 'img') { 1468 qt_instance.theButtons[button_name].callback = function (element, canvas, ed) { 1469 var t = this, 1470 id = jQuery(canvas).attr('id'), 1471 selection = editorInstance[id].getSelection(), 1472 e = "http://", 1473 g = prompt(quicktagsL10n.enterImageURL, e), 1474 f = prompt(quicktagsL10n.enterImageDescription, ""); 1475 t.tagStart = '<img src="' + g + '" alt="' + f + '" />'; 1476 selection = t.tagStart; 1477 t.closeTag(element, ed); 1478 editorInstance[id].replaceSelection(selection, 'end'); 1479 editorInstance[id].focus(); 1480 } 1481 } else if (qt_instance.theButtons[button_name].id == 'close') { 1482 1483 } else if (qt_instance.theButtons[button_name].id == 'link') { 1484 var t = this; 1485 qt_instance.theButtons[button_name].callback = 1486 function (b, c, d, e) { 1487 activeUrlEditor = c; 1488 var f, g = this; 1489 return "undefined" != typeof wpLink ? void wpLink.open(d.id) : (e || (e = "http://"), void(g.isOpen(d) === !1 ? (f = prompt(quicktagsL10n.enterURL, e), f && (g.tagStart = '<a href="' + f + '">', a.TagButton.prototype.callback.call(g, b, c, d))) : a.TagButton.prototype.callback.call(g, b, c, d))) 1490 }; 1491 jQuery('#wp-link-submit').off(); 1492 jQuery('#wp-link-submit').on('click', function (event) { 1493 event.preventDefault(); 1494 if (wpLink.isMCE()) { 1495 wpLink.mceUpdate(); 1496 } else { 1497 var id = jQuery(activeUrlEditor).attr('id'), 1498 selection = editorInstance[id].getSelection(), 1499 inputs = {}, 1500 attrs, text, title, html; 1501 inputs.wrap = jQuery('#wp-link-wrap'); 1502 inputs.backdrop = jQuery('#wp-link-backdrop'); 1503 if (jQuery('#link-target-checkbox').length > 0) { 1504 // Backwards compatibility - before WordPress 4.2 1505 inputs.text = jQuery('#link-title-field'); 1506 attrs = wpLink.getAttrs(); 1507 text = inputs.text.val(); 1508 if (!attrs.href) { 1509 return; 1510 } 1511 // Build HTML 1512 html = '<a href="' + attrs.href + '"'; 1513 if (attrs.target) { 1514 html += ' target="' + attrs.target + '"'; 1515 } 1516 if (text) { 1517 title = text.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); 1518 html += ' title="' + title + '"'; 1519 } 1520 html += '>'; 1521 html += text || selection; 1522 html += '</a>'; 1523 t.tagStart = html; 1524 selection = t.tagStart; 1525 } else { 1526 // WordPress 4.2+ 1527 inputs.text = jQuery('#wp-link-text'); 1528 attrs = wpLink.getAttrs(); 1529 text = inputs.text.val(); 1530 if (!attrs.href) { 1531 return; 1532 } 1533 // Build HTML 1534 html = '<a href="' + attrs.href + '"'; 1535 if (attrs.target) { 1536 html += ' target="' + attrs.target + '"'; 1537 } 1538 html += '>'; 1539 html += text || selection; 1540 html += '</a>'; 1541 selection = html; 1542 } 1543 jQuery(document.body).removeClass('modal-open'); 1544 inputs.backdrop.hide(); 1545 inputs.wrap.hide(); 1546 jQuery(document).trigger('wplink-close', inputs.wrap); 1547 editorInstance[id].replaceSelection(selection, 'end'); 1548 editorInstance[id].focus(); 1549 return false;
1550 } 1551 }); 1552 } else { 1553 qt_instance.theButtons[button_name].callback = function (element, canvas, ed) { 1554 var id = jQuery(canvas).attr('id'), 1555 t = this, 1556 selection = editorInstance[id].getSelection(); 1557 if (selection.length > 0) { 1558 if (!t.tagEnd) { 1559 selection = selection + t.tagStart; 1560 } else { 1561 selection = t.tagStart + selection + t.tagEnd; 1562 } 1563 } else { 1564 if (!t.tagEnd) { 1565 selection = t.tagStart; 1566 } else if (t.isOpen(ed) === false) { 1567 selection = t.tagStart; 1568 t.openTag(element, ed); 1569 } else { 1570 selection = t.tagEnd; 1571 t.closeTag(element, ed); 1572 } 1573 } 1574 editorInstance[id].replaceSelection(selection, 'end'); 1575 editorInstance[id].focus(); 1576 } 1577 } 1578 } 1579 } 1580 } 1581} 1582
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.