JavaScript - cambio estilo con condición

 
Vista:

cambio estilo con condición

Publicado por simone (5 intervenciones) el 30/03/2016 18:33:31
Hola,
Tengo el siguiente problema. Necesito que, según se cumplan una condición, el estilo del texto cambie (overlay en background).

Os dejo el codigo para ver donde está el error.

HTML
1
2
3
4
5
6
<form>
  <label>Main Text Area</label>
  <body>
    <textarea id="maintext" rows="7">Esta é uma @guia de @arrecadacao de @exemplo com @receitaCodigo</textarea>
  </body>
</form>

JAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var mentions = {
  'test': 'test@gmail.com',
  'othertest': 'othertest@gmail.com',
  'guia': 'Guia',
  'arrecadacao': 'Arrecadação',
  'exemplo': 'ExEmplO',
  'fornecedorCodigo': '',
  'fornecedorNome': '',
  'movimentacaoNotaFiscal': '',
  'movimentacaoCheque': '',
  'movimentacaoTed': '',
  'receitaCodigo': '',
  'despesaPrincipalCodigo': '',
  'despesaSecundariaCodigo': '',
  'bancoCodigo': '',
  'bancoNome': '',
  'agenciaCodigo': '',
  'agenciaDigito': '',
  'agenciaNome': '',
  'contaNumero': '',
  'contaDigito': ''
};
mentions['fornecedorNome'] = 'Organizações Tabajara';
 
var arrayOfMentions = Object.keys(mentions).map(function(key) {
  var val = {};
  val[key] = mentions[key];
  return val;
});
 
$('#maintext').textcomplete([{
  mentions: arrayOfMentions,
  match: /\B@(\w*)$/,
  search: function(term, callback) {
    callback($.map(this.mentions, function(mention) {
      var key = Object.keys(mention)[0];
      return key.indexOf(term) === 0 ? mention : null;
    }));
  },
  template: function(mention) {
    return '@' + Object.keys(mention)[0];
  },
  index: 1,
  replace: function(mention) {
    var key = Object.keys(mention)[0];
    if(mention[key]){
    	return mention[key];
    } else {
    	return '@' + key + ' ';
    }
  },
}],
{ appendTo: 'body' }).overlay([
    {
        match: /\B@\w+/g,
        css: {
            'background-color' : '#d8dfea',
        }
    },
]);
 
$('#maintext').focus(function() {
  var content = $(this).text();
  var finalText = content.replace(
    /\B@(\w*)/gi,
    function(str, index) {
      if(mentions[index]){
      	return mentions[index];
      } else {
      	return '@'+index;
      }
    }
  );
  $(this).text(finalText);
});

Alguien tiene idea? Gracias!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder