diff options
| author | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-17 12:12:22 +0300 |
|---|---|---|
| committer | George Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2023-04-17 12:12:22 +0300 |
| commit | 68fc9e55e538e03f94509731ab41a0c8cf96710f (patch) | |
| tree | 3edb1e81864ac3eb35ba0fe8087ed24da1b812bf /html/assets/js/post-features.js | |
| parent | 84b2da85a1b452922dadb6a609533b9945afe51d (diff) | |
| download | classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.tar.gz classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.tar.bz2 classroom-68fc9e55e538e03f94509731ab41a0c8cf96710f.zip | |
setup a real server environment (apache DocumentRoot=/var/www/public)
Diffstat (limited to 'html/assets/js/post-features.js')
| -rw-r--r-- | html/assets/js/post-features.js | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/html/assets/js/post-features.js b/html/assets/js/post-features.js deleted file mode 100644 index ca2928c..0000000 --- a/html/assets/js/post-features.js +++ /dev/null @@ -1,148 +0,0 @@ -const valid_modals = [ // supported sort-code keys - 'product', - 'store' -]; - - -const symbol_escapes = [ - { esc: '>', chr: '>' }, - { esc: '<', chr: '<' }, - { esc: '&', chr: '&' }, - { esc: '"', chr: '\"' }, - { esc: ''', chr: '\'' }, - { esc: '€', chr: '€' }, - { esc: '©', chr: '©' }, - { esc: '®', chr: '®' } -]; - - -/** inject_codeblocks - * --- -- -- - - - - * - * NOTE: - * a short-code is a mustache block of 3 parametres: - * {{ object = someID ; some label description }} - * ex. `{{product=1507175; Coca Cola Zero}}` - * - * The short-code is parsed to a code-block: - * an `a` modal-toggler link with certain data-attributes (+label), ex: - * `<a class='modal-toggler view-product' data-id='1507175'>Coca Cola Zero</a>` - * - * @param code (string): original content html with short-codes - * @returns (string): html content with code-blocks - */ -function inject_codeblocks(code) { - // isolate all mustache blocks - const regexp = /{{(.*?)}}/g; // regex makes multiple-matching easier - const matches = [...code.matchAll(regexp)]; - // console.log(matches); - - var output = code; // use a copy of (source) code - - matches.forEach( match => { - // parse (every) match - // NOTE: - // match array has 3 items; example: - // match[0] : `{{store=247; Pasalimani Market}}` - // match[1] : `store=247; Pasalimani Market` - // match[3] : the (source) code string - let blockparts = unescaped_str( match[1] ).split(';'); - let main_unit = blockparts[0].replaceAll(' ','').split('='); - let target = main_unit[0].toLowerCase(); - let id = main_unit[1]; - let label = escaped_str(blockparts[1]); - if (valid_modals.includes(target)) { - let codeblock = `<a href="#" data-toggle="modal" data-target="#view-${target}" data-id="${id}" class="modal-toggler js-get_${target}">${label}</a>`; - output = output.replaceAll(match[0], codeblock); - } - }); - - return output; -} - - -// pair of function to escepe/unescape special html symbols -// --- -- -- - - - -function unescaped_str(txt) { - symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.esc, pair.chr); }) - return txt; -} - -function escaped_str(txt) { - symbol_escapes.forEach( pair => { txt = txt.replaceAll(pair.chr, pair.esc); }) - return txt; -} - - -$(document).ready(function() { - - - /** translate short-codes to code-blocks - * ------------------------------------------------------------------------- - */ - var content = $('.content .article-body').html(); // get code with shorts - $('.content .article-body').html( inject_codeblocks(content) ); // put code with blocks - - - - /** modal listeners - * ------------------------------------------------------------------------- - */ - - // open store modal listener - // --- -- -- - - - - $(document).on('click', '.js-get_store', function (e) { - e.preventDefault(); - var id = $(this).data('id'); // id for requesting content via ajax - - $('#dynamic-content').html(''); - $('#modal-loader').show(); - - $.ajax({ - url: '/libs/modals/modalStore.php', - type: 'POST', - cache: false, - data: 'id=' + id, - dataType: 'html' - }) - .done(function (data) { - $('#dynamic-content').html(''); - $('#dynamic-content').html(data); - $('#modal-loader').hide(); - }) - .fail(function () { - $('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); - $('#modal-loader').hide(); - }); - }); - - // open product modal listener - // --- - $(document).on('click', '.js-get_product', function (e) { - e.preventDefault(); - var id = $(this).data('id'); // id for requesting content via ajax - - $('#dynamic-product').html(''); - $('#modal-loader').show(); - - $.ajax({ - url: '/products/ajax/get_product_full', - cache: false, - type: 'POST', - data: { id: id }, - dataType: 'html' - }) - .done(function (data) { - $('#dynamic-product').html(''); - $('#dynamic-product').html(data); - $('#modal-loader').hide(); - - }) - .fail(function () { - $('#dynamic-product').html('<i class="glyphicon glyphicon-info-sign"></i> Υπήρξε κάποιο πρόβλημα, παρακαλώ προσπαθήστε ξανά.'); - $('#modal-loader').hide(); - - }); - }); - -});
\ No newline at end of file |
