-
- 1,145 Posts
No, plugin per tv would be utterly tedious.
Put all tv ids in an array (in system settings : 3, 5, 87, 65, 5, 6, 8, or directly in the one plugin.
Then a simple PHP foreach.
If you are still stuck, I can whip something up.
TinymceWrapper: Complete back/frontend content solution.
Harden your MODX site by
passwording your three main folders:
core, manager, connectors and renaming your
assets (thank me later!)
5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
-
- 24,544 Posts
I think the loop would be better inside the JS, rather than registering 20 blocks of JS code.
$modx->regClientStartupHTMLBlock('
<script>
Ext.onReady(function() {
arr = array('20','12','34');
for (var i = 0, len = arr.length; i < len; i++) {
// var tv = document.getElementById("tv'.$tvId.'");
var tv = Ext.get("tv'.$arr[i].'");
var tvDef = Ext.get("tvdef'.$arr[i].'");
//Note upon save, this tv will have a real value in Database
if(tv){
tvValue = tv.dom.value;
tv.dom.value = tvValue || "'.$defaultTVvalue.'";
}
}
//If you have that squiggly thing for TV refresh, the value will be set
if(tvDef){
tvDefValue = tvDef.dom.value;
tvDef.dom.value = tvDefValue || "'.$defaultTVvalue.'";
}
});
</script>
');
[ed. note: BobRay last edited this post 6 years, 7 months ago.]
-
- 1,145 Posts
Yup that's it right there.
Exactly my thought.
You could even go crazy and get TV id from TV name.
If TV names are more stable in your project.
Even get that value from system settings, then explode the list in the plugin
TinymceWrapper: Complete back/frontend content solution.
Harden your MODX site by
passwording your three main folders:
core, manager, connectors and renaming your
assets (thank me later!)
5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
-
- 24,544 Posts
I find that it's difficult to get all the quotes right in a block like this. It might be a good case for PHP's heredoc format, which preserves quotation marks and interprets the variables, though some variables need curly braces.
$script = <<< QUOTE
<script>
Ext.onReady(function() {
arr = array('20','12','34');
var tvValue;
var tvDefValue;
for (var i = 0, len = arr.length; i < len; i++) {
// var tv = document.getElementById("tv'.$tvId.'");
var tv = Ext.get("tv{arr[i]}");
var tvDef = Ext.get("tvdef{arr[i]}");
//Note upon save, this tv will have a real value in Database
if(tv){
tvValue = tv.dom.value;
tv.dom.value = tvValue || "$defaultTVvalue";
}
}
//If you have that squiggly thing for TV refresh, the value will be set
if(tvDef){
tvDefValue = tvDef.dom.value;
tvDef.dom.value = tvDefValue || "$defaultTVvalue";
}
});
</script>
QUOTE;
$modx->regClientStartupHTMLBlock($script);