00001 <?php
00002
00003
00004
00005
00006
00007
00008 class JQueryUI {
00009
00010 const EFFECTS_CORE = 'effects.core';
00011 const EFFECTS_BLIND = 'effects.blind';
00012 const EFFECTS_BOUNCE = 'effects.bounce';
00013 const EFFECTS_CLIP = 'effects.clip';
00014 const EFFECTS_DROP = 'effects.drop';
00015 const EFFECTS_EXPLODE = 'effects.explode';
00016 const EFFECTS_FADE = 'effects.fade';
00017 const EFFECTS_FOLD = 'effects.fold';
00018 const EFFECTS_HIGHLIGHT = 'effects.highlight';
00019 const EFFECTS_PULSATE = 'effects.pulsate';
00020 const EFFECTS_SCALE = 'effects.scale';
00021 const EFFECTS_SHAKE = 'effects.shake';
00022 const EFFECTS_SLIDE = 'effects.slide';
00023 const EFFECTS_TRANSFER = 'effects.transfer';
00024
00025
00026 const WIDGET_ACCORDION = 'ui.accordion';
00027 const WIDGET_BUTTON = 'ui.button';
00028 const WIDGET_DATEPICKER = 'ui.datepicker';
00029 const WIDGET_DIALOG = 'ui.dialog';
00030 const WIDGET_PROGRESSBAR = 'ui.progressbar';
00031 const WIDGET_SLIDER = 'ui.slider';
00032 const WIDGET_TABS = 'ui.tabs';
00033 const WIDGET_AUTOCOMPLETE = 'ui.autocomplete';
00034
00035
00036 const FEATURE_DRAGGABLE = 'ui.draggable';
00037 const FEATURE_DROPPABLE = 'ui.droppable';
00038 const FEATURE_RESIZABLE = 'ui.resizable';
00039 const FEATURE_SELECTABLE = 'ui.selectable';
00040 const FEATURE_SORTABLE = 'ui.sortable';
00041
00042 const FEATURE_MOUSE = 'ui.mouse';
00043 const FEATURE_POSITION = 'ui.position';
00044
00045 const CORE = 'ui.core';
00046 const CORE_WIDGET = 'ui.widget';
00047
00048 const CDN_GOOGLE = 'https://ajax.googleapis.com/ajax/libs/jqueryui/%version%/jquery-ui.min.js';
00049 const CDN_MS = 'https://ajax.aspnetcdn.com/ajax/jquery.ui/%version_min%/jquery-ui.min.js';
00050
00051
00052
00053
00054
00055
00056 private static $enabled_components = array();
00057
00058
00059
00060
00061
00062 private static $enabled_locales = array();
00063
00064
00065
00066
00067
00068
00069 public static function enable_components($components) {
00070 self::$enabled_components = array_merge(self::$enabled_components, Arr::force($components, false));
00071 self::$enabled_components = array_unique(self::$enabled_components);
00072 }
00073
00074
00075
00076
00077
00078
00079 public static function get_enabled_components() {
00080 return self::$enabled_components;
00081 }
00082
00083
00084
00085
00086
00087
00088 public static function enable_locales($locales) {
00089 self::$enabled_locales = array_merge(self::$enabled_locales, Arr::force($locales, false));
00090 self::$enabled_locales = array_unique(self::$enabled_locales);
00091 }
00092
00093
00094
00095
00096
00097
00098 public static function get_enabled_locales() {
00099 return self::$enabled_locales;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 public static function get_js_paths($components) {
00109 $resolved = array();
00110 $deps = self::get_dependencies();
00111 $locs = self::get_supported_locales();
00112 foreach($components as $c) {
00113 self::collect_dependencies($c, $resolved, $deps, $locs);
00114 }
00115
00116 $ret = array();
00117 $prefix = self::is_version_1_8() ? 'jquery.' : '';
00118 foreach($resolved as $c) {
00119 $c = explode('/', $c);
00120 $file = array_pop($c);
00121 $file = $prefix . $file;
00122 $c[] = $file;
00123 $path = 'js/jqueryui/' . implode('/', $c) . '.js';
00124 if (!in_array($path, $ret)) {
00125 $ret[] = $path;
00126 }
00127 }
00128 return $ret;
00129 }
00130
00131
00132
00133
00134 private static function collect_dependencies($component, &$resolved, $dependencies, $localizations) {
00135 if (!self::uses_cdn()) {
00136 $deps = Arr::get_item($dependencies, $component, array());
00137 foreach($deps as $d) {
00138 self::collect_dependencies($d, $resolved, $dependencies, $localizations);
00139 }
00140 $resolved[$component] = $component;
00141 }
00142 self::collect_localizations($component, $resolved, $localizations);
00143 }
00144
00145
00146
00147
00148 private static function collect_localizations($component, &$resolves, $localizations) {
00149 $localizations_for_comp = Arr::get_item($localizations, $component, array());
00150 foreach(self::get_enabled_locales() as $l) {
00151 if (in_array($l, $localizations_for_comp)) {
00152 $file = 'i18n/' . $component . '-' . $l;
00153 $resolves[$file] = $file;
00154 }
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163 public static function uses_cdn() {
00164 return Config::get_value(ConfigJQueryUI::CDN) != '';
00165 }
00166
00167 public static function get_cdn_url() {
00168 $cdn = trim(Config::get_value(ConfigJQueryUI::CDN));
00169 if (empty($cdn)) {
00170 return '';
00171 }
00172
00173
00174 if ($cdn == 'google') { $cdn = self::CDN_GOOGLE; }
00175 elseif ($cdn == 'ms') { $cdn = self::CDN_MS; }
00176
00177 $version = '';
00178 switch(Config::get_value(ConfigJQueryUI::VERSION)) {
00179 case '1.7':
00180 $version = JQUERYUI_VERSION_1_7;
00181 break;
00182 case '1.8':
00183 $version = JQUERYUI_VERSION_1_8;
00184 break;
00185 }
00186 if (empty($version)) {
00187 throw new Exception('Unknown JQueryUI Version ' . Config::get_value(ConfigJQueryUI::VERSION));
00188 }
00189
00190 $cdn = str_replace('%version%', $version, $cdn);
00191 $version_min = preg_replace('|\.0$|', '', $version);
00192 $cdn = str_replace('%version_min%', $version_min, $cdn);
00193
00194 return $cdn;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203 public static function get_css_paths($components) {
00204 $css_components = array(
00205 self::CORE
00206 );
00207 $css_having = self::get_components_having_css();
00208
00209 foreach($components as $c) {
00210 if (in_array($c, $css_having)) {
00211 $css_components[] = $c;
00212 }
00213 }
00214 $css_components[] = 'ui.theme';
00215
00216 $ret = array();
00217 $prefix = self::is_version_1_8() ? 'jquery.' : '';
00218 foreach($css_components as $c) {
00219 $path = 'css/jqueryui/' . $prefix . $c . '.css';
00220 if (!in_array($path, $ret)) {
00221 $ret[] = $path;
00222 }
00223 }
00224 return $ret;
00225 }
00226
00227
00228
00229
00230
00231
00232 public static function get_all_widgets() {
00233 $ret = array(
00234 self::WIDGET_ACCORDION,
00235 self::WIDGET_DATEPICKER,
00236 self::WIDGET_DIALOG,
00237 self::WIDGET_PROGRESSBAR,
00238 self::WIDGET_SLIDER,
00239 self::WIDGET_TABS,
00240 self::WIDGET_AUTOCOMPLETE
00241 );
00242 if (self::is_version_1_8()) {
00243 $ret[] = self::WIDGET_BUTTON;
00244 }
00245 return $ret;
00246 }
00247
00248
00249
00250
00251
00252
00253 private static function is_version_1_8() {
00254 return Config::get_value(ConfigJQueryUI::JQUERYUI_VERSION) == '1.8';
00255 }
00256
00257
00258
00259
00260
00261
00262 private static function get_dependencies() {
00263 if (self::is_version_1_8()) {
00264 return array(
00265 self::EFFECTS_CORE => array(),
00266 self::EFFECTS_BLIND => array(self::EFFECTS_CORE),
00267 self::EFFECTS_BOUNCE => array(self::EFFECTS_CORE),
00268 self::EFFECTS_CLIP => array(self::EFFECTS_CORE),
00269 self::EFFECTS_DROP => array(self::EFFECTS_CORE),
00270 self::EFFECTS_EXPLODE => array(self::EFFECTS_CORE),
00271 self::EFFECTS_FADE => array(self::EFFECTS_CORE),
00272 self::EFFECTS_FOLD => array(self::EFFECTS_CORE),
00273 self::EFFECTS_HIGHLIGHT => array(self::EFFECTS_CORE),
00274 self::EFFECTS_PULSATE => array(self::EFFECTS_CORE),
00275 self::EFFECTS_SCALE => array(self::EFFECTS_CORE),
00276 self::EFFECTS_SHAKE => array(self::EFFECTS_CORE),
00277 self::EFFECTS_SLIDE => array(self::EFFECTS_CORE),
00278 self::EFFECTS_TRANSFER => array(self::EFFECTS_CORE),
00279
00280
00281 self::WIDGET_ACCORDION => array(self::CORE, self::CORE_WIDGET),
00282 self::WIDGET_BUTTON => array(self::CORE, self::CORE_WIDGET),
00283 self::WIDGET_DATEPICKER => array(self::CORE, self::CORE_WIDGET),
00284 self::WIDGET_DIALOG => array(self::WIDGET_BUTTON, self::FEATURE_MOUSE, self::FEATURE_POSITION, self::FEATURE_DRAGGABLE, self::FEATURE_RESIZABLE),
00285 self::WIDGET_PROGRESSBAR => array(self::CORE, self::CORE_WIDGET),
00286 self::WIDGET_SLIDER => array(self::CORE, self::CORE_WIDGET, self::FEATURE_MOUSE),
00287 self::WIDGET_TABS => array(self::CORE, self::CORE_WIDGET),
00288 self::WIDGET_AUTOCOMPLETE => array(self::CORE, self::CORE_WIDGET, self::FEATURE_POSITION),
00289
00290
00291 self::FEATURE_DRAGGABLE => array(self::CORE, self::CORE_WIDGET, self::FEATURE_MOUSE),
00292 self::FEATURE_DROPPABLE => array(self::FEATURE_DRAGGABLE),
00293 self::FEATURE_RESIZABLE => array(self::CORE, self::CORE_WIDGET, self::FEATURE_MOUSE),
00294 self::FEATURE_SELECTABLE => array(self::CORE, self::CORE_WIDGET, self::FEATURE_MOUSE),
00295 self::FEATURE_SORTABLE => array(self::CORE, self::CORE_WIDGET, self::FEATURE_MOUSE),
00296
00297 self::FEATURE_MOUSE => array(self::CORE_WIDGET),
00298 self::FEATURE_POSITION => array(),
00299
00300 self::CORE_WIDGET => array(),
00301 self::CORE => array(),
00302 );
00303 }
00304 else {
00305
00306 return array(
00307 self::EFFECTS_CORE => array(),
00308 self::EFFECTS_BLIND => array(self::EFFECTS_CORE),
00309 self::EFFECTS_BOUNCE => array(self::EFFECTS_CORE),
00310 self::EFFECTS_CLIP => array(self::EFFECTS_CORE),
00311 self::EFFECTS_DROP => array(self::EFFECTS_CORE),
00312 self::EFFECTS_EXPLODE => array(self::EFFECTS_CORE),
00313 self::EFFECTS_FADE => array(self::EFFECTS_CORE),
00314 self::EFFECTS_FOLD => array(self::EFFECTS_CORE),
00315 self::EFFECTS_HIGHLIGHT => array(self::EFFECTS_CORE),
00316 self::EFFECTS_PULSATE => array(self::EFFECTS_CORE),
00317 self::EFFECTS_SCALE => array(self::EFFECTS_CORE),
00318 self::EFFECTS_SHAKE => array(self::EFFECTS_CORE),
00319 self::EFFECTS_SLIDE => array(self::EFFECTS_CORE),
00320 self::EFFECTS_TRANSFER => array(self::EFFECTS_CORE),
00321
00322
00323 self::WIDGET_ACCORDION => array(self::CORE),
00324 self::WIDGET_DATEPICKER => array(self::CORE),
00325 self::WIDGET_DIALOG => array(self::CORE, self::FEATURE_DRAGGABLE, self::FEATURE_RESIZABLE),
00326 self::WIDGET_PROGRESSBAR => array(self::CORE),
00327 self::WIDGET_SLIDER => array(self::CORE),
00328 self::WIDGET_TABS => array(self::CORE),
00329 self::WIDGET_AUTOCOMPLETE => array(),
00330
00331
00332 self::FEATURE_DRAGGABLE => array(self::CORE),
00333 self::FEATURE_DROPPABLE => array(self::FEATURE_DRAGGABLE),
00334 self::FEATURE_RESIZABLE => array(self::CORE),
00335 self::FEATURE_SELECTABLE => array(self::CORE),
00336 self::FEATURE_SORTABLE => array(self::CORE),
00337
00338 self::CORE => array(),
00339 );
00340 }
00341 }
00342
00343
00344
00345
00346
00347
00348 private static function get_supported_locales() {
00349 if (self::is_version_1_8()) {
00350 return array(
00351 self::WIDGET_DATEPICKER => array(
00352 'af', 'ar', 'az',
00353 'bg', 'bs',
00354 'ca', 'cs',
00355 'da', 'de',
00356 'el', 'en-GB', 'eo', 'es', 'et', 'eu',
00357 'fa', 'fi', 'fo', 'fr-CH', 'fr',
00358 'he', 'hr', 'hu', 'hy',
00359 'id', 'is', 'it',
00360 'ja',
00361 'ko',
00362 'lt', 'lv',
00363 'ms',
00364 'nl', 'no',
00365 'pl', 'pt-BR',
00366 'ro', 'ru',
00367 'sk', 'sl', 'sq', 'sr', 'sr-SR', 'sv',
00368 'ta', 'th', 'tr',
00369 'uk',
00370 'vi',
00371 'zh-CN', 'zh-HK', 'zh-TW',
00372 ),
00373 );
00374 }
00375 else {
00376
00377 return array(
00378 self::WIDGET_DATEPICKER => array(
00379 'ar',
00380 'bg',
00381 'ca', 'cs',
00382 'da', 'de',
00383 'el', 'eo', 'es',
00384 'fa', 'fi', 'fr',
00385 'he', 'hr', 'hu', 'hy',
00386 'id', 'is', 'it',
00387 'ja',
00388 'ko',
00389 'lt', 'lv',
00390 'ms',
00391 'nl', 'no',
00392 'pl', 'pt-BR',
00393 'ro', 'ru',
00394 'sk', 'sl', 'sq', 'sr', 'sr-SR', 'sv',
00395 'th', 'tr',
00396 'uk',
00397 'vi',
00398 'zh-CN', 'zh-TW',
00399 ),
00400 );
00401 }
00402 }
00403
00404
00405
00406
00407
00408
00409 private static function get_components_having_css() {
00410 $ret = self::get_all_widgets();
00411 $ret[] = self::FEATURE_RESIZABLE;
00412 $ret[] = self::FEATURE_SELECTABLE;
00413 return $ret;
00414 }
00415 }