diff --git a/cpn.admin.inc b/cpn.admin.inc index 5d98af5..af09879 100644 --- a/cpn.admin.inc +++ b/cpn.admin.inc @@ -13,6 +13,44 @@ function cpn_settings($form, &$form_state) { '#default_value' => variable_get('cpn_syntax_highlighting', 0), ); + // Added weight to the appearance of the js in the template. + $form['cpn_weight'] = array( + '#title' => t('weight for the added scripts'), + '#type' => 'select', + '#default_value' => variable_get('cpn_weight', 0), + '#description' => t('weight for the added scripts. Notice that if you load before any other js that your script uses, like jquery, it could break your own js'), + '#options' => array( + -13 => '-13', + -12 => '-12', + -11 => '-11', + -10 => '-10', + -9 => '-9', + -8 => '-8', + -7 => '-7', + -6 => '-6', + -5 => '-5', + -4 => '-4', + -3 => '-3', + -2 => '-2', + -1 => '-1', + 0 => '0', + 1 => '1', + 2 => '2', + 3 => '3', + 4 => '4', + 5 => '5', + 6 => '6', + 7 => '7', + 8 => '8', + 9 => '9', + 10 => '10', + 11 => '11', + 12 => '12', + 13 => '13', + 14 => '14', + ), + ); + // Add CodeMirror as a syntax highlighting option if available. if (cpn_codemirror()) { $form['cpn_syntax_highlighting']['#options']['codemirror'] = 'CodeMirror 2'; @@ -36,6 +74,16 @@ function cpn_settings($form, &$form_state) { } /** + * Settings form - validate callback. + */ +function cpn_settings_validate($form, &$form_state) { + if (!is_numeric($form_state['values']['cpn_weight'])) { + form_set_error('cpn', t('You must select a numeric value.')); + } + +} + +/** * Settings form - submit callback. */ function cpn_settings_submit($form, &$form_state) { diff --git a/cpn.module b/cpn.module index ee701ec..fd040e1 100644 --- a/cpn.module +++ b/cpn.module @@ -223,7 +223,10 @@ function cpn_node_load($nodes, $types) { function cpn_node_view($node, $view_mode, $langcode) { // This variable ensures that CSS and JS don't get added twice, which is a // problem especially for JS. - static $previewed = FALSE; + static $previewed = FALSE; + + // Weight to use when displaying the code amongst the other js in theme. + $cpn_weight = variable_get('cpn_weight', 0); // Attach the content type CSS/JS, lighter than the per-page files. foreach (array('css', 'js') as $type) { @@ -231,8 +234,8 @@ function cpn_node_view($node, $view_mode, $langcode) { if (is_file($file)) { $node->content['#attached'][$type]['cpn_type'] = array( 'type' => 'file', - 'group' => $type == 'css' ? CSS_THEME : JS_THEME, - 'weight' => ($type == 'css' ? CSS_THEME : JS_THEME) - 1, + 'group' => $type == 'css' ? CSS_THEME : JS_LIBRARY + $cpn_weight, + 'weight' => ($type == 'css' ? CSS_THEME : JS_LIBRARY) + $cpn_weight, 'data' => $file, ); } @@ -245,8 +248,8 @@ function cpn_node_view($node, $view_mode, $langcode) { if (isset($node->cpn[$type]) && drupal_strlen(trim($node->cpn[$type]))) { $node->content['#attached'][$type]['cpn_node'] = array( 'type' => 'inline', - 'group' => $type == 'css' ? CSS_THEME : JS_THEME, - 'weight' => $type == 'css' ? CSS_THEME : JS_THEME, + 'group' => $type == 'css' ? CSS_THEME : JS_LIBRARY + $cpn_weight, + 'weight' => $type == 'css' ? CSS_THEME : JS_LIBRARY + $cpn_weight, 'data' => $node->cpn[$type], ); } @@ -262,8 +265,8 @@ function cpn_node_view($node, $view_mode, $langcode) { if (is_file($file)) { $node->content['#attached'][$type]['cpn_node'] = array( 'type' => 'file', - 'group' => $type == 'css' ? CSS_THEME : JS_THEME, - 'weight' => $type == 'css' ? CSS_THEME : JS_THEME, + 'group' => $type == 'css' ? CSS_THEME : JS_LIBRARY + $cpn_weight, + 'weight' => $type == 'css' ? CSS_THEME : JS_LIBRARY + $cpn_weight, 'data' => $file, ); }