Plugin Directory

Changeset 2723516


Ignore:
Timestamp:
05/13/2022 06:29:23 PM (4 years ago)
Author:
Wolfram Research
Message:

initial commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wolfram-notebook-embedder/trunk/js/WneBlockJs.js

    r2723502 r2723516  
    55
    66    var registry = [];
     7    var embeds = [];
    78    var blockIcon =  El(
    89        'svg',
     
    4748            },
    4849            edit: function(props){
    49                 console.log('edit called');
    5050
    5151                function generateUuid(){
     
    6666                }
    6767
     68                function registerEmbed(id){
     69                    embeds.push(id);
     70                }
     71
    6872                function isregistered(id){
    6973                    if (registry.indexOf(id) !== -1){
     
    7478                }
    7579
     80                function isEmbeded(id){
     81                    if (embeds.indexOf(id) !== -1){
     82                        return true;
     83                    }
     84
     85                    return false;
     86                }
     87
    7688                function removeEmbed(){
    7789                    document.getElementById(embedWrapperId).innerHTML = '';
    7890                }
    7991
    80                 function hasEmbed(){
    81                     if(document.getElementById(props.attributes.id) == null){
    82                         return false;
    83                     }
    84 
    85                     return true;
    86                 }
    87 
    8892                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
    130133                }
    131134
     
    200203                var embedWrapperId = 'wneEmbedWrapper-' + props.attributes.id;
    201204
    202 
    203205                // the convoluted part
    204206                if (isregistered(props.attributes.id)) {
    205                     console.log('1');
    206                     if (hasEmbed()) {
     207                    if (isEmbeded(props.attributes.id)) {
    207208                        formWrapperClass += ' wneHide';
    208                         console.log('2');
    209209                    }else{
    210210                        editButtonClasses += ' wneHide';
    211                         console.log('3');
    212211                    }
    213212                }else{
    214                     console.log('4');
    215213                    register(props.attributes.id);
    216214
    217215                    if(props.attributes.hasOwnProperty('url') && regexValidate(urlValidationPattern, props.attributes.url)){
    218                         console.log('5');
    219216                        formWrapperClass += ' wneHide';
    220217
     218                        registerEmbed(props.attributes.id);
    221219                        setTimeout(function(){
    222220                            renderEmbed();
    223221                        }, 50);
    224222                    }else{
    225                         console.log('6');
    226223                        editButtonClasses += ' wneHide';
    227224                    }
Note: See TracChangeset for help on using the changeset viewer.