Changeset 2723516
- Timestamp:
- 05/13/2022 06:29:23 PM (4 years ago)
- File:
-
- 1 edited
-
wolfram-notebook-embedder/trunk/js/WneBlockJs.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wolfram-notebook-embedder/trunk/js/WneBlockJs.js
r2723502 r2723516 5 5 6 6 var registry = []; 7 var embeds = []; 7 8 var blockIcon = El( 8 9 'svg', … … 47 48 }, 48 49 edit: function(props){ 49 console.log('edit called');50 50 51 51 function generateUuid(){ … … 66 66 } 67 67 68 function registerEmbed(id){ 69 embeds.push(id); 70 } 71 68 72 function isregistered(id){ 69 73 if (registry.indexOf(id) !== -1){ … … 74 78 } 75 79 80 function isEmbeded(id){ 81 if (embeds.indexOf(id) !== -1){ 82 return true; 83 } 84 85 return false; 86 } 87 76 88 function removeEmbed(){ 77 89 document.getElementById(embedWrapperId).innerHTML = ''; 78 90 } 79 91 80 function hasEmbed(){81 if(document.getElementById(props.attributes.id) == null){82 return false;83 }84 85 return true;86 }87 88 92 function renderEmbed(){ 89 if(!hasEmbed()){ 90 var wrap = document.createElement("div"); 91 wrap.id = props.attributes.id; 92 93 var style = ''; 94 if(props.attributes.hasOwnProperty('width') && regexValidate(widthValidationPattern, props.attributes.width)){ 95 if (props.attributes.width != '') { 96 style += 'width:' + props.attributes.width + 'px;'; 97 } 98 } 99 if(props.attributes.hasOwnProperty('maxHeight') && regexValidate(maxHeightValidationPattern, props.attributes.maxHeight)){ 100 if (props.attributes.maxHeight != '') { 101 style += 'max-height:' + props.attributes.maxHeight + 'px;'; 102 } 103 } 104 wrap.style = style; 105 106 var className = 'wneContainer '; 107 if(props.attributes.hasOwnProperty('className')){ 108 className += props.attributes.className; 109 } 110 wrap.className = className; 111 112 document.getElementById(embedWrapperId).appendChild(wrap); 113 114 var EmbedAttributes = {}; 115 if(props.attributes.hasOwnProperty('width') && props.attributes.width != ''){ 116 EmbedAttributes.width = props.attributes.width; 117 } 118 119 if(props.attributes.hasOwnProperty('maxHeight') && props.attributes.maxHeight != ''){ 120 EmbedAttributes.maxHeight = props.attributes.maxHeight; 121 } 122 123 if(props.attributes.hasOwnProperty('blockInteractivity')){ 124 EmbedAttributes.allowInteract = !props.attributes.blockInteractivity; 125 } 126 127 var target = document.getElementById(props.attributes.id); 128 WolframNotebookEmbedder.embed(props.attributes.url, target, EmbedAttributes); 129 } 93 var wrap = document.createElement("div"); 94 wrap.id = props.attributes.id; 95 96 var style = ''; 97 if(props.attributes.hasOwnProperty('width') && regexValidate(widthValidationPattern, props.attributes.width)){ 98 if (props.attributes.width != '') { 99 style += 'width:' + props.attributes.width + 'px;'; 100 } 101 } 102 if(props.attributes.hasOwnProperty('maxHeight') && regexValidate(maxHeightValidationPattern, props.attributes.maxHeight)){ 103 if (props.attributes.maxHeight != '') { 104 style += 'max-height:' + props.attributes.maxHeight + 'px;'; 105 } 106 } 107 wrap.style = style; 108 109 var className = 'wneContainer '; 110 if(props.attributes.hasOwnProperty('className')){ 111 className += props.attributes.className; 112 } 113 wrap.className = className; 114 115 document.getElementById(embedWrapperId).appendChild(wrap); 116 117 var EmbedAttributes = {}; 118 if(props.attributes.hasOwnProperty('width') && props.attributes.width != ''){ 119 EmbedAttributes.width = props.attributes.width; 120 } 121 122 if(props.attributes.hasOwnProperty('maxHeight') && props.attributes.maxHeight != ''){ 123 EmbedAttributes.maxHeight = props.attributes.maxHeight; 124 } 125 126 if(props.attributes.hasOwnProperty('blockInteractivity')){ 127 EmbedAttributes.allowInteract = !props.attributes.blockInteractivity; 128 } 129 130 var target = document.getElementById(props.attributes.id); 131 WolframNotebookEmbedder.embed(props.attributes.url, target, EmbedAttributes); 132 130 133 } 131 134 … … 200 203 var embedWrapperId = 'wneEmbedWrapper-' + props.attributes.id; 201 204 202 203 205 // the convoluted part 204 206 if (isregistered(props.attributes.id)) { 205 console.log('1'); 206 if (hasEmbed()) { 207 if (isEmbeded(props.attributes.id)) { 207 208 formWrapperClass += ' wneHide'; 208 console.log('2');209 209 }else{ 210 210 editButtonClasses += ' wneHide'; 211 console.log('3');212 211 } 213 212 }else{ 214 console.log('4');215 213 register(props.attributes.id); 216 214 217 215 if(props.attributes.hasOwnProperty('url') && regexValidate(urlValidationPattern, props.attributes.url)){ 218 console.log('5');219 216 formWrapperClass += ' wneHide'; 220 217 218 registerEmbed(props.attributes.id); 221 219 setTimeout(function(){ 222 220 renderEmbed(); 223 221 }, 50); 224 222 }else{ 225 console.log('6');226 223 editButtonClasses += ' wneHide'; 227 224 }
Note: See TracChangeset
for help on using the changeset viewer.