rasmusbergpalm / jslate

Write your dashboards in pure html/js
jslate.com
244 stars 54 forks source link

Change widget backgronud color #56

Closed n7k1 closed 10 years ago

n7k1 commented 10 years ago

Any ideas on how to change the background color of a single widget from within the html template?

This works but changes all the widget backgrounds:

n7k1 commented 10 years ago

This is my jquery in-widget hack:

            //change the backgronud color of the widget in the 'Select a template' view
            if($('#${wid}').parent("div").attr('class') == 'well') {
               $('#${wid}').parent("div").css({"background-color":"red"});
            }                
            //change the backgronud color of the widget in the dashboard view
            else if($('#${wid}').parent("div").parent("div").attr('class') == 'well dragbox') {
               $('#${wid}').parent("div").parent("div").css({"background-color":"red"});
            }

Forgive me if it's ugly. I'm new to jquery.

n7k1 commented 10 years ago

This is uglier but it works better:

            //debug
            //console.log($('#${wid}').parent("div").attr('id'));
            //console.log($('#${wid}').parent("div").parent("div"));

            //change the background color of the widget in the dashboard view
            if($('#${wid}').parent("div").parent("div").attr('id').search('dragbox') >= 0) {
               $('#${wid}').parent("div").parent("div").css({"background-color":"white"});
            }
            //change the background color of the widget in the 'Select a template' view
            else if($('#${wid}').parent("div").attr('id').search('view') >= 0) {
               $('#${wid}').parent("div").css({"background-color":"white"});
            }                
rasmusbergpalm commented 10 years ago

If you're using the latest and greatest jSlate you can add css to the entire dashboard under settings. Might make it prettier.