diff --git a/cpn.admin.inc b/cpn.admin.inc index 5d98af5..2ce3243 100644 --- a/cpn.admin.inc +++ b/cpn.admin.inc @@ -13,6 +13,15 @@ function cpn_settings($form, &$form_state) { '#default_value' => variable_get('cpn_syntax_highlighting', 0), ); + $form['cpn_weight'] = array( + '#title' => t('weight for the added scripts'), + '#type' => 'textfield', + '#default_value' => variable_get('cpn_weight', 0),//0, //variable_get('cpn_path', 'public://cpn'), + '#description' => t('weight for the added scripts.'), + '#size' => 3, + '#maxlength' => 4, + ); + // Add CodeMirror as a syntax highlighting option if available. if (cpn_codemirror()) { $form['cpn_syntax_highlighting']['#options']['codemirror'] = 'CodeMirror 2'; @@ -36,6 +45,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('', 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..2979704 100644 --- a/cpn.module +++ b/cpn.module @@ -231,8 +231,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_THEME + variable_get('cpn_weight', 0), + 'weight' => ($type == 'css' ? CSS_THEME : JS_THEME) + variable_get('cpn_weight', 0), 'data' => $file, ); } @@ -245,8 +245,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_THEME + variable_get('cpn_weight', 0), + 'weight' => $type == 'css' ? CSS_THEME : JS_THEME + variable_get('cpn_weight', 0), 'data' => $node->cpn[$type], ); } @@ -262,8 +262,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_THEME + variable_get('cpn_weight', 0), + 'weight' => $type == 'css' ? CSS_THEME : JS_THEME + variable_get('cpn_weight', 0), 'data' => $file, ); }