includes/clientside/static/rank-manager.js
changeset 651 ce9d78d7251d
parent 628 ab6f55abb17e
child 699 c7d737202d59
equal deleted inserted replaced
650:e45183014778 651:ce9d78d7251d
     3  */
     3  */
     4 
     4 
     5 var RankEditorControl = function(rankdata)
     5 var RankEditorControl = function(rankdata)
     6 {
     6 {
     7   this.rankdata = ( typeof(rankdata) == 'object' ) ? rankdata : {};
     7   this.rankdata = ( typeof(rankdata) == 'object' ) ? rankdata : {};
       
     8   if ( !this.rankdata.rank_style )
       
     9   {
       
    10     this.rankdata.rank_style = '';
       
    11   }
     8   
    12   
     9   // have the browser parse CSS for us and use an anchor to be as close
    13   // have the browser parse CSS for us and use an anchor to be as close
    10   // as possible in calculating CSS
    14   // as possible in calculating CSS
    11   
    15   
    12   // this is kind of a hack as it relies on setAttribute/getAttribute in
    16   // this is kind of a hack as it relies on setAttribute/getAttribute in
   195     
   199     
   196     tr_color.appendChild(td_color_l);
   200     tr_color.appendChild(td_color_l);
   197     tr_color.appendChild(td_color_f);
   201     tr_color.appendChild(td_color_f);
   198     table.appendChild(tr_color);
   202     table.appendChild(tr_color);
   199     
   203     
       
   204     // field: additional CSS
       
   205     var tr_css = document.createElement('tr');
       
   206     
       
   207     var td_css_l = document.createElement('td');
       
   208     td_css_l.className = 'row2';
       
   209     td_css_l.appendChild(document.createTextNode($lang.get('acpur_field_style_css')));
       
   210     tr_css.appendChild(td_css_l);
       
   211     
       
   212     var td_css_f = document.createElement('td');
       
   213     td_css_f.className = 'row2';
       
   214     var f_css = document.createElement('input');
       
   215     f_css.type = 'text';
       
   216     f_css.value = this.stripBasicCSSAttributes(this.rankdata.rank_style);
       
   217     f_css.style.width = '98%';
       
   218     f_css.editor = this;
       
   219     f_css.onkeyup = function()
       
   220     {
       
   221       if ( !(trim(this.value)).match(/^((([a-z-]+):(.+?);)+)?$/) )
       
   222         return;
       
   223       var newcss = this.editor.stripExtendedCSSAttributes(String(this.editor.style_sim_obj.getAttribute('style'))) + ' ' + this.value;
       
   224       this.editor.preview_div.setAttribute('style', 'font-size: x-large; ' + newcss);
       
   225       this.editor.style_sim_obj.setAttribute('style', newcss);
       
   226     }
       
   227     this.f_css = f_css;
       
   228     td_css_f.appendChild(f_css);
       
   229     tr_css.appendChild(td_css_f);
       
   230     table.appendChild(tr_css);
       
   231     
   200     // "field": preview
   232     // "field": preview
   201     var tr_preview = document.createElement('tr');
   233     var tr_preview = document.createElement('tr');
   202     var td_preview_l = document.createElement('td');
   234     var td_preview_l = document.createElement('td');
   203     td_preview_l.className = 'row2';
   235     td_preview_l.className = 'row1';
   204     td_preview_l.appendChild(document.createTextNode($lang.get('acpur_field_preview')));
   236     td_preview_l.appendChild(document.createTextNode($lang.get('acpur_field_preview')));
   205     tr_preview.appendChild(td_preview_l);
   237     tr_preview.appendChild(td_preview_l);
   206     
   238     
   207     var td_preview_f = document.createElement('td');
   239     var td_preview_f = document.createElement('td');
   208     td_preview_f.className = 'row2';
   240     td_preview_f.className = 'row1';
   209     var div_preview = document.createElement('a');
   241     var div_preview = document.createElement('a');
   210     this.preview_div = div_preview;
   242     this.preview_div = div_preview;
   211     div_preview.style.fontSize = 'x-large';
   243     div_preview.style.fontSize = 'x-large';
   212     div_preview.appendChild(document.createTextNode(''));
   244     div_preview.appendChild(document.createTextNode(''));
   213     div_preview.firstChild.nodeValue = ( this.editing ) ? this.rankdata.rank_title : '';
   245     div_preview.firstChild.nodeValue = ( this.editing ) ? this.rankdata.rank_title : '';
   319     var rgb = this.hex2rgb(hexval);
   351     var rgb = this.hex2rgb(hexval);
   320     var lumin = ( rgb[0] + rgb[1] + rgb[2] ) / 3;
   352     var lumin = ( rgb[0] + rgb[1] + rgb[2] ) / 3;
   321     return ( lumin > 60 ) ? '000000' : 'ffffff';
   353     return ( lumin > 60 ) ? '000000' : 'ffffff';
   322   }
   354   }
   323   
   355   
   324   this.getJSONDataset = function()
   356   /**
   325   {
   357    * Strips out basic CSS attributes (color, font-weight, font-style, text-decoration) from a snippet of CSS.
   326     
   358    * @param string
       
   359    * @return string
       
   360    */
       
   361   
       
   362   this.stripBasicCSSAttributes = function(css)
       
   363   {
       
   364     return trim(css.replace(/(color|font-weight|font-style|text-decoration): ?([A-z0-9# ,\(\)]+);/g, ''));
       
   365   }
       
   366   
       
   367   /**
       
   368    * Strips out all but basic CSS attributes.
       
   369    * @param string
       
   370    * @return string
       
   371    */
       
   372   
       
   373   this.stripExtendedCSSAttributes = function(css)
       
   374   {
       
   375     var match;
       
   376     var final_css = '';
       
   377     var basics = ['color', 'font-weight', 'font-style', 'text-decoration'];
       
   378     while ( match = css.match(/([a-z-]+):(.+?);/) )
       
   379     {
       
   380       if ( in_array(match[1], basics) )
       
   381       {
       
   382         final_css += ' ' + match[0] + ' ';
       
   383       }
       
   384       css = css.replace(match[0], '');
       
   385     }
       
   386     final_css = trim(final_css);
       
   387     return final_css;
   327   }
   388   }
   328   
   389   
   329   this.getCSS = function()
   390   this.getCSS = function()
   330   {
   391   {
   331     return this.style_sim_obj.getAttribute('style');
   392     return this.style_sim_obj.getAttribute('style');
   431   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   492   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   432     {
   493     {
   433       if ( ajax.readyState == 4 && ajax.status == 200 )
   494       if ( ajax.readyState == 4 && ajax.status == 200 )
   434       {
   495       {
   435         var response = String(ajax.responseText + '');
   496         var response = String(ajax.responseText + '');
   436         if ( response.substr(0, 1) != '{' )
   497         if ( !check_json_response(response) )
   437         {
   498         {
   438           handle_invalid_json(ajax.responseText);
   499           handle_invalid_json(ajax.responseText);
   439           return false;
   500           return false;
   440         }
   501         }
   441         try
   502         try
   486   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   547   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   487     {
   548     {
   488       if ( ajax.readyState == 4 && ajax.status == 200 )
   549       if ( ajax.readyState == 4 && ajax.status == 200 )
   489       {
   550       {
   490         var response = String(ajax.responseText + '');
   551         var response = String(ajax.responseText + '');
   491         if ( response.substr(0, 1) != '{' )
   552         if ( !check_json_response(response) )
   492         {
   553         {
   493           handle_invalid_json(ajax.responseText);
   554           handle_invalid_json(ajax.responseText);
   494           return false;
   555           return false;
   495         }
   556         }
   496         try
   557         try
   632   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   693   ajaxPost(makeUrlNS('Admin', 'UserRanks/action.json'), 'r=' + json_packet, function()
   633     {
   694     {
   634       if ( ajax.readyState == 4 && ajax.status == 200 )
   695       if ( ajax.readyState == 4 && ajax.status == 200 )
   635       {
   696       {
   636         var response = String(ajax.responseText + '');
   697         var response = String(ajax.responseText + '');
   637         if ( response.substr(0, 1) != '{' )
   698         if ( !check_json_response(response) )
   638         {
   699         {
   639           handle_invalid_json(ajax.responseText);
   700           handle_invalid_json(ajax.responseText);
   640           return false;
   701           return false;
   641         }
   702         }
   642         try
   703         try