Plugin Directory

Changeset 2248759


Ignore:
Timestamp:
02/22/2020 03:21:55 PM (6 years ago)
Author:
platformlycom
Message:

Integration with Elementor plugin

Location:
platformly/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • platformly/trunk/css/editor_btn.css

    r2024659 r2248759  
    133133    margin-right: -13px;
    134134}
     135
     136#ply-dialog-link-settings {
     137    display: none;
     138    padding: 5px 10px 10px 10px;
     139    font-weight: bold;
     140    border-top: 1px solid #dfdfdf;
     141    position: relative;
     142}
     143#ply-dialog-link-settings table {
     144    margin: 0px auto;
     145}
     146#ply-link-text-error,
     147#ply-link-url-error {
     148    display: none;
     149    font-weight: 300;
     150}
  • platformly/trunk/inc/ply.btn.php

    r2208564 r2248759  
    1010</div>
    1111<script type="text/javascript">
    12     <?php if(!empty($projectCodeInclude) && !empty($projectCode)): ?>
    13         var plyProjectMsg = "A code from Project '<span class='ply-project-name'></span>' is being used on this site.";
    14         var plyProjectId = '<?php echo $projectCode['ply_project_id'] ?>';
    15     <?php else: ?>
    16         var plyProjectMsg = 'You must include a Platform.ly project code within your site, please <a href="<?php echo get_admin_url(null, 'admin.php?page=ply') ?>">"click here"</a> to do it now.';
    17         var plyProjectId = 0;
    18     <?php endif; ?>
     12<?php if(!empty($projectCodeInclude) && !empty($projectCode)): ?>
     13    var plyProjectMsg = "A code from Project '<span class='ply-project-name'></span>' is being used on this site.";
     14    var plyProjectId = '<?php echo $projectCode['ply_project_id'] ?>';
     15<?php else: ?>
     16    var plyProjectMsg = 'You must include a Platform.ly project code within your site, please <a href="<?php echo get_admin_url(null, 'admin.php?page=ply') ?>">"click here"</a> to do it now.';
     17    var plyProjectId = 0;
     18<?php endif; ?>
     19    var editInElementor = <?php echo isEditInElementor() ? 'true' : 'false'; ?>;
     20    var siteUrl = '<?php echo home_url(); ?>';
     21
    1922    jQuery(function ($) {
    2023        // initalise the dialog
     
    2831            resizable: false,
    2932            closeOnEscape: true,
    30             maxHeight: 500,
     33            maxHeight: 550,
    3134            dialogClass: "ply-dialog-editor",
    3235            position: {
     
    3437                at: "center",
    3538                of: window
     39            },
     40            close: function () {
     41                $('#ply-dialog-link-settings').hide();
    3642            },
    3743            open: function () {
     
    5258                $('.ui-dialog-titlebar-close').addClass('ui-button');
    5359                $('.ply-dialog-editor .ui-dialog-buttonpane').before('<div id="ply-dialog-footer"></div>');
     60                $('#ply-dialog-footer').after('<div id="ply-dialog-link-settings"></div>');
    5461            },
    5562            buttons: [{
     
    6269                                    enteredUrl = jQuery('.chosenCustomLink:checked').data('mainlink') + '?' + (($("#trc1").val() != '') ? '&c1=' + $("#trc1").val() : '') + (($("#trc2").val() != '') ? '&c2=' + $("#trc2").val() : '') + (($("#trc3").val() != '') ? '&c3=' + $("#trc3").val() : '') + (($("#trc4").val() != '') ? '&c4=' + $("#trc4").val() : '');
    6370                                }
     71
    6472                                if(plySelectedWord.value.start == plySelectedWord.value.end){
    6573                                    var newElement = wp.richText.insert(plySelectedWord.value, enteredUrl);
     
    6977                                        type: 'core/link',
    7078                                        attributes: {
    71                                             url: enteredUrl,
     79                                            url: enteredUrl
    7280                                        }
    7381                                    }));
     
    7684                                        type: 'core/link',
    7785                                        attributes: {
    78                                             url: enteredUrl,
     86                                            url: enteredUrl
    7987                                        }
    8088                                    }));
     
    119127                            var action = selectedEvent.find('.existing-action span').text();
    120128                            var eventCode = "<script type='text/javascript'>plyt('"+action.replace(/[^a-zA-Z0-9_ ]/gi, "")+"', '"+description.replace(/[^a-zA-Z0-9_ ]/gi, "")+"','"+encodeURIComponent(id)+"');<\/script>";
    121                             insertedBlock = wp.blocks.createBlock('core/html', {
    122                                 content: eventCode,
    123                             });
    124                             wp.data.dispatch('core/editor').insertBlocks(insertedBlock, 0);
     129
     130                            if(typeof wp.richText !== 'undefined'){
     131                                // Using WP blocks editor
     132                                insertedBlock = wp.blocks.createBlock('core/html', {
     133                                    content: eventCode
     134                                });
     135                                wp.data.dispatch('core/editor').insertBlocks(insertedBlock, 0);
     136                            } else if(typeof window.tinymce !== 'undefined' && !tinymce.activeEditor.isHidden()) {
     137                                // Using TinyMCE editor
     138                                tinymce.activeEditor.insertContent(eventCode);
     139                            }
    125140                            closePlyDialog();
    126141                        }else{
     
    133148                    text: "Add on Link Click",
    134149                    click: function() {
     150                        var link_text, link_url = siteUrl;
     151                        // Validate link settings
     152                        if (jQuery('#ply-dialog-link-settings').css('display') !== 'none') {
     153                            if (jQuery('#ply_dialog_link_text').val() === '') {
     154                                jQuery('#ply-link-text-error').show();
     155                                return;
     156                            }
     157                            if (jQuery('#ply_dialog_link_url').val() === '') {
     158                                jQuery('#ply-link-url-error').show();
     159                                return;
     160                            }
     161                            link_text = jQuery('#ply_dialog_link_text').val();
     162                            link_url  = jQuery('#ply_dialog_link_url').val();
     163                        }
     164
    135165                        var id = jQuery('.chosenEvent:checked').val();
    136166                        if(typeof id !== 'undefined' && id.length > 0){
     
    139169                            var action = selectedEvent.find('.existing-action span').text();
    140170                            var eventCodeClick = "plyt('"+action.replace(/[^a-zA-Z0-9_ ]/gi, "")+"', '"+description.replace(/[^a-zA-Z0-9_ ]/gi, "")+"','"+encodeURIComponent(id)+"');";
    141                             if(Object.keys(plySelectedWord).length > 0){
    142                                 var activeLink = wp.richText.getActiveFormat(plySelectedWord.value, 'core/link');
    143                                 var attributes = {
    144                                         url: 'javascript:;',
     171
     172                            if(typeof wp.richText !== 'undefined'){
     173                                if(Object.keys(plySelectedWord).length > 0){
     174                                    var activeLink = wp.richText.getActiveFormat(plySelectedWord.value, 'core/link');
     175                                    var attributes = {
     176                                        url: link_url,
    145177                                        onclick: eventCodeClick
    146                                     }
    147                                 if(typeof activeLink !== 'undefined'){
    148                                     attributes.url = activeLink.attributes.url;
    149                                     if(typeof activeLink.attributes.target !== 'undefined'){
    150                                         attributes.target = activeLink.attributes.target;
    151                                     }
    152                                 }
    153                                 plySelectedWord.onChange(wp.richText.applyFormat(plySelectedWord.value, {
    154                                     type: 'core/link',
    155                                     attributes: attributes
    156                                 }));
    157                             }else if(Object.keys(plyEventButton).length > 0){
    158                                 plyEventButton.setAttributes({onclick: eventCodeClick});
     178                                    };
     179
     180                                    if(typeof activeLink !== 'undefined'){
     181                                        attributes.url = activeLink.attributes.url;
     182                                        if(typeof activeLink.attributes.target !== 'undefined'){
     183                                            attributes.target = activeLink.attributes.target;
     184                                        }
     185                                    }
     186
     187                                    plySelectedWord.onChange(wp.richText.applyFormat(plySelectedWord.value, {
     188                                        type: 'core/link',
     189                                        attributes: attributes
     190                                    }));
     191                                } else if(Object.keys(plyEventButton).length > 0){
     192                                    plyEventButton.setAttributes({onclick: eventCodeClick});
     193                                }
     194                            } else {
     195                                if (typeof window.tinymce !== 'undefined' && !tinymce.activeEditor.isHidden()) {
     196                                    var selectedText = tinymce.activeEditor.selection.getContent();
     197                                    if (selectedText.length < 1) {
     198                                        selectedText = link_text;
     199                                    }
     200
     201                                    // Check if editing not in Elementor
     202                                    if (elementor === 'undefined') {
     203                                        tinymce.activeEditor.insertContent('<a href="javascript:;" onclick="eventCodeClick">' + selectedText + '</a>');
     204                                    } else {
     205                                        var a_id = 'a_plyt_'+id,
     206                                            linkTag = '<a href="'+link_url+'" target="_blank" id="' + a_id + '">' + selectedText + '</a>',
     207                                            scriptTag = '<script type="text/javascript">jQuery("#' + a_id + '").on("click", function() {' + eventCodeClick + '})<\/script>';
     208                                        tinymce.activeEditor.insertContent(linkTag + scriptTag);
     209                                    }
     210                                } else {
     211                                    var selectedText = getSelected();
     212                                    if (selectedText.length < 1) {
     213                                        selectedText = link_text;
     214                                    }
     215                                    QTags.insertContent('<a href="' + link_url + '" onclick="' + eventCodeClick + '">' + selectedText + '</a>');
     216                                }
    159217                            }
    160218                            closePlyDialog();
     
    197255                    text: "Remove Event",
    198256                    click: function(){
    199                         //console.log(plyEventButton);
    200257                        delete plyEventButton.attributes.onclick;
    201258                        closePlyDialog();
     
    211268        });
    212269    });
     270
     271<?php if (isEditInElementor()): ?>
     272    elementor.hooks.addAction( 'panel/open_editor/widget/text-editor', function( panel, model, view ) {
     273        setTimeout(function() {
     274            elementorEditorAddButton();
     275        }, 500);
     276    } );
     277<?php else: ?>
    213278    QTags.addButton('platform_ly_link', 'Platform.ly', showPlyDialogOptions);
    214    
     279<?php endif; ?>
     280
    215281    function getBlockDOMNode(clientId){
    216282        document.querySelector('[data-block="' + clientId + '"]');
    217283    }
     284
     285    function elementorEditorAddButton() {
     286        // get an instance of the editor
     287        var editor = tinymce.activeEditor; //or tinymce.editors[0], or loop, whatever
     288        var plyButtonName = 'platform_ly_link';
     289
     290        if (editor.buttons.hasOwnProperty(plyButtonName)) {
     291            return;
     292        }
     293
     294        //add a button to the editor buttons
     295        editor.addButton(plyButtonName, {
     296          title: 'Add Platform.ly Link',
     297          icon: 'icon platform_ly_link_button',
     298          onclick: function () {
     299            showPlyDialogOptions();
     300          }
     301        });
     302        //the button now becomes
     303        var button=editor.buttons[plyButtonName];
     304        //find the buttongroup in the toolbar found in the panel of the theme
     305        var bg=editor.theme.panel.find('toolbar buttongroup')[0];
     306        //without this, the buttons look weird after that
     307        bg._lastRepaintRect=bg._layoutRect;
     308        //append the button to the group
     309        bg.append(button);
     310    }
    218311</script>
    219 
  • platformly/trunk/js/editor_btn.js

    r2024659 r2248759  
    11(function() {
    22    tinymce.PluginManager.add('platform_ly_link', function( editor, url ) {
     3        console.log('tinymce.PluginManager.add');
     4
    35        editor.addButton('platform_ly_link', {
    46            title: 'Add Platform.ly Link',
  • platformly/trunk/js/ply_add_link_functions.js

    r2208564 r2248759  
    5555                });
    5656            });
    57             jQuery('#ply-add-link-dialog').dialog({width: '600px'}).position({ my: "center", at: "center", of: window });
     57            jQuery('#ply-add-link-dialog').dialog({width: '600px'}); // .position({ my: "center", at: "center", of: window });
    5858        }
    5959    });
     
    8686                    </table>';
    8787            jQuery('#ply-add-link-dialog').html(table);
    88             jQuery('#ply-add-link-dialog').dialog('widget').position({ my: "center", at: "center", of: window });
     88            jQuery('#ply-add-link-dialog').dialog('widget'); // .position({ my: "center", at: "center", of: window });
    8989            jQuery('.ui-dialog-buttonpane button:contains("Add Link")').button().show();
    9090        }else{
     
    113113}
    114114function showPlyDialogOptions(){
    115     if(typeof wp.richText === 'undefined'){
     115    if(typeof wp.richText === 'undefined' && typeof elementor === 'undefined'){
    116116        jQuery('#ply-add-link-dialog').dialog('open');
    117117        get_ply_tracking_links();
    118118    }else{
    119119        jQuery('#ply-add-link-dialog').dialog('open');
    120         jQuery('#ply-add-link-dialog').dialog({width: '600px'}).position({ my: "center", at: "center", of: window });
     120        jQuery('#ply-add-link-dialog').dialog({width: '600px'}); // .position({ my: "center", at: "center", of: window });
    121121        var options = '<div id="ply-block-btns"><div class="ply-btn-etitor-block" onclick="get_ply_tracking_links()">Add a tracking link</div><div class="ply-btn-etitor-block" onclick="get_ply_projects()">Add an event</div></div>';
    122122        jQuery('#ply-add-link-dialog').html(options);
     
    188188                var table = '<table id="links_table_toggle">\n\
    189189                    <thead>\n\
    190                          <th style="width: 40px;">Select</th>\n\
     190                        <th style="width: 40px;">Select</th>\n\
    191191                        <th>Date</th>\n\
    192192                        <th>Action</th>\n\
     
    212212                jQuery('.ui-dialog-buttonpane button:contains("Add on Link Click")').button().show();
    213213                jQuery('.ui-dialog-buttonpane button:contains("Copy Code")').button().show();
     214
     215                // Check if no text selected
     216                if (elementor !== 'undefined' && typeof window.tinymce !== 'undefined' && !tinymce.activeEditor.isHidden()) {
     217                    var selectedText = tinymce.activeEditor.selection.getContent();
     218                    if (selectedText.length === 0) {
     219                        var ply_link_settings = '<div style="text-align: center;padding: 5px;">Add new link</div>\n\
     220                            <table><tbody>\n\
     221                            <tr><td style="padding: 5px;text-align: right;">Text</td><td style="width: 300px;"><input id="ply_dialog_link_text" type="text" onkeypress="jQuery(\'#ply-link-text-error\').hide();" placeholder="Click this one" required></td></tr>\n\
     222                            <tr id="ply-link-text-error"><td></td><td style="color: red">This field is required</td></tr>\n\
     223                            <tr><td style="padding: 5px;text-align: right;">URL</td><td style="width: 300px;"><input id="ply_dialog_link_url" type="text" onkeypress="jQuery(\'#ply-link-url-error\').hide();" placeholder="' + siteUrl + '" required></td></tr>\n\
     224                            <tr id="ply-link-url-error"><td></td><td style="color: red">This field is required</td></tr>\n\
     225                            </tbody></table>';
     226                        jQuery('#ply-dialog-link-settings').html(ply_link_settings);
     227                        jQuery('#ply-dialog-link-settings').show();
     228                    }
     229                }
    214230            }else{
    215231                jQuery('#ply-add-link-dialog #ply-events-block').html("<div id='ply-default-event-msg'>You haven't created an Event for this project yet.</div>");
    216232            }
    217             jQuery('#ply-add-link-dialog').dialog({width: '600px'}).position({ my: "center", at: "center", of: window });
     233            jQuery('#ply-add-link-dialog').dialog({width: '600px'}); // .position({ my: "center", at: "center", of: window });
    218234        }
    219235    });
     
    221237function showPlyDialogOnlyEventOptions(){
    222238    jQuery('#ply-add-link-dialog').dialog('open');
    223     jQuery('#ply-add-link-dialog').dialog({width: '600px'}).position({ my: "center", at: "center", of: window });
    224     //console.log(plyEventButton);
     239    jQuery('#ply-add-link-dialog').dialog({width: '600px'}); // .position({ my: "center", at: "center", of: window });
    225240    if(typeof plyEventButton.attributes.onclick !== 'undefined' && plyEventButton.attributes.onclick != ''){
    226241        jQuery('.ui-dialog-buttonpane button:contains("Edit Event")').button().show();
    227242        jQuery('.ui-dialog-buttonpane button:contains("Remove Event")').button().show();
    228243        jQuery('#ply-add-link-dialog').html("There's existing event for this button. Choose one of the following action.");
    229         jQuery('#ply-add-link-dialog').dialog({width: '600px'}).position({ my: "center", at: "center", of: window });
     244        jQuery('#ply-add-link-dialog').dialog({width: '600px'}); // .position({ my: "center", at: "center", of: window });
    230245    }else{
    231246        get_ply_projects();
  • platformly/trunk/js/ply_editor_btn_functions.js

    r2024659 r2248759  
    55      );
    66 */
    7   var iconEl = el('span',{className: 'platform_ly_link_button_new'},
    8             el('i',{
    9                 className: 'platform_ly_link_button',
    10             })
    11         );
     7    var iconEl = el('span',{className: 'platform_ly_link_button_new'},
     8        el('i',{
     9            className: 'platform_ly_link_button'
     10        })
     11    );
    1212 
    1313    wp.richText.registerFormatType('platform-ly/link', {
    14     title: 'Platform Link',
    15     tagName: 'a',
    16     attributes: {
    17             url: 'href',
    18             onclick: 'onclick',
    19             target: 'target',
    20     },
    21     className: 'platform-ly-link',
    22     edit: function( props ) {
     14        title: 'Platform Link',
     15        tagName: 'a',
     16        attributes: {
     17                url: 'href',
     18                onclick: 'onclick',
     19                target: 'target'
     20        },
     21        className: 'platform-ly-link',
     22        edit: function( props ) {
    2323            var selectedBlock = wp.data.select("core/editor").getSelectedBlock();
    2424            if(selectedBlock.name != 'core/button'){
    25         return wp.element.createElement(wp.editor.RichTextToolbarButton, {
    26             icon: iconEl,
    27             title: 'Add Platform.ly Link',
    28             onClick: function() {
    29                             plySelectedWord = props;
    30                             plyEventButton = {};
    31                             showPlyDialogOptions();
    32                             //add_platform_ly_link();
    33                 /*props.onChange( wp.richText.toggleFormat( props.value, {type: 'platform-ly/link', attributes: {
    34                     url: '#test',
    35                 } } ) );*/
    36             },
    37             isActive: props.isActive,
    38         });
     25                return wp.element.createElement(wp.editor.RichTextToolbarButton, {
     26                    icon: iconEl,
     27                    title: 'Add Platform.ly Link',
     28                    onClick: function() {
     29                        plySelectedWord = props;
     30                        plyEventButton = {};
     31                        showPlyDialogOptions();
     32                        //add_platform_ly_link();
     33                        /*props.onChange( wp.richText.toggleFormat( props.value, {type: 'platform-ly/link', attributes: {
     34                            url: '#test',
     35                        } } ) );*/
     36                    },
     37                    isActive: props.isActive
     38                });
    3939            }else{
    4040               return [];
    4141            }
    42     },
     42        }
    4343    });
    4444function withClientIdClassName(settings, name){
     
    4949            source: "attribute",
    5050            type: "string"
    51         }
     51        };
    5252    }
    5353    return settings;
  • platformly/trunk/platformly.php

    r2208564 r2248759  
    44Plugin Name: Platform.ly Official
    55Description: Platform.ly plugin is the easiest way to setup your optins and pages that your created with Platform.ly. After building your optin or page with our interactive WYSIWYG builders, you can set them up to show on your site with just a couple of clicks.
    6 Version: 1.6
     6Version: 1.6.1
    77Author: Platform.ly
    88Author URI: https://www.platform.ly/
     
    387387}
    388388
    389 add_action('admin_head', 'add_mce_platform_ly_link');
    390 
    391389function platform_ly_editor_css(){
    392390    wp_enqueue_style('ply_styles', plugin_dir_url(__FILE__) . "css/ply_styles.css");
     
    394392}
    395393
    396 add_action('admin_enqueue_scripts', 'platform_ly_editor_css');
     394function add_mce_platform_ly_link_to_elementor_editor(){
     395    platform_ly_editor_css();
     396    add_mce_platform_ly_link();
     397}
     398
     399/**
     400 * Check if the user is currently editing using Elementor
     401 * @return boolean
     402 */
     403function isEditInElementor() {
     404    $path = parse_url($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], PHP_URL_PATH);
     405    if (strpos($path, 'post.php') !== false && isset($_GET['action']) && $_GET['action'] === 'elementor') {
     406        return true;
     407    } else {
     408        return false;
     409    }
     410}
     411
     412if (isEditInElementor()) {
     413    add_action('elementor/editor/before_enqueue_scripts', 'add_mce_platform_ly_link_to_elementor_editor');
     414} else {
     415    add_action('admin_enqueue_scripts', 'platform_ly_editor_css');
     416    add_action('admin_head', 'add_mce_platform_ly_link');
     417}
    397418
    398419function platform_ly_set_project_code(){
  • platformly/trunk/readme.txt

    r2208564 r2248759  
    7878== Upgrade Notice ==
    7979
     80= 1.6.1 =
     81- Integration with Elementor plugin
     82
    8083= 1.6 =
    8184- Fixed jQuery issues
Note: See TracChangeset for help on using the changeset viewer.