Best JavaScript code snippet using storybook-root
ccm.teambuild_builder-1.0.0.js
Source:ccm.teambuild_builder-1.0.0.js
...561 }562 // no submit button wanted? => remove submit button563 if ( !my.submit_button ) $.removeElement( self.element.querySelector( '#submit' ) );564 // render initial preview565 self.renderPreview();566 // rendering completed => perform callback567 if ( callback ) callback();568 };569 /** updates the preview taking into account the given input data */570 this.renderPreview = () => {571 // clear preview area572 self.element.querySelector( '#preview' ).innerHTML = '';573 // render new preview574 my.preview.start( getResultData(), instance => $.setContent( self.element.querySelector( '#preview' ), instance.root ) );575 };576 /** triggers the submit of the entered data */577 this.submit = event => {578 // prevent page reload579 if ( event ) event.preventDefault();...
bpds_twitter.js
Source:bpds_twitter.js
...29 switch( option ) {30 case "share" :31 jQuery( "#bpds-twitter-option-share-url-manual-text" ).blur( function() {32 if( !jQuery( "#bpds-twitter-option-share-url-manual-text" ).val() ) jQuery( "#bpds-twitter-option-share-url-auto" ).attr( "checked", "checked" );33 bpdsTwitter.renderPreview( option );34 } );35 36 jQuery( "#bpds-twitter-option-share-title-manual-text" ).blur( function() {37 if( !jQuery( "#bpds-twitter-option-share-title-manual-text" ).val() ) jQuery( "#bpds-twitter-option-share-title-auto" ).attr( "checked", "checked" );38 bpdsTwitter.renderPreview( option );39 } );4041 jQuery( '#bpds-twitter-option-share-count' ).click( function() {42 bpdsTwitter.renderPreview( option );43 } );44 45 jQuery( "#bpds-twitter-option-share-via" ).blur( function() {46 bpdsTwitter.renderPreview( option );47 } );48 49 jQuery( "#bpds-twitter-option-share-recommend" ).blur( function() {50 bpdsTwitter.renderPreview( option );51 } );52 53 jQuery( "#bpds-twitter-option-share-hashtag" ).blur( function() {54 bpdsTwitter.renderPreview( option );55 } );56 57 jQuery( "#bpds-twitter-option-share-large" ).click( function() {58 bpdsTwitter.renderPreview( option );59 } );60 61 jQuery( "#bpds-twitter-option-share-lang" ).change( function() {62 bpdsTwitter.renderPreview( option );63 } );64 65 jQuery( '#bpds-twitter-option-share-url-manual' ).click( function() {66 jQuery( "#bpds-twitter-option-share-url-manual-text" ).focus();67 } );68 69 jQuery( '#bpds-twitter-option-share-title-manual' ).click( function() {70 jQuery( "#bpds-twitter-option-share-title-manual-text" ).focus();71 } );72 break;73 case "follow" :74 jQuery( "#bpds-twitter-option-follow-user" ).blur( function() {75 bpdsTwitter.renderPreview( option );76 } ); 7778 jQuery( '#bpds-twitter-option-follow-usershow' ).click( function() {79 bpdsTwitter.renderPreview( option );80 } );81 82 jQuery( '#bpds-twitter-option-follow-followershow' ).click( function() {83 bpdsTwitter.renderPreview( option );84 } );85 86 jQuery( "#bpds-twitter-option-follow-large" ).click( function() {87 bpdsTwitter.renderPreview( option );88 } );89 90 jQuery( "#bpds-twitter-option-follow-lang" ).change( function() {91 bpdsTwitter.renderPreview( option );92 } );93 break;94 case "hashtag" :95 jQuery( "#bpds-twitter-option-hashtag-url-manual-text" ).blur( function() {96 if( !jQuery( "#bpds-twitter-option-hashtag-url-manual-text" ).val() ) jQuery( "#bpds-twitter-option-hashtag-url-auto" ).attr( "checked", "checked" );97 bpdsTwitter.renderPreview( option );98 } );99 100 jQuery( "#bpds-twitter-option-hashtag-title-manual-text" ).blur( function() {101 if( !jQuery( "#bpds-twitter-option-hashtag-title-manual-text" ).val() ) jQuery( "#bpds-twitter-option-hashtag-title-auto" ).attr( "checked", "checked" );102 bpdsTwitter.renderPreview( option );103 } );104 105 jQuery( "#bpds-twitter-option-hashtag-recommend" ).blur( function() {106 bpdsTwitter.renderPreview( option );107 } );108 109 jQuery( "#bpds-twitter-option-hashtag-recommend1" ).blur( function() {110 bpdsTwitter.renderPreview( option );111 } );112 113 jQuery( "#bpds-twitter-option-hashtag-hashtag" ).blur( function() {114 bpdsTwitter.renderPreview( option );115 } );116 117 jQuery( "#bpds-twitter-option-hashtag-large" ).click( function() {118 bpdsTwitter.renderPreview( option );119 } );120 121 jQuery( "#bpds-twitter-option-hashtag-lang" ).change( function() {122 bpdsTwitter.renderPreview( option );123 } );124 125 jQuery( '#bpds-twitter-option-hashtag-url-manual' ).click( function() {126 jQuery( "#bpds-twitter-option-hashtag-url-manual-text" ).focus();127 } );128 129 jQuery( '#bpds-twitter-option-hashtag-title-manual' ).click( function() {130 jQuery( "#bpds-twitter-option-hashtag-title-manual-text" ).focus();131 } );132 break;133 case "mention" : 134 jQuery( "#bpds-twitter-option-mention-title-manual-text" ).blur( function() {135 if( !jQuery( "#bpds-twitter-option-mention-title-manual-text" ).val() ) jQuery( "#bpds-twitter-option-mention-title-auto" ).attr( "checked", "checked" );136 bpdsTwitter.renderPreview( option );137 } );138 139 jQuery( "#bpds-twitter-option-mention-recommend" ).blur( function() {140 bpdsTwitter.renderPreview( option );141 } );142 143 jQuery( "#bpds-twitter-option-mention-recommend1" ).blur( function() {144 bpdsTwitter.renderPreview( option );145 } );146 147 jQuery( "#bpds-twitter-option-mention-tweet" ).blur( function() {148 bpdsTwitter.renderPreview( option );149 } );150 151 jQuery( "#bpds-twitter-option-mention-large" ).click( function() {152 bpdsTwitter.renderPreview( option );153 } );154 155 jQuery( "#bpds-twitter-option-mention-lang" ).change( function() {156 bpdsTwitter.renderPreview( option );157 } );158 159 jQuery( '#bpds-twitter-option-mention-title-manual' ).click( function() {160 jQuery( "#bpds-twitter-option-mention-title-manual-text" ).focus();161 } );162 break;163 }164 },165 insertEditor : function() {166 var option = jQuery( 'input[name="bpds-twitter-type"]:checked' ).val();167 var h = this.renderPreview( option, false );168169 if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) ed.execCommand('mceInsertContent', false, h);170 else if ( typeof edInsertContent == 'function' ) edInsertContent(edCanvas, h);171 else jQuery( edCanvas ).val( jQuery( edCanvas ).val() + h );172173 tb_remove();174 },175 renderPreview : function( option, preview ) {176 if( typeof preview == 'undefined' ) preview = true;177 var content = '';178 179 switch( option ) {180 case "share" :181 var shareUrlRadio = jQuery( 'input[name="bpds-twitter-option-share-url"]:checked' ).val();182 var shareTitleRadio = jQuery( 'input[name="bpds-twitter-option-share-title"]:checked' ).val();183 var shareCount = jQuery( '#bpds-twitter-option-share-count' ).is( ":checked" );184 var shareVia = jQuery( '#bpds-twitter-option-share-via' ).val();185 var shareRecommend = jQuery( '#bpds-twitter-option-share-recommend' ).val();186 var shareHashtag = jQuery( '#bpds-twitter-option-share-hashtag' ).val();187 var shareLarge = jQuery( '#bpds-twitter-option-share-large' ).is( ":checked" );188 var shareLang = jQuery( '#bpds-twitter-option-share-lang' ).val();189 190 content += '<a href="https://twitter.com/share" class="twitter-share-button" ';191 if( shareUrlRadio == '1' ) content += 'data-url="' + jQuery( '#bpds-twitter-option-share-url-manual-text' ).val() + '" ';192 if( shareTitleRadio == '1' ) content += 'data-text="' + jQuery( '#bpds-twitter-option-share-title-manual-text' ).val() + '" ';193 if( !shareCount ) content += 'data-count="none" ';194 if( shareVia ) content += 'data-via="' + shareVia + '" ';195 if( shareRecommend ) content += 'data-via="' + shareRecommend + '" ';196 if( shareHashtag ) content += 'data-hashtags="' + shareHashtag + '" ';197 if( shareLarge ) content += 'data-size="large" ';198 199 content += 'data-lang="' + shareLang + '" ';200 content += '><span>Tweet</span></a>';201 break;202 case "follow" :203 var followUser = jQuery( '#bpds-twitter-option-follow-user' ).val();204 var followUserShow = jQuery( '#bpds-twitter-option-follow-usershow' ).is( ":checked" );205 var followFollwerShow = jQuery( '#bpds-twitter-option-follow-followershow' ).is( ":checked" );206 var followLarge = jQuery( '#bpds-twitter-option-follow-large' ).is( ":checked" );207 var followLang = jQuery( '#bpds-twitter-option-follow-lang' ).val();208 209 content += '<a href="https://twitter.com/';210 if( !followUser ) content += 'twitter';211 else content += followUser;212 213 content += '" class="twitter-follow-button" ';214 215 if( !followUserShow ) content += 'data-show-screen-name="false" ';216 if( followFollwerShow ) content += 'data-show-count="true" ';217 else content += 'data-show-count="false" ';218 if( followLarge ) content += 'data-size="large" ';219 220 content += 'data-lang="' + followLang + '" ';221 content += '><span>';222 if( !followUser ) content += 'Follow @twitter';223 else content += 'Follow @' + followUser;224 content += '</span></a>';225 break;226 case "hashtag" :227 var hashtagHashtag = jQuery( '#bpds-twitter-option-hashtag-hashtag' ).val();228 var hashtagTitleRadio = jQuery( 'input[name="bpds-twitter-option-hashtag-title"]:checked' ).val();229 var hashtagRecommend = jQuery( '#bpds-twitter-option-hashtag-recommend' ).val();230 var hashtagRecommend1 = jQuery( '#bpds-twitter-option-hashtag-recommend1' ).val();231 var hashtagUrlRadio = jQuery( 'input[name="bpds-twitter-option-hashtag-url"]:checked' ).val();232 var hashtagLarge = jQuery( '#bpds-twitter-option-hashtag-large' ).is( ":checked" );233 var hashtagLang = jQuery( '#bpds-twitter-option-hashtag-lang' ).val();234 235 content += '<a href="https://twitter.com/intent/tweet?button_hashtag=';236 if( hashtagHashtag ) content += hashtagHashtag;237 else content += 'TwitterStories';238 if( hashtagTitleRadio == '1' ) content += '&text=' + jQuery( '#bpds-twitter-option-hashtag-title-manual-text' ).val();239 content += '" class="twitter-hashtag-button" ';240 content += 'data-lang="' + hashtagLang + '" ';241 242 if( hashtagLarge ) content += 'data-size="large" ';243 if( hashtagRecommend || hashtagRecommend1 ) {244 content += 'data-related="';245 if( hashtagRecommend ) {246 content += hashtagRecommend;247 if( hashtagRecommend1 ) content += ',';248 }249 if( hashtagRecommend1 ) content += hashtagRecommend1;250 } 251 if( hashtagUrlRadio == '1' ) content += 'data-url="' + jQuery( '#bpds-twitter-option-hashtag-url-manual-text' ).val() + '" '; 252 253 content += '><span>Tweet #';254 if( hashtagHashtag ) content += hashtagHashtag;255 else content += 'TwitterStories';256 content += '</span></a>';257 break;258 case "mention" :259 var mentionTweet = jQuery( '#bpds-twitter-option-mention-tweet' ).val();260 var mentionTitleRadio = jQuery( 'input[name="bpds-twitter-option-mention-title"]:checked' ).val();261 var mentionRecommend = jQuery( '#bpds-twitter-option-mention-recommend' ).val();262 var mentionRecommend1 = jQuery( '#bpds-twitter-option-mention-recommend1' ).val();263 var mentionLarge = jQuery( '#bpds-twitter-option-mention-large' ).is( ":checked" );264 var mentionLang = jQuery( '#bpds-twitter-option-mention-lang' ).val();265 266 content += '<a href="https://twitter.com/intent/tweet?screen_name=';267 if( mentionTweet ) content += mentionTweet;268 else content += 'support';269 if( mentionTitleRadio == '1' ) content += '&text=' + jQuery( '#bpds-twitter-option-mention-title-manual-text' ).val();270 content += '" class="twitter-mention-button" ';271 content += 'data-lang="' + mentionLang + '" ';272 273 if( mentionLarge ) content += 'data-size="large" ';274 if( mentionRecommend || mentionRecommend1 ) {275 content += 'data-related="';276 if( mentionRecommend ) {277 content += mentionRecommend;278 if( mentionRecommend1 ) content += ',';279 }280 if( mentionRecommend1 ) content += mentionRecommend1;281 }282 283 content += '><span>Tweet to @';284 if( mentionTweet ) content += mentionTweet;285 else content += 'support';286 content += '</span></a>';287 break;288 }289 290 if( preview ) {291 jQuery( "#bpds-twitter-preview-show" ).html( content );292 twttr.widgets.load();293 } else return content;294 },295 showOption : function() {296 var content = '';297 var option = jQuery( 'input[name="bpds-twitter-type"]:checked' ).val();298 299 jQuery( "#TB_ajaxContent" ).height( jQuery( "#TB_window" ).height() - 45 );300 jQuery( "#TB_ajaxContent" ).width( jQuery( "#TB_window" ).width() - 30 );301 302 switch( option ) {303 case "share" :304 content = this.contentOptionShare;305 break;306 case "follow" :307 content = this.contentOptionFollow;308 break;309 case "hashtag" :310 content = this.contentOptionHashtag;311 break;312 case "mention" :313 content = this.contentOptionMention;314 break;315 }316 317 jQuery( "#bpds-twitter-option #bpds-twitter-content" ).html( content );318 this.initOption( option );319 this.renderPreview( option );320 }
...
controls.js
Source:controls.js
...13 lineWrapping: true,14 onChange: function() {15 $prompt = true;16 if($render == true){17 renderPreview();18 } 19 }20});21//Grabs ctrl+key combos for shortcut commands22//Cannot grab ctrl+n in chrome 4 or higher :(23$.ctrl = function(key, callback, args) {24 $(document).keydown(function(e) {25 if(!args) args=[];26 if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {27 callback.apply(this, args);28 return false;29 }30 });31};32//Render contents of editor33function renderPreview()34{35 var previewFrame = document.getElementById('output');36 var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;37 preview.open();38 //Lets user write pure js into the editor, fudges in the script tags for rendering39 if($langMode == 'javascript'){40 preview.write('<script>'+editor.getValue()+'</script>');41 }else{42 preview.write(editor.getValue());43 }44 preview.close();45}46$(document).ready(function()47{48 var $textarea = $('#col-left');49 var $output = $('#col-right');50 var $iframe = $('#output');51 var $CM = $('.CodeMirror-scroll');52 $textarea.height($window.height()-60);53 $output.height($window.height()-60);54 $iframe.height($output.height());55 $CM.height($textarea.height());56 renderPreview();57});58//Menu Button Functions59//File Menu Options60//New file (empty)61$('#new').click(function ()62{63 if($prompt == true){64 if (confirm('All unsaved work will be lost. Are you sure?')) {65 editor.setValue('');66 renderPreview();67 }68 }else{69 editor.setValue('');70 renderPreview();71 }72});73//New HTML Template file74$('#new-html').click(function ()75{76 if($prompt == true){77 if (confirm('All unsaved work will be lost. Are you sure?')) {78 editor.setValue('<html>\n<head>\n\t<title></title>\n</head>\n<body>\n\tSkeleton File\n</body>\n</html>');79 $langMode = 'text/html';80 editor.setOption("mode", $langMode);81 82 $htmlIcon.addClass("icon-ok");83 $svgIcon.removeClass("icon-ok");84 $jsIcon.removeClass("icon-ok");85 CodeMirror.autoLoadMode(editor, $langMode);86 renderPreview();87 }88 }else{89 editor.setValue('<html>\n<head>\n\t<title></title>\n</head>\n<body>\n\tSkeleton File\n</body>\n</html>');90 $langMode = 'text/html';91 editor.setOption("mode", $langMode);92 93 $htmlIcon.addClass("icon-ok");94 $svgIcon.removeClass("icon-ok");95 $jsIcon.removeClass("icon-ok");96 CodeMirror.autoLoadMode(editor, $langMode);97 renderPreview();98 99 }100//console.log($langMode);101});102//New SVG Template file103$('#new-svg').click(function ()104{105 if($prompt == true){106 if (confirm('All unsaved work will be lost. Are you sure?')) {107 editor.setValue('<svg xmlns="http://www.w3.org/2000/svg" version="1.1">\n\n</svg>');108 $langMode = 'xml';109 editor.setOption("mode", $langMode);110 $htmlIcon.removeClass("icon-ok");111 $svgIcon.addClass("icon-ok");112 $jsIcon.removeClass("icon-ok");113 CodeMirror.autoLoadMode(editor, $langMode);114 renderPreview();115 }116 }else{117 editor.setValue('<svg xmlns="http://www.w3.org/2000/svg" version="1.1">\n\n</svg>');118 $langMode = 'xml';119 editor.setOption("mode", $langMode);120 $htmlIcon.removeClass("icon-ok");121 $svgIcon.addClass("icon-ok");122 $jsIcon.removeClass("icon-ok");123 CodeMirror.autoLoadMode(editor, $langMode);124 renderPreview();125 }126//console.log($langMode);127});128//New JS Template file129$('#new-js').click(function ()130{131 if($prompt == true){132 if (confirm('All unsaved work will be lost. Are you sure?')) {133 editor.setValue('\/\/Author: <yourname>\n\/\/Date: <date>\nfunction myScript(){\nreturn 100;\n}\n');134 $langMode = 'javascript';135 editor.setOption("mode", $langMode);136 137 $htmlIcon.removeClass("icon-ok");138 $svgIcon.removeClass("icon-ok");139 $jsIcon.addClass("icon-ok");140 CodeMirror.autoLoadMode(editor, $langMode);141 renderPreview();142 }143 }else{144 editor.setValue('\/\/Author: <yourname>\n\/\/Date: <date>\n\nfunction myScript(){\n\treturn 100;\n}\n');145 $langMode = 'javascript';146 editor.setOption("mode", $langMode);147 148 $htmlIcon.removeClass("icon-ok");149 $svgIcon.removeClass("icon-ok");150 $jsIcon.addClass("icon-ok");151 CodeMirror.autoLoadMode(editor, $langMode);152 renderPreview();153 }154//console.log($langMode);155});156//Open file dialog157$('#open').click(function() {158 if($prompt == true){159 if (confirm('All unsaved work will be lost. Are you sure?')) {160 toggleOpenFile();161 }162 }else{163 editor.setValue('');164 toggleOpenFile();165 }166});167//Save file dialog168$('#save').click(function() {169 toggleSaveFile();170});171//Reload file172$('#reload').click(function ()173{174 renderPreview();175});176//Languages Options177var $htmlIcon = $('#html-icon');178var $svgIcon = $('#svg-icon');179var $jsIcon = $('#js-icon');180//Set HTML Mode181$('#toggle-html').click(function()182{183 $langMode = 'text/html';184 editor.setOption("mode", $langMode);185 186 $htmlIcon.addClass("icon-ok");187 $svgIcon.removeClass("icon-ok");188 $jsIcon.removeClass("icon-ok");189 CodeMirror.autoLoadMode(editor, $langMode);190 renderPreview();191 192});193//Set SVG Mode194$('#toggle-svg').click(function()195{196 $langMode = 'xml';197 editor.setOption("mode", $langMode);198 $htmlIcon.removeClass("icon-ok");199 $svgIcon.addClass("icon-ok");200 $jsIcon.removeClass("icon-ok");201 CodeMirror.autoLoadMode(editor, $langMode);202 renderPreview();203});204//Set Javascript Mode205$('#toggle-js').click(function()206{207 $langMode = 'javascript';208 editor.setOption("mode", $langMode);209 210 $htmlIcon.removeClass("icon-ok");211 $svgIcon.removeClass("icon-ok");212 $jsIcon.addClass("icon-ok");213 CodeMirror.autoLoadMode(editor, $langMode);214 renderPreview();215});216//Settings Menu Options217//Toggle Auto Render218$("#toggle-render").click(function ()219{220 var $renderIcon = $('#render-icon');221 if($render == true){222 $render = false;223 //alert("Render is off");224 $renderIcon.removeClass("icon-ok");225 }else{226 $render = true;227 //alert("Render is on");228 $renderIcon.addClass("icon-ok");229 }230});231//Toggle Auto Indent232$("#toggle-indent").click(function ()233{234 var $indentIcon = $('#indent-icon');235 if($indent == true){236 $indent = false;237 $indentIcon.removeClass("icon-ok");238 editor.setOption("smartIndent", "false");239 }else{240 $indent = true;241 $indentIcon.addClass("icon-ok");242 editor.setOption("smartIndent", "true");243 }244});245//Keyboard shortcuts246//New file: Ctrl-N *Will not work in Chrome :(247$.ctrl('N', function() {248 if($prompt == true){249 if (confirm('All unsaved work will be lost. Are you sure?')) {250 editor.setValue('');251 renderPreview();252 }253 }else{254 editor.setValue('');255 renderPreview();256 }257});258//Open file: Ctrl-O *Doesn't completely override in Firefox259$.ctrl('O', function() {260 if($prompt == true){261 if (confirm('All unsaved work will be lost. Are you sure?')) {262 toggleOpenFile();263 }264 }else{265 toggleOpenFile();266 }267});268//Save file: Ctrl-S269$.ctrl('S', function() {270 toggleSaveFile();271});272//Reload file: Ctrl-R273$.ctrl('R', function() {274 renderPreview();275});276//File Handler functions277function toggleOpenFile(){278 $('.upload_toggle').toggle()279}280function openFile(){281 $('#upload_message').html('Uploading...');282 document.open_file_form.submit();283 return false;284}285function openFileComplete(){286 $('#upload_message').html('Upload Complete');287 editor.setValue($('#upload_iframe').contents().find('#the_file').val());288 renderPreview();289 290 $('.upload_toggle').animate({291 opacity: 0292 }, 500, function() {293 $('.upload_toggle').hide()294 $('#modal_overlay').css({295 opacity: 1296 });297 $('#bg_fader').css({298 opacity: 0.8299 });300 });301}302function toggleSaveFile(){...
register.js
Source:register.js
1(function Register(_AJAX, _GMAPS, _ALERTS, _IMAGEPREVIEW, _INPUTHELPER){2 var _private = {3 $myForm: document.querySelector('#myForm'),4 $fileUp: document.querySelector('#uplImage'),5 $inputPhone: document.querySelector('#txtPhone'),6 $inputCPF: document.querySelector('#txtCPF'),7 $inputSubmit: document.querySelector('#btnSave')8 };9 function Register(){10 this._init();11 }12 Register.prototype = {13 buttonStatus: function($el, status) {14 if (status === 'disabled') {15 $el.setAttribute('disabled', true);16 } else {17 $el.removeAttribute('disabled');18 }19 },20 uploadPreview: function($el) {21 if( !document.querySelector('#renderPreview') ) {22 var renderPreview = document.createElement('img');23 renderPreview.id = 'renderPreview',24 _private.$myForm.insertBefore(renderPreview, $el.nextSibling);25 }26 27 var preview = new _IMAGEPREVIEW({28 element: $el,29 renderElement: document.querySelector('#renderPreview'),30 renderWidth: '100%',31 renderHeight: '400px'32 });33 },34 registerSubmit: function($el) {35 var _this = this;36 var data = new FormData($el);37 this.buttonStatus(_private.$inputSubmit, 'disabled');38 if (document.querySelector('#alertsForm'))39 _ALERTS.remove({id: '#alertsForm'})40 var req = new _AJAX({41 method : 'POST',42 URI : $el.getAttribute('action'),43 data : data,44 success : function(resp) {45 if(resp.success) {46 _ALERTS.create({47 id: 'alertsForm',48 type: 'success',49 message: resp.success.message,50 method: 'append',51 element: _private.$myForm52 });53 if( document.querySelector('#renderPreview') ) {54 document.querySelector('#renderPreview').remove();55 }56 _private.$myForm.reset();57 } else {58 _ALERTS.create({59 id: 'alertsForm',60 type: 'error',61 message: resp.error.message,62 method: 'append',63 element: _private.$myForm64 });65 }66 _this.buttonStatus(_private.$inputSubmit, 'enabled');67 }, 68 error: function(resp) {69 _ALERTS.create({70 id: 'alertsForm',71 type: 'error',72 message: resp.error.message,73 method: 'append',74 element: _private.$myForm75 });76 _this.buttonStatus(_private.$inputSubmit, 'enabled');77 }78 });79 },80 _installEvents: function() {81 var _this = this;82 _private.$myForm.addEventListener('submit', function(e) {83 e.preventDefault();84 _this.registerSubmit(this);85 });86 _private.$fileUp.addEventListener('change', function(){87 _this.uploadPreview(this);88 });89 _private.$inputPhone.maxLength = 11;90 _private.$inputPhone.minLength = 10;91 _INPUTHELPER.validNumbersOnKeypress(_private.$inputPhone);92 _private.$inputCPF.maxLength = 11;93 _private.$inputCPF.minLength = 11;94 _INPUTHELPER.validNumbersOnKeypress(_private.$inputCPF);95 96 var google = new _GMAPS({ inputFormID: 'txtAddress', divMapID: 'map' });97 _ALERTS.remove({id: '#alertsForm'})98 },99 _init: function() {100 this._installEvents();101 }102 }103 return new Register();...
file-upload.js
Source:file-upload.js
...56 renderPreview = () => {57 const { value, renderPreview } = this.props;58 const { url } = this.state || {};59 const previewUrl = url || (value && (value.url || value));60 if (typeof renderPreview === 'function') return renderPreview(previewUrl);61 return null;62 };63 render() {64 const { renderPreview, accept, validateFile, error } = this.props;65 const { file, progress } = this.state || {};66 const fileName = this.getFileName();67 return (68 <div>69 <div className={classNames(this.props.className, styles.inputBlock)}>70 <FileUploadForm71 onStart={this.onStart}72 onPreload={renderPreview ? this.onPreload : null}73 onProgress={this.onProgress}74 onComplete={this.onComplete}75 onDelete={this.onDelete}76 onError={this.onError}77 accept={accept}78 validateFile={validateFile}79 ref={this.onRefUpload}80 />81 <div className={styles.input}>82 <input value={fileName || ''} type='text' disabled />83 { (file || error) && (84 <div className={classNames(styles.progress, { [styles.progressError]: error })}>85 <div style={{ width: `${Math.round(progress * 100)}%` }} />86 </div>87 )}88 </div>89 <div>90 { fileName ? (91 <button className={styles.buttonDelete} onClick={this.onDeleteFile}>92 Delete93 </button>94 ) : (95 <button className={styles.buttonAdd} onClick={this.onSelectFile}>96 Upload97 </button>98 )}99 </div>100 </div>101 { renderPreview && this.renderPreview() }102 </div>103 );104 }...
wizard-step-5-samenvatting.test.js
Source:wizard-step-5-samenvatting.test.js
...4import { renderPreview, summary, Label, ObjectLabel, SCSVLabel, Null } from '../wizard-step-5-samenvatting';5describe('signals/incident/definitions/wizard-step-5-samenvatting', () => {6 describe('renderPreview', () => {7 it('should return the correct component', () => {8 expect(renderPreview({ render: { name: 'RadioInputGroup' } })).toEqual(ObjectLabel);9 expect(renderPreview({ render: { name: 'TextInput' } })).toEqual(Label);10 expect(renderPreview({ render: { name: 'TextareaInput' } })).toEqual(Label);11 expect(renderPreview({ render: { name: 'MultiTextInput' } })).toEqual(SCSVLabel);12 expect(renderPreview({ render: { name: 'CheckboxInput' }, meta: { values: {} } })).toEqual(PreviewComponents.ListObjectValue);13 expect(renderPreview({ render: { name: 'CheckboxInput' }, meta: { value: '' } })).toEqual(expect.any(Function));14 expect(renderPreview({ render: { name: 'SomethingElse' } })).toEqual(Null);15 });16 });17 describe('summary', () => {18 const controls = {19 extra_bedrijven_horeca_wat: {20 meta: {21 label: 'Uw melding gaat over:',22 shortLabel: 'Soort bedrijf',23 },24 options: { validators: [Validators.required] },25 render: FormComponents.RadioInputGroup,26 },27 extra_bedrijven_horeca_naam: {28 meta: {...
render-preview.unit.test.js
Source:render-preview.unit.test.js
...5describe("renderPreview", () => {6 const css = {};7 const deleteButton = null;8 it("should return false if there is no data", () => {9 expect(renderPreview(ATTACHMENT_TYPES.photo, {}, css, deleteButton)).to.be.false;10 });11 it("should return a span with the file name if attachment it's document", () => {12 const file = {13 data: {},14 fileName: "test.txt"15 };16 const component = createSimpleMount(renderPreview(ATTACHMENT_TYPES.document, file, css, deleteButton));17 expect(component.find("span")).to.have.lengthOf(1);18 expect(component.text()).to.be.equal("test.txt");19 });20 it("should return an AttachmentPreview", () => {21 const file = {22 data: "abcd",23 fileName: "test.png"24 };25 const component = createSimpleMount(renderPreview(ATTACHMENT_TYPES.photo, file, css, deleteButton));26 expect(component.find(AttachmentPreview)).to.have.lengthOf(1);27 });...
preview.js
Source:preview.js
...16 />,17 outlet18 );19};20renderPreview();21if (module.hot) {22 module.hot.accept('./components', () => {23 renderPreview({ components: require('./components') });24 });25 module.hot.accept('./themes', () => {26 renderPreview({ themes: require('./themes') });27 });28 module.hot.accept('./frameComponent', () => {29 renderPreview({ FrameComponent: require('./frameComponent') });30 });...
Using AI Code Generation
1import { renderPreview } from 'storybook-root';2import { renderPreview } from 'storybook-root';3import { renderPreview } from 'storybook-root';4import { renderPreview } from 'storybook-root';5import { renderPreview } from 'storybook-root';6import { renderPreview } from 'storybook-root';7import { renderPreview } from 'storybook-root';8import { renderPreview } from 'storybook-root';9import { renderPreview } from 'storybook-root';10import { renderPreview } from 'storybook-root';11import { renderPreview } from 'storybook-root';12import { renderPreview } from 'storybook-root';13import { renderPreview } from 'storybook-root';14import { renderPreview } from 'storybook-root';15import { renderPreview } from 'storybook-root';16import { renderPreview } from 'storybook-root';17import { renderPreview } from 'storybook-root';18import { renderPreview } from 'storybook-root';19import { renderPreview } from 'storybook-root';20import { renderPreview } from 'storybook-root';
Using AI Code Generation
1import {renderPreview} from 'storybook-root';2import {MyComponent} from './MyComponent';3renderPreview(MyComponent);4import React from 'react';5import {storiesOf} from '@storybook/react';6import {withKnobs, text} from '@storybook/addon-knobs';7import MyComponent from './MyComponent';8storiesOf('MyComponent', module)9 .addDecorator(withKnobs)10 .add('default', () => (11 label={text('label', 'Hello World')}12 ));13MIT © [Nikhil Karamchandani]()
Using AI Code Generation
1import { renderPreview } from 'storybook-root';2const { getStorybook, configure, storiesOf } = renderPreview();3configure(() => {4 require('../stories');5}, module);6storiesOf('Button', module)7 .add('with text', () => <Button>Hello Button</Button>)8 .add('with some emoji', () => (9 ));10storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);11import { renderPreview } from 'storybook-root';12const { getStorybook, configure, storiesOf } = renderPreview();13configure(() => {14 require('../stories');15}, module);16storiesOf('Button', module)17 .add('with text', () => <Button>Hello Button</Button>)18 .add('with some emoji', () => (19 ));20storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);21import { renderPreview } from 'storybook-root';22const { getStorybook, configure, storiesOf } = renderPreview();23configure(() => {24 require('../stories');25}, module);26storiesOf('Button', module)27 .add('with text', () => <Button>Hello Button</Button>)28 .add('with some emoji', () => (29 ));30storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);31import { renderPreview } from 'storybook-root';32const { getStorybook, configure, storiesOf } = renderPreview();33configure(() => {34 require('../stories');35}, module);36storiesOf('Button', module)37 .add('with text', () => <Button>Hello Button</Button>)
Using AI Code Generation
1const { renderPreview } = require("storybook-root");2const { render } = require("react-dom");3const { jsx } = require("@emotion/core");4render(renderPreview({ jsx, component: MyComponent }), document.getElementById("root"));5import { renderPreview } from "storybook-root";6import { render } from "react-dom";7import { jsx } from "@emotion/core";8render(renderPreview({ jsx, component: MyComponent }), document.getElementById("root"));9const { renderPreview } = require("storybook-root");10const { render } = require("react-dom");11const { jsx } = require("@emotion/core");12render(renderPreview({ jsx, component: MyComponent, props: { name: "John Doe" } }), document.getElementById("root"));13import { renderPreview } from "storybook-root";14import { render } from "react-dom";15import { jsx } from "@emotion/core";16render(renderPreview({ jsx, component: MyComponent, props: { name: "John Doe" } }), document.getElementById("root"));17const { renderPreview } = require("storybook-root");18const { render } = require("react-dom");19const { jsx } = require("@emotion/core");20render(renderPreview({ jsx, component: MyComponent, props: { name: "John Doe" }, theme: { color: "blue" } }), document.getElementById("root"));21import { renderPreview } from "storybook-root";22import { render } from "react-dom";
Using AI Code Generation
1import { renderPreview } from 'storybook-root';2const { html } = renderPreview('my-story', { a: 1, b: 2 });3console.log(html);4import { renderPreview } from '@storybook/html';5export { renderPreview };6module.exports = {7 core: {8 },9 preview: {10 import: './preview.js',11 },12};13import { defineConfig } from 'vite';14import path from 'path';15export default defineConfig({16 resolve: {17 alias: {18 'storybook-root': path.resolve(__dirname, '../'),19 },20 },21});
Using AI Code Generation
1import { renderPreview } from 'storybook-root-provider';2const story = require('./story.js');3const storyFn = () => story;4const render = renderPreview(storyFn, { name: 'hello' });5import { useStorybookState } from 'storybook-root-provider';6const Story = () => {7 const state = useStorybookState();8 return <div>{state.name}</div>;9};10export default Story;11import React from 'react';12import { useStorybookState } from 'storybook-state';13import { useStorybookApi } from '@storybook/api';14const StorybookRootProvider = ({ children }) => {15 const state = useStorybookState();16 const api = useStorybookApi();17 const { storyStore } = api;18 const { fromId, getStoryContext } = storyStore;19 return (20 <storybook-root-provider state={state} api={api}>21 {children}22 );23};24export const useStorybookState = () => {25 const [state, setState] = React.useState({});26 const { storyStore } = api;27 const { fromId, getStoryContext } = storyStore;28 React.useEffect(() => {29 const channel = api.getChannel();30 channel.on('storybook-root-provider/state', setState);31 return () => channel.removeListener('storybook-root-provider/state', setState);32 }, [api]);33 return state;34};35export const useStorybookApi = () => {36 const [api, setApi] = React.useState({});37 React.useEffect(() => {38 const channel = api.getChannel();39 channel.on('storybook-root-provider/api', setApi);40 return () => channel.removeListener('storybook-root-provider/api', setApi);41 }, [api]);42 return api;43};44export const renderPreview = (storyFn, state) => {45 const channel = api.getChannel();46 channel.emit('storybook-root-provider/state', state);47 return storyFn();48};49export default StorybookRootProvider;50import addons from '@storybook/addons';51import { ADDON_ID, PANEL_ID, EVENT_ID } from './constants';52export const register = ()
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!!