The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

javascript code work with members but doesn't with visiteurs

3 posters

Go down

Solved javascript code work with members but doesn't with visiteurs

Post by alla13 May 30th 2018, 7:46 pm

hello there i hope you are doing well
i have this code made to me by @ Ange Tuteur
and modified a bit by @pedxz
i did post this issue in the arabic forum support and no one could solve it
so here i am
with members the code work just fine
the issue is that the code doesn't work with visteur
a video to show the issue



the code
Code:


$(function() {
  if (!$.sceditor) return;
 
  $.sceditor.command.set('cmd', {
 
  dropDown : function(editor, caller, callback) {
 
    var content = $(
    '<div>' +
    '  <div>' +
    '    <label>رابط</label>' +
    '    <input type="text" placeholder="رابط الخلفية" id="cmdValue" value="" />' +
    '  </div>' +
    '  <div>' +
    '    <input type="button" class="button" value="ادخال الخلفية">' +
    '  </div>' +
    '</div>'
    );
            content.find('.button').click(function(e) {
                callback(content.find('select').val());
                editor.closeDropDown(true);
            });
            editor.createDropDown(caller, "cmd", content);
  },
  // WYSIWYG MODE
  exec : function(caller) {
  var editor = this;
      $.sceditor.command.get('cmd').dropDown(editor, caller, function(cmd) {
        var before = '[tbl]', title = $('#cmdValue').val();
        if(title !== '') {
          before = '[tbl=' + title + ']';
            editor.wysiwygEditorInsertHtml(before);
        }
      });
  },
  // SOURCE MODE
  txtExec : function(caller) {
  var editor = this;
      $.sceditor.command.get('cmd').dropDown(editor, caller, function(cmd) {
        var title = $('#cmdValue').val();
        if(title) {
            editor.insertText('[tbl=' + title + ']');
        } else {
            editor.insertText('[tbl=' + title + ']');
        }
      });
  }, tooltip: "خلفية الموضوع"});
 
    for (var a = $('.post .content'), i = 0, j = a.length; i < j; i++) {
    if (/\[tbl=.*?\]/i.test(a[i].innerHTML)) {
      a[i].innerHTML = a[i].innerHTML.replace(/\[tbl=(.*?)\]/i, function(M, $1) {
        a[i].style.backgroundImage = 'url(' + $1 + ')';
        return '';
      });
    }
  }
 
  toolbar = toolbar.replace(/image/,'cmd,image');
 
  $('head').append(
  '<style type="text/css">' +
  '.sceditor-button-cmd div {' +
  '  background:url(https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/image-16.png) !important}' +
  '  .sceditor-cmd {' +
  '  width:auto;' +
  '  height:auto;' +
  '  overflow-y:auto;' +
  '}' +
  '.sceditor-cmd select {' +
  '  margin: 0 0 .75em;' +
  '}' +
  '</style>'
  );
});


Last edited by alla13 on May 31st 2018, 3:49 pm; edited 1 time in total
alla13
alla13
Forumember

Posts : 91
Reputation : 6
Language : Arab5/5 Eng3/5 Fr2/5

http://alla-omar.mo-rpg.com

Back to top Go down

Solved Re: javascript code work with members but doesn't with visiteurs

Post by SLGray May 30th 2018, 9:53 pm

So the issue is that a code appears when you are a visitor?


javascript code work with members but doesn't with visiteurs Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51554
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: javascript code work with members but doesn't with visiteurs

Post by alla13 May 31st 2018, 12:41 am

yes, instead of a background the code shows up like the java does not work
alla13
alla13
Forumember

Posts : 91
Reputation : 6
Language : Arab5/5 Eng3/5 Fr2/5

http://alla-omar.mo-rpg.com

Back to top Go down

Solved Re: javascript code work with members but doesn't with visiteurs

Post by Wecoc May 31st 2018, 2:43 am

Everything (SCEditor button and the tag effect) is in the same function. That function is aborted in the very start if the SCEditor text area is not found, which happens in guest mode but also in closed topics, etc. That's where this bug comes from. You can simply change it to 2 different functions, so only de button function is aborted.

Code:
$(function() {
  if (!$.sceditor) return;
  $.sceditor.command.set('cmd', {
  dropDown : function(editor, caller, callback) {
    var content = $(
    '<div>' +
    '  <div>' +
    '    <label>رابط</label>' +
    '    <input type="text" placeholder="رابط الخلفية" id="cmdValue" value="" />' +
    '  </div>' +
    '  <div>' +
    '    <input type="button" class="button" value="ادخال الخلفية">' +
    '  </div>' +
    '</div>'
    );
    content.find('.button').click(function(e) {
      callback(content.find('select').val());
      editor.closeDropDown(true);
    });
    editor.createDropDown(caller, "cmd", content);
  },
  // WYSIWYG MODE
  exec : function(caller) {
    var editor = this;
    $.sceditor.command.get('cmd').dropDown(editor, caller, function(cmd) {
      var before = '[tbl]', title = $('#cmdValue').val();
      if(title !== '') {
        before = '[tbl=' + title + ']';
          editor.wysiwygEditorInsertHtml(before);
      }
    });
  },
  // SOURCE MODE
  txtExec : function(caller) {
    var editor = this;
    $.sceditor.command.get('cmd').dropDown(editor, caller, function(cmd) {
      var title = $('#cmdValue').val();
      if(title) {
          editor.insertText('[tbl=' + title + ']');
      } else {
          editor.insertText('[tbl=' + title + ']');
      }
    });
  }, tooltip: "خلفية الموضوع"});
  toolbar = toolbar.replace(/image/,'cmd,image');
});

$(function() {
  for (var a = $('.post .content'), i = 0, j = a.length; i < j; i++) {
    if (/\[tbl=.*?\]/i.test(a[i].innerHTML)) {
      a[i].innerHTML = a[i].innerHTML.replace(/\[tbl=(.*?)\]/i, function(M, $1) {
        a[i].style.backgroundImage = 'url(' + $1 + ')';
        return '';
      });
    }
  }
 
  $('head').append(
    '<style type="text/css">' +
    '.sceditor-button-cmd div {' +
    '  background:url(https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/image-16.png) !important}' +
    '  .sceditor-cmd {' +
    '  width:auto;' +
    '  height:auto;' +
    '  overflow-y:auto;' +
    '}' +
    '.sceditor-cmd select {' +
    '  margin: 0 0 .75em;' +
    '}' +
    '</style>'
  );
});

This should work Smile
Wecoc
Wecoc
Forumember

Male Posts : 144
Reputation : 111
Language : Catalan, Spanish, English

Back to top Go down

Solved Re: javascript code work with members but doesn't with visiteurs

Post by alla13 May 31st 2018, 3:32 pm

@Wecoc
thank you very much topic solved
but another problem show up
the guest can't reply now
even when i give them permission

nevermind i solved the issue
alla13
alla13
Forumember

Posts : 91
Reputation : 6
Language : Arab5/5 Eng3/5 Fr2/5

http://alla-omar.mo-rpg.com

Back to top Go down

Solved Re: javascript code work with members but doesn't with visiteurs

Post by SLGray May 31st 2018, 8:12 pm

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


javascript code work with members but doesn't with visiteurs Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51554
Reputation : 3524
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum