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 Wed May 30 2018, 20:46

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 Thu May 31 2018, 16:49; 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 Wed May 30 2018, 22:53

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 : 51172
Reputation : 3507
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 Thu May 31 2018, 01:41

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 Thu May 31 2018, 03:43

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 Thu May 31 2018, 16:32

@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 Thu May 31 2018, 21:12

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 : 51172
Reputation : 3507
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