Best JavaScript code snippet using wpt
sab-preview.js
Source:sab-preview.js
1wp.SAB = 'undefined' === typeof( wp.SAB ) ? {} : wp.SAB;2wp.SAB.views = 'undefined' === typeof( wp.SAB.views ) ? {} : wp.SAB.views;3wp.SAB.models = 'undefined' === typeof( wp.SAB.models ) ? {} : wp.SAB.models;4wp.SAB.contructors = 'undefined' === typeof( wp.SAB.contructors ) ? [] : wp.SAB.contructors;5wp.SAB.models.Settings = Backbone.Model.extend({6 initialize: function(){7 var model = this;8 var view = new wp.SAB.views.Settings({9 model: this,10 el: jQuery( '#sabox-container' )11 });12 this.set( 'view', view );13 },14 getAttribute: function( type ){15 var value = this.get( type );16 if ( 'undefined' == typeof value ) {17 value = jQuery( '#' + type ).val();18 }19 return value;20 }21});22wp.SAB.views.Settings = Backbone.View.extend({23 events: {24 // Settings specific events25 'keyup input': 'updateModel',26 'keyup textarea': 'updateModel',27 'change input': 'updateModel',28 'change textarea': 'updateModel',29 'blur textarea': 'updateModel',30 'change select': 'updateModel',31 },32 initialize: function( args ) {33 // Check for Google Fonts34 this.checkGoogleFonts();35 this.listenTo( this.model, 'change:sab_email', this.emailVisibility );36 // Author website37 this.listenTo( this.model, 'change:sab_web', this.websiteVisibility );38 this.listenTo( this.model, 'change:sab_web_position', this.websitePosition );39 // Social Icons40 this.listenTo( this.model, 'change:sab_hide_socials', this.socialsVisibility );41 this.listenTo( this.model, 'change:sab_colored', this.socialIconTypeVisibility );42 this.listenTo( this.model, 'change:sab_icons_style', this.socialIconTypeVisibility );43 this.listenTo( this.model, 'change:sab_social_hover', this.socialIconHover );44 this.listenTo( this.model, 'change:sab_box_long_shadow', this.socialIconShadow );45 this.listenTo( this.model, 'change:sab_box_thin_border', this.socialIconBorder );46 // Avatar47 this.listenTo( this.model, 'change:sab_avatar_style', this.avatarStyle );48 this.listenTo( this.model, 'change:sab_avatar_hover', this.avatarHover );49 // Padding50 this.listenTo( this.model, 'change:sab_box_padding_top_bottom', this.adjustPadding );51 this.listenTo( this.model, 'change:sab_box_padding_left_right', this.adjustPadding );52 // Author Box Border53 this.listenTo( this.model, 'change:sab_box_border_width', this.adjustBorder );54 this.listenTo( this.model, 'change:sab_box_border', this.adjustBorder );55 // Adjust Author name settings56 this.listenTo( this.model, 'change:sab_box_name_size', this.adjustAuthorName );57 this.listenTo( this.model, 'change:sab_box_name_font', this.adjustAuthorName );58 this.listenTo( this.model, 'change:sab_box_author_color', this.adjustAuthorName );59 // Adjust Author website settings60 this.listenTo( this.model, 'change:sab_box_web_font', this.adjustAuthorWebsite );61 this.listenTo( this.model, 'change:sab_box_web_size', this.adjustAuthorWebsite );62 this.listenTo( this.model, 'change:sab_box_web_color', this.adjustAuthorWebsite );63 // Adjust Author description settings64 this.listenTo( this.model, 'change:sab_box_desc_font', this.adjustAuthorDescription );65 this.listenTo( this.model, 'change:sab_box_desc_size', this.adjustAuthorDescription );66 this.listenTo( this.model, 'change:sab_box_author_p_color', this.adjustAuthorDescription );67 this.listenTo( this.model, 'change:sab_box_author_a_color', this.adjustAuthorDescription );68 this.listenTo( this.model, 'change:sab_desc_style', this.adjustAuthorDescription );69 // Icon Size70 this.listenTo( this.model, 'change:sab_box_icon_size', this.adjustIconSize );71 // Social Bar Background Color72 this.listenTo( this.model, 'change:sab_box_icons_back', this.changeSocialBarBackground );73 // Author Box Background Color74 this.listenTo( this.model, 'change:sab_box_author_back', this.changeAuthorBoxBackground );75 // Author Box Background Color76 this.listenTo( this.model, 'change:sab_box_icons_color', this.changeSocialIconsColor );77 },78 emailVisibility: function() {79 var showEmail = wp.SAB.Settings.get( 'sab_email' );80 if ( '1' == showEmail ) {81 jQuery('.sab-user_email').parent().show();82 }else{83 jQuery('.sab-user_email').parent().hide();84 }85 },86 socialsVisibility: function(){87 var hideSocials = wp.SAB.Settings.get( 'sab_hide_socials' );88 if ( '1' == hideSocials ) {89 jQuery('.saboxplugin-socials').hide();90 }else{91 jQuery('.saboxplugin-socials').show();92 }93 },94 websiteVisibility: function(){95 var showWesite = wp.SAB.Settings.get( 'sab_web' );96 if ( '1' == showWesite ) {97 jQuery('.saboxplugin-web').show();98 }else{99 jQuery('.saboxplugin-web').hide();100 }101 },102 websitePosition: function() {103 var attribute = wp.SAB.Settings.get( 'sab_web_position' );104 105 if ( '1' == attribute ) {106 jQuery('.saboxplugin-web').addClass( 'sab-web-position' );107 }else{108 jQuery('.saboxplugin-web').removeClass( 'sab-web-position' );109 }110 },111 socialIconTypeVisibility: function() {112 var iconType = wp.SAB.Settings.getAttribute( 'sab_colored' ),113 iconStyle = wp.SAB.Settings.getAttribute( 'sab_icons_style' );114 jQuery('.saboxplugin-socials').removeClass( 'sab-show-simple sab-show-circle sab-show-square' );115 if ( '1' == iconType ) {116 if ( '1' == iconStyle ) {117 jQuery('.saboxplugin-socials').addClass( 'sab-show-circle' );118 }else{119 jQuery('.saboxplugin-socials').addClass( 'sab-show-square' );120 }121 }else{122 jQuery('.saboxplugin-socials').addClass( 'sab-show-simple' );123 }124 },125 socialIconHover: function() {126 var attribute = wp.SAB.Settings.get( 'sab_social_hover' );127 128 if ( '1' == attribute ) {129 jQuery('.saboxplugin-socials').addClass( 'sab-rotate-icons' );130 }else{131 jQuery('.saboxplugin-socials').removeClass( 'sab-rotate-icons' );132 }133 },134 socialIconShadow: function() {135 var attribute = wp.SAB.Settings.get( 'sab_box_long_shadow' );136 137 if ( '1' == attribute ) {138 jQuery('.saboxplugin-socials').removeClass( 'without-long-shadow' );139 }else{140 jQuery('.saboxplugin-socials').addClass( 'without-long-shadow' );141 }142 },143 socialIconBorder: function() {144 var attribute = wp.SAB.Settings.get( 'sab_box_thin_border' );145 146 if ( '1' == attribute ) {147 jQuery('.saboxplugin-socials').addClass( 'sab-icons-with-border' );148 }else{149 jQuery('.saboxplugin-socials').removeClass( 'sab-icons-with-border' );150 }151 },152 avatarStyle: function() {153 var attribute = wp.SAB.Settings.get( 'sab_avatar_style' );154 155 if ( '1' == attribute ) {156 jQuery('.saboxplugin-gravatar').addClass( 'sab-round-image' );157 }else{158 jQuery('.saboxplugin-gravatar').removeClass( 'sab-round-image' );159 }160 },161 avatarHover: function() {162 var attribute = wp.SAB.Settings.get( 'sab_avatar_hover' );163 164 if ( '1' == attribute ) {165 jQuery('.saboxplugin-gravatar').addClass( 'sab-rotate-img' );166 }else{167 jQuery('.saboxplugin-gravatar').removeClass( 'sab-rotate-img' );168 }169 },170 adjustPadding: function() {171 var paddingTopBottom = wp.SAB.Settings.getAttribute( 'sab_box_padding_top_bottom' ),172 paddingLeftRight = wp.SAB.Settings.getAttribute( 'sab_box_padding_left_right' );173 jQuery( '.saboxplugin-wrap' ).css({ 'padding' : paddingTopBottom + ' ' + paddingLeftRight });174 },175 adjustBorder: function() {176 var border = wp.SAB.Settings.getAttribute( 'sab_box_border_width' ),177 borderColor = wp.SAB.Settings.getAttribute( 'sab_box_border' );178 if ( '' == borderColor ) {179 borderColor = 'inherit';180 }181 jQuery( '.saboxplugin-wrap' ).css({ 'border-width' : border, 'border-color' : borderColor });182 jQuery( '.saboxplugin-wrap .saboxplugin-socials' ).css({ 'border-width' : border, 'border-color' : borderColor });183 },184 adjustAuthorName: function() {185 var font = wp.SAB.Settings.getAttribute( 'sab_box_name_font' ),186 size = wp.SAB.Settings.getAttribute( 'sab_box_name_size' ),187 color = wp.SAB.Settings.getAttribute( 'sab_box_author_color' ),188 lineHeight = parseInt( size ) + 7;189 if ( '' == color ) {190 color = 'inherit';191 }192 if ( '' == font || 'None' == font ) {193 font = 'inherit';194 }else{195 this.loadGoogleFonts( font );196 }197 jQuery( '.saboxplugin-wrap .saboxplugin-authorname a' ).css({ 'font-family' : font, 'color' : color, 'font-size': size, 'line-height' : lineHeight.toString() + 'px' });198 },199 adjustAuthorWebsite: function() {200 var font = wp.SAB.Settings.getAttribute( 'sab_box_web_font' ),201 size = wp.SAB.Settings.getAttribute( 'sab_box_web_size' ),202 color = wp.SAB.Settings.getAttribute( 'sab_box_web_color' ),203 lineHeight = parseInt( size ) + 7;204 if ( '' == color ) {205 color = 'inherit';206 }207 if ( '' == font || 'None' == font ) {208 font = 'inherit';209 }else{210 this.loadGoogleFonts( font );211 }212 jQuery( '.saboxplugin-wrap .saboxplugin-web a' ).css({ 'font-family' : font, 'color' : color, 'font-size': size, 'line-height' : lineHeight.toString() + 'px' });213 },214 adjustAuthorDescription: function() {215 var font = wp.SAB.Settings.getAttribute( 'sab_box_desc_font' ),216 size = wp.SAB.Settings.getAttribute( 'sab_box_desc_size' ),217 color = wp.SAB.Settings.getAttribute( 'sab_box_author_p_color' ),218 link_color = wp.SAB.Settings.getAttribute( 'sab_box_author_a_color' ),219 style = wp.SAB.Settings.getAttribute( 'sab_desc_style' ),220 lineHeight = parseInt( size ) + 7;221 if ( '' == color ) {222 color = 'inherit';223 }224 if ( '' == link_color ) {225 link_color = 'inherit';226 }227 if ( '' == font || 'None' == font ) {228 font = 'inherit';229 }else{230 this.loadGoogleFonts( font );231 }232 if ( '0' == style ) {233 style = 'normal';234 }else{235 style = 'italic';236 }237 jQuery( '.saboxplugin-wrap .saboxplugin-desc p, .saboxplugin-wrap .saboxplugin-desc' ).css({ 'font-family' : font, 'color' : color, 'font-size': size, 'line-height' : lineHeight.toString() + 'px', 'font-style' : style });238 jQuery( '.saboxplugin-wrap .saboxplugin-desc a' ).css({ 'font-family' : font, 'color' : link_color, 'font-size': size, 'line-height' : lineHeight.toString() + 'px', 'font-style' : style });239 },240 adjustIconSize: function() {241 var size = this.model.get( 'sab_box_icon_size' ),242 size2x = parseInt( size ) * 2;243 jQuery( '.saboxplugin-wrap .saboxplugin-socials a.saboxplugin-icon-grey svg' ).css({ 'width' : size, 'height' : size });244 jQuery( '.saboxplugin-wrap .saboxplugin-socials a.saboxplugin-icon-color svg' ).css({ 'width' : size2x.toString() + 'px', 'height' : size2x.toString() + 'px' });245 },246 changeSocialBarBackground: function() {247 var color = this.model.get( 'sab_box_icons_back' );248 if ( '' == color ) {249 color = 'inherit';250 }251 jQuery( '.saboxplugin-wrap .saboxplugin-socials' ).css({ 'background-color' : color });252 },253 changeAuthorBoxBackground: function() {254 var color = this.model.get( 'sab_box_author_back' );255 if ( '' == color ) {256 color = 'inherit';257 }258 jQuery( '.saboxplugin-wrap' ).css({ 'background-color' : color });259 },260 changeSocialIconsColor: function() {261 var color = this.model.get( 'sab_box_icons_color' );262 if ( '' == color ) {263 color = 'inherit';264 }265 jQuery( '.saboxplugin-wrap .saboxplugin-socials a.saboxplugin-icon-grey svg' ).css({ 'color' : color, 'fill' : color });266 },267 updateModel: function( event ) {268 var value, setting;269 // Check if the target has a data-field. If not, it's not a model value we want to store270 if ( undefined === event.target.id ) {271 return;272 }273 // Update the model's value, depending on the input type274 if ( event.target.type == 'checkbox' ) {275 value = ( event.target.checked ? '1' : '0' );276 } else {277 value = event.target.value;278 }279 // Update the model280 this.model.set( event.target.id, value );281 },282 checkGoogleFonts: function() {283 var authorFont = this.model.getAttribute( 'sab_box_name_font' ),284 webFont = this.model.getAttribute( 'sab_box_web_font' ),285 descriptionFont = this.model.getAttribute( 'sab_box_desc_font' );286 if ( '' != authorFont && 'None' != authorFont ) {287 this.loadGoogleFonts( authorFont );288 }289 if ( '' != webFont && 'None' != webFont ) {290 this.loadGoogleFonts( webFont );291 }292 if ( '' != descriptionFont && 'None' != descriptionFont ) {293 this.loadGoogleFonts( descriptionFont );294 }295 },296 loadGoogleFonts: function( font ) {297 if ( ! wp.SAB.Fonts.includes( font ) ) {298 wp.SAB.Fonts.push( font );299 WebFont.load({300 google: {301 families: [ font ]302 }303 });304 }305 },306 307});308jQuery( document ).ready(function(){309 wp.SAB.Fonts = [];310 wp.SAB.Settings = new wp.SAB.models.Settings();...
edit.js
Source:edit.js
1/**2 * Internal dependencies3 */4import Inspector from './inspector';5import SAB_Social_Icon from '../utils/social-icon';6/**7 * WordPress dependencies8 */9const { __ } = wp.i18n;10const { Component, Fragment } = wp.element;11const { Spinner } = wp.components;12/**13 * Block edit function14 */15export default class Edit extends Component {16 constructor( props ) {17 super( ...arguments );18 }19 renderSocialIcon( url, iconName ) {20 let sabColor;21 if ( '1' == sabVars.sab_colored ) {22 sabColor = 'saboxplugin-icon-color';23 } else {24 sabColor = 'saboxplugin-icon-grey';25 }26 let type = 'simple';27 if ( '1' == sabVars.sab_colored ) {28 if ( '1' == sabVars.sab_icons_style ) {29 type = 'circle';30 } else {31 type = 'square';32 }33 }34 let social_icon = new SAB_Social_Icon();35 return [36 <a href={ url } target="_blank" class={ sabColor }>37 { social_icon.icon_to_svg( iconName, type ) }38 </a>39 ];40 }41 changeAuthor( authorID ) {42 jQuery.ajax({43 type: "POST",44 data : { action: "sab_get_author", author_ID: authorID, nonce: sabVars.nonce },45 url : sabVars.ajaxURL,46 success: ( result ) => {47 if( result.success == false ) {48 this.props.setAttributes( {49 status: 'error',50 } );51 return;52 }53 let author = JSON.parse(result);54 this.props.setAttributes( {55 authorID: author.ID,56 avatar: author.avatar,57 profile_image: author['sabox-profile-image'],58 display_name: author.data.display_name,59 description: author.description,60 user_url: author.data.user_url,61 social_links: author.sabox_social_links,62 status: 'ready'63 } );64 }65 });66 }67 generateInlineCSS() {68 let css = '';69 // Border color of Simple Author Box70 if ( '' != sabVars.sab_box_border ) {71 css += '.saboxplugin-wrap {border-color:' + sabVars.sab_box_border + ';}';72 css += '.saboxplugin-wrap .saboxplugin-socials {border-color:' + sabVars.sab_box_border + ';}';73 }74 // Border width of Simple Author Box75 if ( '1' != sabVars.sab_box_border_width ) {76 css += '.saboxplugin-wrap, .saboxplugin-wrap .saboxplugin-socials{ border-width: ' + sabVars.sab_box_border_width + 'px; }';77 }78 // Avatar image style79 if ( '0' != sabVars.sab_avatar_style ) {80 css += '.saboxplugin-wrap .saboxplugin-gravatar img {-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%;}';81 }82 // Social icons style83 if ( '0' != sabVars.sab_colored && '0' != sabVars.sab_icons_style ) {84 css += '.saboxplugin-wrap .saboxplugin-socials .saboxplugin-icon-color {-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%;}';85 }86 // Long Shadow87 if ( '1' == sabVars.sab_colored && '1' != sabVars.sab_box_long_shadow ) {88 css += '.saboxplugin-wrap .saboxplugin-socials .saboxplugin-icon-color .st1 {display: none;}';89 }90 // Thin border91 if ( '1' == sabVars.sab_colored && '1' == sabVars.sab_box_thin_border ) {92 let style = 'border-width: 1px;border-style:solid;';93 if ( '1' == sabVars.sab_icons_style ) {94 style += 'border-radius:50%';95 }96 css += '.saboxplugin-wrap .saboxplugin-socials .saboxplugin-icon-color svg {' + style + '}';97 }98 // Background color of social icons bar99 if ( '' != sabVars.sab_box_icons_back ) {100 css += '.saboxplugin-wrap .saboxplugin-socials{background-color:' + sabVars.sab_box_icons_back + ';}';101 }102 // Background color of author box103 if ( '' != sabVars.sab_box_author_back ) {104 css += '.saboxplugin-wrap {background-color:' + sabVars.sab_box_author_back + ';}';105 }106 // Color of author box paragraphs107 if ( '' != sabVars.sab_box_author_p_color ) {108 css += '.saboxplugin-wrap .saboxplugin-desc {color:' + sabVars.sab_box_author_p_color + ';}';109 }110 // Color of author box links111 if ( '' != sabVars.sab_box_author_a_color ) {112 css += '.saboxplugin-wrap .saboxplugin-desc a {color:' + sabVars.sab_box_author_a_color + ';}';113 }114 // Author name color115 if ( '' != sabVars.sab_box_author_color ) {116 css += '.saboxplugin-wrap .saboxplugin-authorname a {color:' + sabVars.sab_box_author_color + ';}';117 }118 // Author web color119 if ( '1' == sabVars.sab_web && '' != sabVars.sab_box_web_color ) {120 css += '.saboxplugin-wrap .saboxplugin-web a {color:' + sabVars.sab_box_web_color + ';}';121 }122 // Author name font family123 if ( 'None' != sabVars.sab_box_name_font ) {124 css += '.saboxplugin-wrap .saboxplugin-authorname {font-family:"' + sabVars.sab_box_name_font + '";}';125 }126 // Author description font family127 if ( 'None' != sabVars.sab_box_desc_font ) {128 css += '.saboxplugin-wrap .saboxplugin-desc {font-family:' + sabVars.sab_box_desc_font + ';}';129 }130 // Author web font family131 if ( '1' == sabVars.sab_web && 'None' != sabVars.sab_box_web_font ) {132 css += '.saboxplugin-wrap .saboxplugin-web {font-family:"' + sabVars.sab_box_web_font + '";}';133 }134 // Author description font style135 if ( '1' == sabVars.sab_desc_style ) {136 css += '.saboxplugin-wrap .saboxplugin-desc {font-style:italic;}';137 }138 // Margin top & bottom, Padding139 if ( '' != sabVars.padding_top_bottom ) {140 css += '.saboxplugin-wrap {padding-top: ' + sabVars.padding_top_bottom + 'px; padding-bottom:' + sabVars.padding_top_bottom + 'px; }';141 }142 if ( '' != sabVars.padding_left_right ) {143 css += '.saboxplugin-wrap {padding-left: ' + sabVars.padding_left_right + 'px; padding-right:' + sabVars.padding_left_right + 'px; }';144 }145 if ( '' != sabVars.top_margin ) {146 css += '.saboxplugin-wrap {margin-top: ' + sabVars.top_margin + 'px; }';147 }148 if ( '' != sabVars.bottom_margin ) {149 css += '.saboxplugin-wrap {margin-bottom: ' + sabVars.bottom_margin + 'px; }';150 }151 // Author name text size152 css += '.saboxplugin-wrap .saboxplugin-authorname {font-size:' + sabVars.sabox_name_size + 'px; line-height:' + ( parseInt ( sabVars.sabox_name_size ) + 7 ) + 'px;}';153 // Author description font size154 css += '.saboxplugin-wrap .saboxplugin-desc p, .saboxplugin-wrap .saboxplugin-desc {font-size:' + sabVars.sabox_desc_size + 'px !important; line-height:' + ( parseInt ( sabVars.sabox_desc_size ) + 7 ) + 'px !important;}';155 // Author website text size156 css += '.saboxplugin-wrap .saboxplugin-web {font-size:' + sabVars.sabox_web_size + 'px;}';157 // Icons size158 let icon_size = parseInt( sabVars.sabox_icon_size );159 if ( '1' == sabVars.sab_colored ) {160 icon_size *= 2;161 }162 css += '.saboxplugin-wrap .saboxplugin-socials a svg {width:' + icon_size + 'px;height:' + icon_size + 'px;}';163 return css;164 }165 loadCustomFonts(){166 let sab_subset;167 if ( 'none' != sabVars.sab_box_subset ) {168 sab_subset = '&subset=' + sabVars.sab_box_subset;169 } else {170 sab_subset = '&subset=latin';171 }172 let google_fonts = [];173 if ( 'None' != sabVars.sab_box_name_font ) {174 google_fonts.push( sabVars.sab_box_name_font.replace(' ', '+') );175 }176 if ( 'None' != sabVars.sab_box_desc_font ) {177 google_fonts.push( sabVars.sab_box_desc_font.replace(' ', '+') );178 }179 if ( 'None' != sabVars.sab_box_web_font ) {180 google_fonts.push( sabVars.sab_box_web_font.replace(' ', '+') );181 }182 function onlyUnique(value, index, self) {183 return self.indexOf(value) === index;184 }185 google_fonts = google_fonts.filter( onlyUnique );186 if ( google_fonts.length > 0 ) {187 google_fonts.forEach(function(entry,index) {188 google_fonts[index] = entry + ':400,700,400italic,700italic';189 });190 return <link href={ 'https://fonts.googleapis.com/css?family=' + google_fonts.join('|') + sab_subset } rel="stylesheet"/>191 }192 }193 componentDidMount() {194 this.changeAuthor( this.props.attributes.authorID == 0 ? sabVars.currentUserID : this.props.attributes.authorID );195 }196 render() {197 const {198 attributes,199 isSelected,200 } = this.props;201 const {202 authorID,203 display_name,204 avatar,205 profile_image,206 description,207 user_url,208 social_links,209 status,210 } = attributes;211 if( status == 'loading' ) {212 return <div class="saboxplugin-wrap saboxplugin-wrap--loading"><Spinner/></div>213 }214 if( status == 'error' ) {215 return [216 <Fragment>217 { isSelected && (218 <Inspector219 changeAuthor = { ( authorID ) => this.changeAuthor( authorID ) }220 { ...this.props }221 />222 ) }223 <div class="saboxplugin-wrap saboxplugin-wrap--error">{ __( 'Author not found' ) }</div>224 </Fragment>225 ];226 }227 return [228 <Fragment>229 { isSelected && (230 <Inspector231 changeAuthor = { ( authorID ) => this.changeAuthor( authorID ) }232 { ...this.props }233 />234 ) }235 <div class="saboxplugin-wrap">236 <div class="saboxplugin-gravatar">237 <img src={ ! profile_image ? avatar : profile_image } height="100" width="100"/>238 </div>239 <div class="saboxplugin-authorname">240 <a href="#" class="vcard author" rel="author" itemprop="url">241 <span class="fn" itemprop="name">{ display_name }</span>242 </a>243 </div>244 <div class="saboxplugin-desc" dangerouslySetInnerHTML={{ __html: description }}></div>245 { sabVars.sab_web == '1' && user_url != '' && (246 <div class="saboxplugin-web">247 <a href="#">{ user_url }</a>248 </div>249 ) }250 <div class="clearfix"></div>251 { social_links.length == 0 && sabVars.currentUserID == authorID && (252 <a target="_blank" href={ sabVars.adminURL + 'profile.php?#sabox-social-table' } >{ __( 'Add Social Links' ) }</a>253 ) }254 { sabVars.sab_hide_socials == 0 && ! jQuery.isEmptyObject( social_links ) && (255 <div class="saboxplugin-socials">256 { Object.keys(social_links).map( (key) => {257 return this.renderSocialIcon( social_links[key], key );258 })}259 </div>260 ) }261 </div>262 <style dangerouslySetInnerHTML={{ __html: this.generateInlineCSS() }} />263 { this.loadCustomFonts() }264 </Fragment>265 ];266 }...
cross-compartment-nukeccw.js
Source:cross-compartment-nukeccw.js
1load(libdir + "asserts.js");2const otherGlobal = newGlobal({newCompartment: true});3function nukeValue(wrapper, value) {4 return {5 valueOf() {6 nukeCCW(wrapper);7 return value;8 }9 };10};11function assertIsDeadWrapper(value) {12 assertTypeErrorMessage(() => value.foo, "can't access dead object");13}14// Atomics.load15{16 let sab = new otherGlobal.SharedArrayBuffer(4);17 let ta = new otherGlobal.Int32Array(sab);18 ta[0] = 1;19 let val = Atomics.load(ta, nukeValue(ta, 0));20 assertEq(val, 1);21 assertIsDeadWrapper(ta);22}23{24 let sab = new otherGlobal.SharedArrayBuffer(4);25 let ta = new otherGlobal.Int32Array(sab);26 ta[0] = 1;27 let val = Atomics.load(ta, nukeValue(sab, 0));28 assertEq(val, 1);29 assertEq(ta[0], 1);30 assertIsDeadWrapper(sab);31}32// Atomics.store33{34 let sab = new otherGlobal.SharedArrayBuffer(4);35 let ta = new otherGlobal.Int32Array(sab);36 Atomics.store(ta, 0, nukeValue(ta, 1));37 assertIsDeadWrapper(ta);38}39{40 let sab = new otherGlobal.SharedArrayBuffer(4);41 let ta = new otherGlobal.Int32Array(sab);42 Atomics.store(ta, 0, nukeValue(sab, 1));43 assertEq(ta[0], 1);44 assertIsDeadWrapper(sab);45}46// Atomics.compareExchange47{48 let sab = new otherGlobal.SharedArrayBuffer(4);49 let ta = new otherGlobal.Int32Array(sab);50 ta[0] = 1;51 let val = Atomics.compareExchange(ta, 0, 1, nukeValue(ta, 2));52 assertEq(val, 1);53 assertIsDeadWrapper(ta);54}55{56 let sab = new otherGlobal.SharedArrayBuffer(4);57 let ta = new otherGlobal.Int32Array(sab);58 ta[0] = 1;59 let val = Atomics.compareExchange(ta, 0, 1, nukeValue(sab, 2));60 assertEq(val, 1);61 assertEq(ta[0], 2);62 assertIsDeadWrapper(sab);63}64// Atomics.exchange65{66 let sab = new otherGlobal.SharedArrayBuffer(4);67 let ta = new otherGlobal.Int32Array(sab);68 ta[0] = 1;69 let val = Atomics.exchange(ta, 0, nukeValue(ta, 2));70 assertEq(val, 1);71 assertIsDeadWrapper(ta);72}73{74 let sab = new otherGlobal.SharedArrayBuffer(4);75 let ta = new otherGlobal.Int32Array(sab);76 ta[0] = 1;77 let val = Atomics.exchange(ta, 0, nukeValue(sab, 2));78 assertEq(val, 1);79 assertEq(ta[0], 2);80 assertIsDeadWrapper(sab);81}82// Atomics.add83{84 let sab = new otherGlobal.SharedArrayBuffer(4);85 let ta = new otherGlobal.Int32Array(sab);86 ta[0] = 1;87 let val = Atomics.add(ta, 0, nukeValue(ta, 2));88 assertEq(val, 1);89 assertIsDeadWrapper(ta);90}91{92 let sab = new otherGlobal.SharedArrayBuffer(4);93 let ta = new otherGlobal.Int32Array(sab);94 ta[0] = 1;95 let val = Atomics.add(ta, 0, nukeValue(sab, 2));96 assertEq(val, 1);97 assertEq(ta[0], 3);98 assertIsDeadWrapper(sab);99}100// Atomics.sub101{102 let sab = new otherGlobal.SharedArrayBuffer(4);103 let ta = new otherGlobal.Int32Array(sab);104 ta[0] = 3;105 let val = Atomics.sub(ta, 0, nukeValue(ta, 2));106 assertEq(val, 3);107 assertIsDeadWrapper(ta);108}109{110 let sab = new otherGlobal.SharedArrayBuffer(4);111 let ta = new otherGlobal.Int32Array(sab);112 ta[0] = 3;113 let val = Atomics.sub(ta, 0, nukeValue(sab, 2));114 assertEq(val, 3);115 assertEq(ta[0], 1);116 assertIsDeadWrapper(sab);117}118// Atomics.and119{120 let sab = new otherGlobal.SharedArrayBuffer(4);121 let ta = new otherGlobal.Int32Array(sab);122 ta[0] = 3;123 let val = Atomics.and(ta, 0, nukeValue(ta, 1));124 assertEq(val, 3);125 assertIsDeadWrapper(ta);126}127{128 let sab = new otherGlobal.SharedArrayBuffer(4);129 let ta = new otherGlobal.Int32Array(sab);130 ta[0] = 3;131 let val = Atomics.and(ta, 0, nukeValue(sab, 1));132 assertEq(val, 3);133 assertEq(ta[0], 1);134 assertIsDeadWrapper(sab);135}136// Atomics.or137{138 let sab = new otherGlobal.SharedArrayBuffer(4);139 let ta = new otherGlobal.Int32Array(sab);140 ta[0] = 2;141 let val = Atomics.or(ta, 0, nukeValue(ta, 1));142 assertEq(val, 2);143 assertIsDeadWrapper(ta);144}145{146 let sab = new otherGlobal.SharedArrayBuffer(4);147 let ta = new otherGlobal.Int32Array(sab);148 ta[0] = 2;149 let val = Atomics.or(ta, 0, nukeValue(sab, 1));150 assertEq(val, 2);151 assertEq(ta[0], 3);152 assertIsDeadWrapper(sab);153}154// Atomics.xor155{156 let sab = new otherGlobal.SharedArrayBuffer(4);157 let ta = new otherGlobal.Int32Array(sab);158 ta[0] = 3;159 let val = Atomics.xor(ta, 0, nukeValue(ta, 1));160 assertEq(val, 3);161 assertIsDeadWrapper(ta);162}163{164 let sab = new otherGlobal.SharedArrayBuffer(4);165 let ta = new otherGlobal.Int32Array(sab);166 ta[0] = 3;167 let val = Atomics.xor(ta, 0, nukeValue(sab, 1));168 assertEq(val, 3);169 assertEq(ta[0], 2);170 assertIsDeadWrapper(sab);...
Using AI Code Generation
1var sab = new SharedArrayBuffer(1024);2var sabView = new Int32Array(sab);3sabView[0] = 1;4sabView[1] = 2;5sabView[2] = 3;6sabView[3] = 4;7sabView[4] = 5;8sabView[5] = 6;9sabView[6] = 7;10sabView[7] = 8;11sabView[8] = 9;12sabView[9] = 10;13var wpt = new Worker('wpt.js');14wpt.postMessage(sab, [sab]);15wpt.onmessage = function (e) {16 console.log(e.data);17};18onmessage = function (e) {19 var sabView = new Int32Array(e.data);20 var result = 0;21 for (var i = 0; i < sabView.length; i++) {22 result += sabView[i];23 }24 postMessage(result);25};
Using AI Code Generation
1var sab = new SharedArrayBuffer(1024);2var sabView = new Int32Array(sab);3sabView[0] = 1;4sabView[1] = 2;5sabView[2] = 3;6sabView[3] = 4;7sabView[4] = 5;8sabView[5] = 6;9sabView[6] = 7;10sabView[7] = 8;11sabView[8] = 9;12sabView[9] = 10;13sabView[10] = 11;14sabView[11] = 12;15sabView[12] = 13;16sabView[13] = 14;17sabView[14] = 15;18sabView[15] = 16;19sabView[16] = 17;20sabView[17] = 18;21sabView[18] = 19;22sabView[19] = 20;23sabView[20] = 21;24sabView[21] = 22;25sabView[22] = 23;26sabView[23] = 24;27sabView[24] = 25;28sabView[25] = 26;29sabView[26] = 27;30sabView[27] = 28;31sabView[28] = 29;32sabView[29] = 30;33sabView[30] = 31;34sabView[31] = 32;35sabView[32] = 33;36sabView[33] = 34;37sabView[34] = 35;38sabView[35] = 36;39sabView[36] = 37;40sabView[37] = 38;41sabView[38] = 39;42sabView[39] = 40;43sabView[40] = 41;44sabView[41] = 42;45sabView[42] = 43;46sabView[43] = 44;47sabView[44] = 45;48sabView[45] = 46;49sabView[46] = 47;
Using AI Code Generation
1var sab = new SharedArrayBuffer(1024*1024*1024);2var data = new Uint8Array(sab);3for(var i = 0; i < data.length; i++) {4 data[i] = i % 256;5}6var startTime = Date.now();7var endTime = Date.now();8var result = {9};10postMessage(result);11var worker = new Worker('test.js');12worker.onmessage = function(e) {13 var result = e.data;14 var startTime = result.startTime;15 var endTime = result.endTime;16 var data = result.data;17 var view = new Uint8Array(data);18 var sum = 0;19 for(var i = 0; i < view.length; i++) {20 sum += view[i];21 }22 console.log(sum);23};24import scrapy25class MySpider(scrapy.Spider):26 def parse(self, response):27 yield {'url': response.url}28scrapy.exceptions.CloseSpider: closing spider (finished)29import scrapy30class MySpider(scrapy.Spider):31 def parse(self,
Using AI Code Generation
1var _wpt = _wpt || [];2_wpt.push(['sab', 'test']);3_wpt.push(['sab', 'test2']);4_wpt.push(['sab', 'test3']);5var _wpt = _wpt || [];6_wpt.push(['sab', 'test4']);7_wpt.push(['sab', 'test5']);8var _wpt = _wpt || [];9_wpt.push(['sab', 'test6']);10_wpt.push(['sab', 'test7']);11var _wpt = _wpt || [];12_wpt.push(['sab', 'test8']);13_wpt.push(['sab', 'test9']);14var _wpt = _wpt || [];15_wpt.push(['sab', 'test10']);16_wpt.push(['sab', 'test11']);17var _wpt = _wpt || [];18_wpt.push(['sab', 'test12']);19_wpt.push(['sab', 'test13']);20var _wpt = _wpt || [];21_wpt.push(['sab', 'test14']);22_wpt.push(['sab', 'test15']);23var _wpt = _wpt || [];24_wpt.push(['sab', 'test16']);25_wpt.push(['sab', 'test17']);26var _wpt = _wpt || [];27_wpt.push(['sab', 'test18']);28_wpt.push(['sab', 'test19']);29var _wpt = _wpt || [];30_wpt.push(['sab', 'test20']);31_wpt.push(['sab', 'test21']);
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5wpt.runTest(testUrl, {6}, function(err, data) {7 if (err) return console.error(err);8 console.log('Test completed');9 console.log(data);10});11var wpt = require('webpagetest');12var options = {13};14var wpt = new WebPageTest('www.webpagetest.org', options.key);15wpt.runTest(testUrl, {16}, function(err, data) {17 if (err) return console.error(err);18 console.log('Test completed');19 console.log(data);20});21var wpt = require('webpagetest');22var options = {23};24var wpt = new WebPageTest('www.webpagetest.org', options.key);25wpt.runTest(testUrl,
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!