|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: 1.91 JavascriptJQuery.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class JavascriptJQuery. |
|
28
|
|
|
*/ |
|
29
|
|
|
class JavascriptJQuery extends TDMCreateFile |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/* |
|
32
|
|
|
* @public function constructor |
|
33
|
|
|
* @param null |
|
34
|
|
|
*/ |
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/* |
|
44
|
|
|
* @static function &getInstance |
|
45
|
|
|
* @param null |
|
46
|
|
|
*/ |
|
47
|
|
|
/** |
|
48
|
|
|
* @return JavascriptJQuery |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function &getInstance() |
|
51
|
|
|
{ |
|
52
|
|
|
static $instance = false; |
|
53
|
|
|
if (!$instance) { |
|
54
|
|
|
$instance = new self(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $instance; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/* |
|
61
|
|
|
* @public function write |
|
62
|
|
|
* @param string $module |
|
63
|
|
|
* @param string $filename |
|
64
|
|
|
*/ |
|
65
|
|
|
/** |
|
66
|
|
|
* @param $module |
|
67
|
|
|
* @param $filename |
|
68
|
|
|
*/ |
|
69
|
|
|
public function write($module, $filename) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->setModule($module); |
|
72
|
|
|
$this->setFileName($filename); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/* |
|
76
|
|
|
* @public function getJavascriptJQueryButtons |
|
77
|
|
|
* @param null |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getJavascriptJQueryButtons() |
|
82
|
|
|
{ |
|
83
|
|
|
$ret = <<<EOT |
|
84
|
|
|
$(document).ready(function(){ |
|
85
|
|
|
$( "button, input:button, input:submit, input:file, input:reset" ).css("color","inherit").button(); |
|
86
|
|
|
$( ".check" ).css("color","#fff").button(); |
|
87
|
|
|
$( ".radio" ).css("color","#fff").buttonset(); |
|
88
|
|
|
$( ".toolbar" ).css("color","#000").buttonset(); |
|
89
|
|
|
});\n\n |
|
90
|
|
|
EOT; |
|
91
|
|
|
|
|
92
|
|
|
return $ret; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/* |
|
96
|
|
|
* @public function getJavascriptJQueryPrint |
|
97
|
|
|
* @param null |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getJavascriptJQueryPrint() |
|
102
|
|
|
{ |
|
103
|
|
|
$ret = <<<EOT |
|
104
|
|
|
// <![CDATA[ |
|
105
|
|
|
/*------------------------------------------------------------------------------ |
|
106
|
|
|
Excerpts from the jsUtilities Library |
|
107
|
|
|
Version: 2.1 |
|
108
|
|
|
Homepage: http://www.easy-designs.net/code/jsUtilities/ |
|
109
|
|
|
License: Creative Commons Attribution-ShareAlike 2.0 License |
|
110
|
|
|
http://creativecommons.org/licenses/by-sa/2.0/ |
|
111
|
|
|
Note: If you change or improve on this script, please let us know. |
|
112
|
|
|
------------------------------------------------------------------------------*/ |
|
113
|
|
|
if(Array.prototype.push == null) { |
|
114
|
|
|
Array.prototype.push = function(item) { |
|
115
|
|
|
this[this.length] = item; |
|
116
|
|
|
return this.length; |
|
117
|
|
|
}; |
|
118
|
|
|
}; |
|
119
|
|
|
// --------------------------------------------------------------------- |
|
120
|
|
|
// function.apply (if unsupported) |
|
121
|
|
|
// Courtesy of Aaron Boodman - http://youngpup.net |
|
122
|
|
|
// --------------------------------------------------------------------- |
|
123
|
|
|
if (!Function.prototype.apply) { |
|
124
|
|
|
Function.prototype.apply = function(oScope, args) { |
|
125
|
|
|
var sarg = []; |
|
126
|
|
|
var rtrn, call; |
|
127
|
|
|
if (!oScope) oScope = window; |
|
128
|
|
|
if (!args) args = []; |
|
129
|
|
|
for (var i = 0; i < args.length; i++) { |
|
130
|
|
|
sarg[i] = "args["+i+"]"; |
|
131
|
|
|
}; |
|
132
|
|
|
call = "oScope.__applyTemp__(" + sarg.join(",") + ");"; |
|
133
|
|
|
oScope.__applyTemp__ = this; |
|
134
|
|
|
rtrn = eval(call); |
|
135
|
|
|
oScope.__applyTemp__ = null; |
|
136
|
|
|
return rtrn; |
|
137
|
|
|
}; |
|
138
|
|
|
}; |
|
139
|
|
|
function inArray(needle) { |
|
140
|
|
|
for (var i=0; i < this.length; i++) { |
|
141
|
|
|
if (this[i] === needle) { |
|
142
|
|
|
return i; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
return false; |
|
146
|
|
|
} |
|
147
|
|
|
function addClass(theClass) { |
|
148
|
|
|
if (this.className != '') { |
|
149
|
|
|
this.className += ' ' + theClass; |
|
150
|
|
|
} else { |
|
151
|
|
|
this.className = theClass; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
function lastChildContainingText() { |
|
155
|
|
|
var testChild = this.lastChild; |
|
156
|
|
|
var contentCntnr = ['p','li','dd']; |
|
157
|
|
|
while (testChild.nodeType != 1) { |
|
158
|
|
|
testChild = testChild.previousSibling; |
|
159
|
|
|
} |
|
160
|
|
|
var tag = testChild.tagName.toLowerCase(); |
|
161
|
|
|
var tagInArr = inArray.apply(contentCntnr, [tag]); |
|
162
|
|
|
if (!tagInArr && tagInArr!==0) { |
|
163
|
|
|
testChild = lastChildContainingText.apply(testChild); |
|
164
|
|
|
} |
|
165
|
|
|
return testChild; |
|
166
|
|
|
} |
|
167
|
|
|
// ]]> |
|
168
|
|
|
EOT; |
|
169
|
|
|
|
|
170
|
|
|
return $ret; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/* |
|
174
|
|
|
* @public function render |
|
175
|
|
|
* @param null |
|
176
|
|
|
* |
|
177
|
|
|
* @return bool|string |
|
178
|
|
|
*/ |
|
179
|
|
|
public function render() |
|
180
|
|
|
{ |
|
181
|
|
|
$module = $this->getModule(); |
|
182
|
|
|
$filename = $this->getFileName(); |
|
183
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
184
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
185
|
|
|
$content .= $this->getJavascriptJQueryButtons(); |
|
186
|
|
|
$content .= $this->getJavascriptJQueryPrint(); |
|
187
|
|
|
|
|
188
|
|
|
$this->create($moduleDirname, 'assets/js', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
189
|
|
|
|
|
190
|
|
|
return $this->renderFile(); |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.